diff mbox series

sfc: Fix an error handling path in efx_pci_probe()

Message ID dc114193121c52c8fa3779e49bdd99d4b41344a9.1667077009.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Accepted
Commit 6c412da54c80a54b1a8b7f89677f6e82f0fabec4
Delegated to: Netdev Maintainers
Headers show
Series sfc: Fix an error handling path in efx_pci_probe() | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
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: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Christophe JAILLET Oct. 29, 2022, 8:57 p.m. UTC
If an error occurs after the first kzalloc() the corresponding memory
allocation is never freed.

Add the missing kfree() in the error handling path, as already done in the
remove() function.

Fixes: 7e773594dada ("sfc: Separate efx_nic memory from net_device memory")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
When 7e773594dada was merged, sfc/ef100.c had the same issue.
But it seems to have been fixed in 98ff4c7c8ac7.
---
 drivers/net/ethernet/sfc/efx.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Martin Habets Oct. 31, 2022, 9:09 a.m. UTC | #1
Please specify a branch in the subject.
This patch should go to net.

On Sat, Oct 29, 2022 at 10:57:11PM +0200, Christophe JAILLET wrote:
> If an error occurs after the first kzalloc() the corresponding memory
> allocation is never freed.
> 
> Add the missing kfree() in the error handling path, as already done in the
> remove() function.
> 
> Fixes: 7e773594dada ("sfc: Separate efx_nic memory from net_device memory")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Martin Habets <habetsm.xilinx@gmail.com>

> ---
> When 7e773594dada was merged, sfc/ef100.c had the same issue.
> But it seems to have been fixed in 98ff4c7c8ac7.

I agree.

> ---
>  drivers/net/ethernet/sfc/efx.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
> index 054d5ce6029e..0556542d7a6b 100644
> --- a/drivers/net/ethernet/sfc/efx.c
> +++ b/drivers/net/ethernet/sfc/efx.c
> @@ -1059,8 +1059,10 @@ static int efx_pci_probe(struct pci_dev *pci_dev,
>  
>  	/* Allocate and initialise a struct net_device */
>  	net_dev = alloc_etherdev_mq(sizeof(probe_data), EFX_MAX_CORE_TX_QUEUES);
> -	if (!net_dev)
> -		return -ENOMEM;
> +	if (!net_dev) {
> +		rc = -ENOMEM;
> +		goto fail0;
> +	}
>  	probe_ptr = netdev_priv(net_dev);
>  	*probe_ptr = probe_data;
>  	efx->net_dev = net_dev;
> @@ -1132,6 +1134,8 @@ static int efx_pci_probe(struct pci_dev *pci_dev,
>  	WARN_ON(rc > 0);
>  	netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
>  	free_netdev(net_dev);
> + fail0:
> +	kfree(probe_data);
>  	return rc;
>  }
>  
> -- 
> 2.34.1
patchwork-bot+netdevbpf@kernel.org Nov. 1, 2022, 4:30 p.m. UTC | #2
Hello:

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

On Sat, 29 Oct 2022 22:57:11 +0200 you wrote:
> If an error occurs after the first kzalloc() the corresponding memory
> allocation is never freed.
> 
> Add the missing kfree() in the error handling path, as already done in the
> remove() function.
> 
> Fixes: 7e773594dada ("sfc: Separate efx_nic memory from net_device memory")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> 
> [...]

Here is the summary with links:
  - sfc: Fix an error handling path in efx_pci_probe()
    https://git.kernel.org/netdev/net/c/6c412da54c80

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
index 054d5ce6029e..0556542d7a6b 100644
--- a/drivers/net/ethernet/sfc/efx.c
+++ b/drivers/net/ethernet/sfc/efx.c
@@ -1059,8 +1059,10 @@  static int efx_pci_probe(struct pci_dev *pci_dev,
 
 	/* Allocate and initialise a struct net_device */
 	net_dev = alloc_etherdev_mq(sizeof(probe_data), EFX_MAX_CORE_TX_QUEUES);
-	if (!net_dev)
-		return -ENOMEM;
+	if (!net_dev) {
+		rc = -ENOMEM;
+		goto fail0;
+	}
 	probe_ptr = netdev_priv(net_dev);
 	*probe_ptr = probe_data;
 	efx->net_dev = net_dev;
@@ -1132,6 +1134,8 @@  static int efx_pci_probe(struct pci_dev *pci_dev,
 	WARN_ON(rc > 0);
 	netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
 	free_netdev(net_dev);
+ fail0:
+	kfree(probe_data);
 	return rc;
 }