diff mbox series

[net] net: enetc: distinguish error from valid pointers in enetc_fixup_clear_rss_rfs()

Message ID 20230906141609.247579-1-vladimir.oltean@nxp.com (mailing list archive)
State Accepted
Commit 1b36955cc048c8ff6ba448dbf4be0e52f59f2963
Delegated to: Netdev Maintainers
Headers show
Series [net] net: enetc: distinguish error from valid pointers in enetc_fixup_clear_rss_rfs() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1330 this patch: 1330
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1353 this patch: 1353
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1353 this patch: 1353
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Vladimir Oltean Sept. 6, 2023, 2:16 p.m. UTC
enetc_psi_create() returns an ERR_PTR() or a valid station interface
pointer, but checking for the non-NULL quality of the return code blurs
that difference away. So if enetc_psi_create() fails, we call
enetc_psi_destroy() when we shouldn't. This will likely result in
crashes, since enetc_psi_create() cleans up everything after itself when
it returns an ERR_PTR().

Fixes: f0168042a212 ("net: enetc: reimplement RFS/RSS memory clearing as PCI quirk")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/netdev/582183ef-e03b-402b-8e2d-6d9bb3c83bd9@moroto.mountain/
Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/freescale/enetc/enetc_pf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Horman Sept. 6, 2023, 4:41 p.m. UTC | #1
On Wed, Sep 06, 2023 at 05:16:09PM +0300, Vladimir Oltean wrote:
> enetc_psi_create() returns an ERR_PTR() or a valid station interface
> pointer, but checking for the non-NULL quality of the return code blurs
> that difference away. So if enetc_psi_create() fails, we call
> enetc_psi_destroy() when we shouldn't. This will likely result in
> crashes, since enetc_psi_create() cleans up everything after itself when
> it returns an ERR_PTR().
> 
> Fixes: f0168042a212 ("net: enetc: reimplement RFS/RSS memory clearing as PCI quirk")
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/netdev/582183ef-e03b-402b-8e2d-6d9bb3c83bd9@moroto.mountain/
> Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Simon Horman <horms@kernel.org>
patchwork-bot+netdevbpf@kernel.org Sept. 7, 2023, 6:30 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  6 Sep 2023 17:16:09 +0300 you wrote:
> enetc_psi_create() returns an ERR_PTR() or a valid station interface
> pointer, but checking for the non-NULL quality of the return code blurs
> that difference away. So if enetc_psi_create() fails, we call
> enetc_psi_destroy() when we shouldn't. This will likely result in
> crashes, since enetc_psi_create() cleans up everything after itself when
> it returns an ERR_PTR().
> 
> [...]

Here is the summary with links:
  - [net] net: enetc: distinguish error from valid pointers in enetc_fixup_clear_rss_rfs()
    https://git.kernel.org/netdev/net/c/1b36955cc048

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index e0a4cb7e3f50..c153dc083aff 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -1402,7 +1402,7 @@  static void enetc_fixup_clear_rss_rfs(struct pci_dev *pdev)
 		return;
 
 	si = enetc_psi_create(pdev);
-	if (si)
+	if (!IS_ERR(si))
 		enetc_psi_destroy(pdev);
 }
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_FREESCALE, ENETC_DEV_ID_PF,