linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next 1/2] xtensa: iss: fix handling error cases in iss_net_configure()
@ 2022-07-05 13:20 Yang Yingliang
  2022-07-05 13:20 ` [PATCH -next 2/2] xtensa: iss: change the return type of iss_net_configure() to void Yang Yingliang
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang @ 2022-07-05 13:20 UTC (permalink / raw)
  To: linux-kernel, linux-xtensa; +Cc: chris, jcmvbkbc

The 'pdev' and 'netdev' need be release in error cases of iss_net_configure().
In orde to fix this, add two labels for error case to release them.

Fixes: 7282bee78798 ("[PATCH] xtensa: Architecture support for Tensilica Xtensa Part 8")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 arch/xtensa/platforms/iss/network.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/arch/xtensa/platforms/iss/network.c b/arch/xtensa/platforms/iss/network.c
index fd84d4891758..5e475f7472e4 100644
--- a/arch/xtensa/platforms/iss/network.c
+++ b/arch/xtensa/platforms/iss/network.c
@@ -481,7 +481,7 @@ static int iss_net_configure(int index, char *init)
 	dev = alloc_etherdev(sizeof(*lp));
 	if (dev == NULL) {
 		pr_err("eth_configure: failed to allocate device\n");
-		return 1;
+		return -ENOMEM;
 	}
 
 	/* Initialize private element. */
@@ -509,7 +509,8 @@ static int iss_net_configure(int index, char *init)
 	if (!tuntap_probe(lp, index, init)) {
 		pr_err("%s: invalid arguments. Skipping device!\n",
 		       dev->name);
-		goto errout;
+		err = -EINVAL;
+		goto err_free_netdev;
 	}
 
 	pr_info("Netdevice %d (%pM)\n", index, dev->dev_addr);
@@ -517,7 +518,9 @@ static int iss_net_configure(int index, char *init)
 	/* sysfs register */
 
 	if (!driver_registered) {
-		platform_driver_register(&iss_net_driver);
+		err = platform_driver_register(&iss_net_driver);
+		if (err)
+			goto err_free_netdev;
 		driver_registered = 1;
 	}
 
@@ -527,7 +530,9 @@ static int iss_net_configure(int index, char *init)
 
 	lp->pdev.id = index;
 	lp->pdev.name = DRIVER_NAME;
-	platform_device_register(&lp->pdev);
+	err = platform_device_register(&lp->pdev);
+	if (err)
+		goto err_free_netdev;
 	SET_NETDEV_DEV(dev, &lp->pdev.dev);
 
 	dev->netdev_ops = &iss_netdev_ops;
@@ -541,18 +546,18 @@ static int iss_net_configure(int index, char *init)
 
 	if (err) {
 		pr_err("%s: error registering net device!\n", dev->name);
-		/* XXX: should we call ->remove() here? */
-		free_netdev(dev);
-		return 1;
+		goto err_unregister_device;
 	}
 
 	timer_setup(&lp->tl, iss_net_user_timer_expire, 0);
 
 	return 0;
 
-errout:
-	/* FIXME: unregister; free, etc.. */
-	return -EIO;
+err_unregister_device:
+	platform_device_unregister(&lp->pdev);
+err_free_netdev:
+	free_netdev(dev);
+	return err;
 }
 
 /* ------------------------------------------------------------------------- */
-- 
2.25.1


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

end of thread, other threads:[~2022-07-06  1:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-05 13:20 [PATCH -next 1/2] xtensa: iss: fix handling error cases in iss_net_configure() Yang Yingliang
2022-07-05 13:20 ` [PATCH -next 2/2] xtensa: iss: change the return type of iss_net_configure() to void Yang Yingliang
2022-07-05 15:59   ` Max Filippov
2022-07-06  1:33     ` Yang Yingliang

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).