netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/2] net: tehuti: Fix some error handling paths in bdx_probe()
@ 2024-02-27 20:50 Christophe JAILLET
  2024-02-27 20:50 ` [PATCH net 1/2] net: tehuti: Fix a missing pci_disable_msi() in the error handling path of bdx_probe() Christophe JAILLET
  2024-02-27 20:50 ` [PATCH net 2/2] net: tehuti: Fix leaks " Christophe JAILLET
  0 siblings, 2 replies; 8+ messages in thread
From: Christophe JAILLET @ 2024-02-27 20:50 UTC (permalink / raw)
  To: andy, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

The patch has been split in 2 patches in the hope to ease review. But
they both fix issues introduced years ago in the same commit.

Moreover, the 2nd patch partly undoes the first one.

So, if preferred they can be merged in a single patch.

They are both compile tested-only.

Christophe JAILLET (2):
  net: tehuti: Fix a missing pci_disable_msi() in the error handling
    path of bdx_probe()
  net: tehuti: Fix leaks in the error handling path of bdx_probe()

 drivers/net/ethernet/tehuti/tehuti.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

-- 
2.43.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net 1/2] net: tehuti: Fix a missing pci_disable_msi() in the error handling path of bdx_probe()
  2024-02-27 20:50 [PATCH net 0/2] net: tehuti: Fix some error handling paths in bdx_probe() Christophe JAILLET
@ 2024-02-27 20:50 ` Christophe JAILLET
  2024-02-28  9:51   ` Jiri Pirko
  2024-02-27 20:50 ` [PATCH net 2/2] net: tehuti: Fix leaks " Christophe JAILLET
  1 sibling, 1 reply; 8+ messages in thread
From: Christophe JAILLET @ 2024-02-27 20:50 UTC (permalink / raw)
  To: andy, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

If an error occurs after a successful call to pci_enable_msi(),
pci_disable_msi() should be called as already done in the remove function.

Add a new label and the missing pci_disable_msi() call.

Fixes: 1a348ccc1047 ("[NET]: Add Tehuti network driver.")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only.
---
 drivers/net/ethernet/tehuti/tehuti.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/tehuti/tehuti.c b/drivers/net/ethernet/tehuti/tehuti.c
index ca409515ead5..938a5caf5a3b 100644
--- a/drivers/net/ethernet/tehuti/tehuti.c
+++ b/drivers/net/ethernet/tehuti/tehuti.c
@@ -1965,7 +1965,7 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		ndev = alloc_etherdev(sizeof(struct bdx_priv));
 		if (!ndev) {
 			err = -ENOMEM;
-			goto err_out_iomap;
+			goto err_out_disable_msi;
 		}
 
 		ndev->netdev_ops = &bdx_netdev_ops;
@@ -2031,7 +2031,7 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		if (bdx_read_mac(priv)) {
 			pr_err("load MAC address failed\n");
 			err = -EFAULT;
-			goto err_out_iomap;
+			goto err_out_disable_msi;
 		}
 		SET_NETDEV_DEV(ndev, &pdev->dev);
 		err = register_netdev(ndev);
@@ -2048,6 +2048,11 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 err_out_free:
 	free_netdev(ndev);
+err_out_disable_msi:
+#ifdef BDX_MSI
+	if (nic->irq_type == IRQ_MSI)
+		pci_disable_msi(pdev);
+#endif
 err_out_iomap:
 	iounmap(nic->regs);
 err_out_res:
-- 
2.43.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net 2/2] net: tehuti: Fix leaks in the error handling path of bdx_probe()
  2024-02-27 20:50 [PATCH net 0/2] net: tehuti: Fix some error handling paths in bdx_probe() Christophe JAILLET
  2024-02-27 20:50 ` [PATCH net 1/2] net: tehuti: Fix a missing pci_disable_msi() in the error handling path of bdx_probe() Christophe JAILLET
@ 2024-02-27 20:50 ` Christophe JAILLET
  2024-02-28 10:17   ` Dan Carpenter
  2024-02-28 10:24   ` Jiri Pirko
  1 sibling, 2 replies; 8+ messages in thread
From: Christophe JAILLET @ 2024-02-27 20:50 UTC (permalink / raw)
  To: andy, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

If an error occurs when allocating the net_device, all the one already
allocated and registered should be released, as already done in the remove
function.

Add a new label, remove the now useless 'err_out_disable_msi' label and
adjust the error handling path accordingly.

Fixes: 1a348ccc1047 ("[NET]: Add Tehuti network driver.")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only.
---
 drivers/net/ethernet/tehuti/tehuti.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/tehuti/tehuti.c b/drivers/net/ethernet/tehuti/tehuti.c
index 938a5caf5a3b..6678179885cb 100644
--- a/drivers/net/ethernet/tehuti/tehuti.c
+++ b/drivers/net/ethernet/tehuti/tehuti.c
@@ -1965,7 +1965,7 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		ndev = alloc_etherdev(sizeof(struct bdx_priv));
 		if (!ndev) {
 			err = -ENOMEM;
-			goto err_out_disable_msi;
+			goto err_out_free;
 		}
 
 		ndev->netdev_ops = &bdx_netdev_ops;
@@ -2031,13 +2031,13 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		if (bdx_read_mac(priv)) {
 			pr_err("load MAC address failed\n");
 			err = -EFAULT;
-			goto err_out_disable_msi;
+			goto err_out_free_current;
 		}
 		SET_NETDEV_DEV(ndev, &pdev->dev);
 		err = register_netdev(ndev);
 		if (err) {
 			pr_err("register_netdev failed\n");
-			goto err_out_free;
+			goto err_out_free_current;
 		}
 		netif_carrier_off(ndev);
 		netif_stop_queue(ndev);
@@ -2046,9 +2046,14 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 	RET(0);
 
-err_out_free:
+err_out_free_current:
 	free_netdev(ndev);
-err_out_disable_msi:
+err_out_free:
+	while (--port >= 0) {
+		ndev = nic->priv[port]->ndev;
+		unregister_netdev(ndev);
+		free_netdev(ndev);
+	}
 #ifdef BDX_MSI
 	if (nic->irq_type == IRQ_MSI)
 		pci_disable_msi(pdev);
-- 
2.43.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/2] net: tehuti: Fix a missing pci_disable_msi() in the error handling path of bdx_probe()
  2024-02-27 20:50 ` [PATCH net 1/2] net: tehuti: Fix a missing pci_disable_msi() in the error handling path of bdx_probe() Christophe JAILLET
@ 2024-02-28  9:51   ` Jiri Pirko
  2024-02-28 17:52     ` Christophe JAILLET
  0 siblings, 1 reply; 8+ messages in thread
From: Jiri Pirko @ 2024-02-28  9:51 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: andy, davem, edumazet, kuba, pabeni, netdev, linux-kernel,
	kernel-janitors

Tue, Feb 27, 2024 at 09:50:55PM CET, christophe.jaillet@wanadoo.fr wrote:
>If an error occurs after a successful call to pci_enable_msi(),
>pci_disable_msi() should be called as already done in the remove function.
>
>Add a new label and the missing pci_disable_msi() call.
>
>Fixes: 1a348ccc1047 ("[NET]: Add Tehuti network driver.")
>Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>---
>Compile tested only.
>---
> drivers/net/ethernet/tehuti/tehuti.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/net/ethernet/tehuti/tehuti.c b/drivers/net/ethernet/tehuti/tehuti.c
>index ca409515ead5..938a5caf5a3b 100644
>--- a/drivers/net/ethernet/tehuti/tehuti.c
>+++ b/drivers/net/ethernet/tehuti/tehuti.c
>@@ -1965,7 +1965,7 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> 		ndev = alloc_etherdev(sizeof(struct bdx_priv));
> 		if (!ndev) {
> 			err = -ENOMEM;
>-			goto err_out_iomap;
>+			goto err_out_disable_msi;
> 		}
> 
> 		ndev->netdev_ops = &bdx_netdev_ops;
>@@ -2031,7 +2031,7 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> 		if (bdx_read_mac(priv)) {
> 			pr_err("load MAC address failed\n");
> 			err = -EFAULT;
>-			goto err_out_iomap;
>+			goto err_out_disable_msi;
> 		}
> 		SET_NETDEV_DEV(ndev, &pdev->dev);
> 		err = register_netdev(ndev);
>@@ -2048,6 +2048,11 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> 
> err_out_free:
> 	free_netdev(ndev);
>+err_out_disable_msi:
>+#ifdef BDX_MSI

ifdef does not seem to be necessary here. The irq_type check should be
enough.

pw-bot: cr


>+	if (nic->irq_type == IRQ_MSI)
>+		pci_disable_msi(pdev);
>+#endif
> err_out_iomap:
> 	iounmap(nic->regs);
> err_out_res:
>-- 
>2.43.2
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 2/2] net: tehuti: Fix leaks in the error handling path of bdx_probe()
  2024-02-27 20:50 ` [PATCH net 2/2] net: tehuti: Fix leaks " Christophe JAILLET
@ 2024-02-28 10:17   ` Dan Carpenter
  2024-02-28 17:59     ` Christophe JAILLET
  2024-02-28 10:24   ` Jiri Pirko
  1 sibling, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2024-02-28 10:17 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: andy, davem, edumazet, kuba, pabeni, netdev, linux-kernel,
	kernel-janitors

On Tue, Feb 27, 2024 at 09:50:56PM +0100, Christophe JAILLET wrote:
> If an error occurs when allocating the net_device, all the one already
> allocated and registered should be released, as already done in the remove
> function.
> 
> Add a new label, remove the now useless 'err_out_disable_msi' label and
> adjust the error handling path accordingly.
> 
> Fixes: 1a348ccc1047 ("[NET]: Add Tehuti network driver.")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only.
> ---
>  drivers/net/ethernet/tehuti/tehuti.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/ethernet/tehuti/tehuti.c b/drivers/net/ethernet/tehuti/tehuti.c
> index 938a5caf5a3b..6678179885cb 100644
> --- a/drivers/net/ethernet/tehuti/tehuti.c
> +++ b/drivers/net/ethernet/tehuti/tehuti.c
> @@ -1965,7 +1965,7 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  		ndev = alloc_etherdev(sizeof(struct bdx_priv));
>  		if (!ndev) {
>  			err = -ENOMEM;
> -			goto err_out_disable_msi;
> +			goto err_out_free;
>  		}
>  
>  		ndev->netdev_ops = &bdx_netdev_ops;
> @@ -2031,13 +2031,13 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  		if (bdx_read_mac(priv)) {
>  			pr_err("load MAC address failed\n");
>  			err = -EFAULT;
> -			goto err_out_disable_msi;
> +			goto err_out_free_current;
>  		}
>  		SET_NETDEV_DEV(ndev, &pdev->dev);
>  		err = register_netdev(ndev);
>  		if (err) {
>  			pr_err("register_netdev failed\n");
> -			goto err_out_free;
> +			goto err_out_free_current;
>  		}
>  		netif_carrier_off(ndev);
>  		netif_stop_queue(ndev);
> @@ -2046,9 +2046,14 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  	}
>  	RET(0);
>  
> -err_out_free:
> +err_out_free_current:
>  	free_netdev(ndev);

Since it seems like you're going to be resending this patch, could you
do this free_netdev() before gotos?  That way if someone adds more code
after the loop then we can still use the goto ladder to unwind.  (No one
is going to add more code after the loop, I know...  I wouldn't have
commented except that it seemed like you were going to resend.)

		if (bdx_read_mac(priv)) {
			free_netdev(ndev);
			pr_err("load MAC address failed\n");
			err = -EFAULT;
			goto err_out_free;
		}

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 2/2] net: tehuti: Fix leaks in the error handling path of bdx_probe()
  2024-02-27 20:50 ` [PATCH net 2/2] net: tehuti: Fix leaks " Christophe JAILLET
  2024-02-28 10:17   ` Dan Carpenter
@ 2024-02-28 10:24   ` Jiri Pirko
  1 sibling, 0 replies; 8+ messages in thread
From: Jiri Pirko @ 2024-02-28 10:24 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: andy, davem, edumazet, kuba, pabeni, netdev, linux-kernel,
	kernel-janitors

Tue, Feb 27, 2024 at 09:50:56PM CET, christophe.jaillet@wanadoo.fr wrote:
>If an error occurs when allocating the net_device, all the one already
>allocated and registered should be released, as already done in the remove
>function.
>
>Add a new label, remove the now useless 'err_out_disable_msi' label and
>adjust the error handling path accordingly.
>
>Fixes: 1a348ccc1047 ("[NET]: Add Tehuti network driver.")
>Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>---
>Compile tested only.


Looks okay.

Reviewed-by: Jiri Pirko <jiri@nvidia.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/2] net: tehuti: Fix a missing pci_disable_msi() in the error handling path of bdx_probe()
  2024-02-28  9:51   ` Jiri Pirko
@ 2024-02-28 17:52     ` Christophe JAILLET
  0 siblings, 0 replies; 8+ messages in thread
From: Christophe JAILLET @ 2024-02-28 17:52 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: andy, davem, edumazet, kuba, pabeni, netdev, linux-kernel,
	kernel-janitors

Le 28/02/2024 à 10:51, Jiri Pirko a écrit :
> Tue, Feb 27, 2024 at 09:50:55PM CET, christophe.jaillet@wanadoo.fr wrote:
>> If an error occurs after a successful call to pci_enable_msi(),
>> pci_disable_msi() should be called as already done in the remove function.
>>
>> Add a new label and the missing pci_disable_msi() call.
>>
>> Fixes: 1a348ccc1047 ("[NET]: Add Tehuti network driver.")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> Compile tested only.
>> ---
>> drivers/net/ethernet/tehuti/tehuti.c | 9 +++++++--
>> 1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/tehuti/tehuti.c b/drivers/net/ethernet/tehuti/tehuti.c
>> index ca409515ead5..938a5caf5a3b 100644
>> --- a/drivers/net/ethernet/tehuti/tehuti.c
>> +++ b/drivers/net/ethernet/tehuti/tehuti.c
>> @@ -1965,7 +1965,7 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>> 		ndev = alloc_etherdev(sizeof(struct bdx_priv));
>> 		if (!ndev) {
>> 			err = -ENOMEM;
>> -			goto err_out_iomap;
>> +			goto err_out_disable_msi;
>> 		}
>>
>> 		ndev->netdev_ops = &bdx_netdev_ops;
>> @@ -2031,7 +2031,7 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>> 		if (bdx_read_mac(priv)) {
>> 			pr_err("load MAC address failed\n");
>> 			err = -EFAULT;
>> -			goto err_out_iomap;
>> +			goto err_out_disable_msi;
>> 		}
>> 		SET_NETDEV_DEV(ndev, &pdev->dev);
>> 		err = register_netdev(ndev);
>> @@ -2048,6 +2048,11 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>>
>> err_out_free:
>> 	free_netdev(ndev);
>> +err_out_disable_msi:
>> +#ifdef BDX_MSI
> 
> ifdef does not seem to be necessary here. The irq_type check should be
> enough.

I thought about removing it, but I left it because it how it is done in 
the remove function.

I'll send a v2 without the ifdef and will also add another patch to 
remove it as well from the remove function.

CJ

> 
> pw-bot: cr
> 
> 
>> +	if (nic->irq_type == IRQ_MSI)
>> +		pci_disable_msi(pdev);
>> +#endif
>> err_out_iomap:
>> 	iounmap(nic->regs);
>> err_out_res:
>> -- 
>> 2.43.2
>>
>>
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 2/2] net: tehuti: Fix leaks in the error handling path of bdx_probe()
  2024-02-28 10:17   ` Dan Carpenter
@ 2024-02-28 17:59     ` Christophe JAILLET
  0 siblings, 0 replies; 8+ messages in thread
From: Christophe JAILLET @ 2024-02-28 17:59 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: andy, davem, edumazet, kuba, pabeni, netdev, linux-kernel,
	kernel-janitors

Le 28/02/2024 à 11:17, Dan Carpenter a écrit :
> On Tue, Feb 27, 2024 at 09:50:56PM +0100, Christophe JAILLET wrote:
>> If an error occurs when allocating the net_device, all the one already
>> allocated and registered should be released, as already done in the remove
>> function.
>>
>> Add a new label, remove the now useless 'err_out_disable_msi' label and
>> adjust the error handling path accordingly.
>>
>> Fixes: 1a348ccc1047 ("[NET]: Add Tehuti network driver.")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> Compile tested only.
>> ---
>>   drivers/net/ethernet/tehuti/tehuti.c | 15 ++++++++++-----
>>   1 file changed, 10 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/tehuti/tehuti.c b/drivers/net/ethernet/tehuti/tehuti.c
>> index 938a5caf5a3b..6678179885cb 100644
>> --- a/drivers/net/ethernet/tehuti/tehuti.c
>> +++ b/drivers/net/ethernet/tehuti/tehuti.c
>> @@ -1965,7 +1965,7 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>>   		ndev = alloc_etherdev(sizeof(struct bdx_priv));
>>   		if (!ndev) {
>>   			err = -ENOMEM;
>> -			goto err_out_disable_msi;
>> +			goto err_out_free;
>>   		}
>>   
>>   		ndev->netdev_ops = &bdx_netdev_ops;
>> @@ -2031,13 +2031,13 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>>   		if (bdx_read_mac(priv)) {
>>   			pr_err("load MAC address failed\n");
>>   			err = -EFAULT;
>> -			goto err_out_disable_msi;
>> +			goto err_out_free_current;
>>   		}
>>   		SET_NETDEV_DEV(ndev, &pdev->dev);
>>   		err = register_netdev(ndev);
>>   		if (err) {
>>   			pr_err("register_netdev failed\n");
>> -			goto err_out_free;
>> +			goto err_out_free_current;
>>   		}
>>   		netif_carrier_off(ndev);
>>   		netif_stop_queue(ndev);
>> @@ -2046,9 +2046,14 @@ bdx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>>   	}
>>   	RET(0);
>>   
>> -err_out_free:
>> +err_out_free_current:
>>   	free_netdev(ndev);
> 
> Since it seems like you're going to be resending this patch, could you
> do this free_netdev() before gotos?  That way if someone adds more code
> after the loop then we can still use the goto ladder to unwind.  (No one
> is going to add more code after the loop, I know...  I wouldn't have
> commented except that it seemed like you were going to resend.)
> 
> 		if (bdx_read_mac(priv)) {
> 			free_netdev(ndev);
> 			pr_err("load MAC address failed\n");
> 			err = -EFAULT;
> 			goto err_out_free;
> 		}
> 

Yeh, I thought about it, but it is more verbose and this code looks 
mostly unchanged since 2007!

Anyway, I agree with you and will update accordingly.

CJ

> regards,
> dan carpenter
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-02-28 17:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 20:50 [PATCH net 0/2] net: tehuti: Fix some error handling paths in bdx_probe() Christophe JAILLET
2024-02-27 20:50 ` [PATCH net 1/2] net: tehuti: Fix a missing pci_disable_msi() in the error handling path of bdx_probe() Christophe JAILLET
2024-02-28  9:51   ` Jiri Pirko
2024-02-28 17:52     ` Christophe JAILLET
2024-02-27 20:50 ` [PATCH net 2/2] net: tehuti: Fix leaks " Christophe JAILLET
2024-02-28 10:17   ` Dan Carpenter
2024-02-28 17:59     ` Christophe JAILLET
2024-02-28 10:24   ` Jiri Pirko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).