All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] net/sonic: Fix some resource leaks in error handling paths
  2020-05-08 17:25 ` Christophe JAILLET
@ 2020-05-09  6:15 ` Markus Elfring
  -1 siblings, 0 replies; 52+ messages in thread
From: Markus Elfring @ 2020-05-09  6:15 UTC (permalink / raw)
  To: Christophe Jaillet, netdev
  Cc: kernel-janitors, linux-kernel, David S. Miller, Finn Thain,
	Jakub Kicinski

> While at it, rename a label in order to be slightly more informative and
> split some too long lines.

Would you like to add the tag “Fixes” to the change description?


…
> +++ b/drivers/net/ethernet/natsemi/macsonic.c
> @@ -506,10 +506,14 @@ static int mac_sonic_platform_probe(struct platform_device *pdev)
>
>  	err = register_netdev(dev);
>  	if (err)
> -		goto out;
> +		goto undo_probe1;
>
>  	return 0;
>
> +undo_probe1:
> +	dma_free_coherent(lp->device,
> +			  SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
> +			  lp->descriptors, lp->descriptors_laddr);
>  out:
…

How do you think about the possibility to use the label “free_dma”?

Regards,
Markus

^ permalink raw reply	[flat|nested] 52+ messages in thread
* [PATCH] net/sonic: Fix some resource leaks in error handling paths
@ 2020-05-08 17:25 ` Christophe JAILLET
  0 siblings, 0 replies; 52+ messages in thread
From: Christophe JAILLET @ 2020-05-08 17:25 UTC (permalink / raw)
  To: davem, fthain; +Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

A call to 'dma_alloc_coherent()' is hidden in 'sonic_alloc_descriptors()'.

This is correctly freed in the remove function, but not in the error
handling path of the probe function.
Fix it and add the missing 'dma_free_coherent()' call.

While at it, rename a label in order to be slightly more informative and
split some too long lines.

This patch is similar to commit 10e3cc180e64 ("net/sonic: Fix a resource leak in an error handling path in 'jazz_sonic_probe()'")
which was for 'jazzsonic.c'.

Suggested-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Only macsonic has been compile tested. I don't have the needed setup to
compile xtsonic
---
 drivers/net/ethernet/natsemi/macsonic.c | 17 +++++++++++++----
 drivers/net/ethernet/natsemi/xtsonic.c  |  7 +++++--
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/macsonic.c b/drivers/net/ethernet/natsemi/macsonic.c
index 1b5559aacb38..38d86c712bbc 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -506,10 +506,14 @@ static int mac_sonic_platform_probe(struct platform_device *pdev)
 
 	err = register_netdev(dev);
 	if (err)
-		goto out;
+		goto undo_probe1;
 
 	return 0;
 
+undo_probe1:
+	dma_free_coherent(lp->device,
+			  SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
+			  lp->descriptors, lp->descriptors_laddr);
 out:
 	free_netdev(dev);
 
@@ -527,8 +531,9 @@ static int mac_sonic_platform_remove(struct platform_device *pdev)
 	struct sonic_local* lp = netdev_priv(dev);
 
 	unregister_netdev(dev);
-	dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
-	                  lp->descriptors, lp->descriptors_laddr);
+	dma_free_coherent(lp->device,
+			  SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
+			  lp->descriptors, lp->descriptors_laddr);
 	free_netdev(dev);
 
 	return 0;
@@ -584,12 +589,16 @@ static int mac_sonic_nubus_probe(struct nubus_board *board)
 
 	err = register_netdev(ndev);
 	if (err)
-		goto out;
+		goto undo_probe1;
 
 	nubus_set_drvdata(board, ndev);
 
 	return 0;
 
+undo_probe1:
+	dma_free_coherent(lp->device,
+			  SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
+			  lp->descriptors, lp->descriptors_laddr);
 out:
 	free_netdev(ndev);
 	return err;
diff --git a/drivers/net/ethernet/natsemi/xtsonic.c b/drivers/net/ethernet/natsemi/xtsonic.c
index dda9ec7d9cee..a917f1a830fc 100644
--- a/drivers/net/ethernet/natsemi/xtsonic.c
+++ b/drivers/net/ethernet/natsemi/xtsonic.c
@@ -229,11 +229,14 @@ int xtsonic_probe(struct platform_device *pdev)
 	sonic_msg_init(dev);
 
 	if ((err = register_netdev(dev)))
-		goto out1;
+		goto undo_probe1;
 
 	return 0;
 
-out1:
+undo_probe1:
+	dma_free_coherent(lp->device,
+			  SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
+			  lp->descriptors, lp->descriptors_laddr);
 	release_region(dev->base_addr, SONIC_MEM_SIZE);
 out:
 	free_netdev(dev);
-- 
2.25.1


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

end of thread, other threads:[~2020-05-13 23:16 UTC | newest]

Thread overview: 52+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-09  6:15 [PATCH] net/sonic: Fix some resource leaks in error handling paths Markus Elfring
2020-05-09  6:15 ` Markus Elfring
2020-05-09 23:45 ` Finn Thain
2020-05-09 23:45   ` Finn Thain
2020-05-10  5:30   ` Markus Elfring
2020-05-10  5:30     ` Markus Elfring
2020-05-10  8:25     ` Finn Thain
2020-05-10  8:25       ` Finn Thain
2020-05-10  9:07       ` Markus Elfring
2020-05-10  9:07         ` Markus Elfring
2020-05-11  0:28         ` Finn Thain
2020-05-11  0:28           ` Finn Thain
2020-05-11  6:48           ` Markus Elfring
2020-05-11  6:48             ` Markus Elfring
2020-05-12  0:08             ` Finn Thain
2020-05-12  0:08               ` Finn Thain
2020-05-12  6:38               ` Markus Elfring
2020-05-12  6:38                 ` Markus Elfring
2020-05-13  1:14                 ` Finn Thain
2020-05-13  1:14                   ` Finn Thain
2020-05-13  5:07                   ` net/sonic: Software evolution around the application of coding standards Markus Elfring
2020-05-13  5:07                     ` Markus Elfring
2020-05-13 23:16                     ` Finn Thain
2020-05-13 23:16                       ` Finn Thain
2020-05-11  8:20           ` net/sonic: Fix some resource leaks in error handling paths Markus Elfring
2020-05-11  8:20             ` Markus Elfring
  -- strict thread matches above, loose matches on Subject: below --
2020-05-08 17:25 [PATCH] " Christophe JAILLET
2020-05-08 17:25 ` Christophe JAILLET
2020-05-08 23:28 ` Finn Thain
2020-05-08 23:28   ` Finn Thain
2020-05-09  0:57 ` Jakub Kicinski
2020-05-09  0:57   ` Jakub Kicinski
2020-05-09  1:57   ` Finn Thain
2020-05-09  1:57     ` Finn Thain
2020-05-09  2:04     ` Jakub Kicinski
2020-05-09  2:04       ` Jakub Kicinski
2020-05-09  1:54 ` Jakub Kicinski
2020-05-09  1:54   ` Jakub Kicinski
2020-05-09 16:47   ` Christophe JAILLET
2020-05-09 16:47     ` Christophe JAILLET
2020-05-09 18:13     ` Jakub Kicinski
2020-05-09 18:13       ` Jakub Kicinski
2020-05-09 20:31       ` Christophe JAILLET
2020-05-09 20:31         ` Christophe JAILLET
2020-05-09 22:42       ` Joe Perches
2020-05-09 22:42         ` Joe Perches
2020-05-09 23:32         ` David Miller
2020-05-09 23:32           ` David Miller
2020-05-09 23:41           ` Joe Perches
2020-05-09 23:41             ` Joe Perches
2020-05-09 23:52   ` Finn Thain
2020-05-09 23:52     ` Finn Thain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.