[PATCH 5.19 0807/1157] xtensa: iss: fix handling error cases in iss_net_configure()

From: Greg Kroah-Hartman
Date: Tue Aug 16 2022 - 00:44:49 EST


From: Yang Yingliang <yangyingliang@xxxxxxxxxx>

[ Upstream commit 628ccfc8f5f79dd548319408fcc53949fe97b258 ]

The 'pdev' and 'netdev' need to be released in error cases of
iss_net_configure().

Change the return type of iss_net_configure() to void, because it's
not used.

Fixes: 7282bee78798 ("[PATCH] xtensa: Architecture support for Tensilica Xtensa Part 8")
Reported-by: Hulk Robot <hulkci@xxxxxxxxxx>
Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
Signed-off-by: Max Filippov <jcmvbkbc@xxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
arch/xtensa/platforms/iss/network.c | 32 ++++++++++++++---------------
1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/arch/xtensa/platforms/iss/network.c b/arch/xtensa/platforms/iss/network.c
index f0c652c1b438..3805dc2c259c 100644
--- a/arch/xtensa/platforms/iss/network.c
+++ b/arch/xtensa/platforms/iss/network.c
@@ -481,16 +481,15 @@ static void iss_net_pdev_release(struct device *dev)
free_netdev(lp->dev);
}

-static int iss_net_configure(int index, char *init)
+static void iss_net_configure(int index, char *init)
{
struct net_device *dev;
struct iss_net_private *lp;
- int err;

dev = alloc_etherdev(sizeof(*lp));
if (dev == NULL) {
pr_err("eth_configure: failed to allocate device\n");
- return 1;
+ return;
}

/* Initialize private element. */
@@ -518,7 +517,7 @@ 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;
+ goto err_free_netdev;
}

pr_info("Netdevice %d (%pM)\n", index, dev->dev_addr);
@@ -526,7 +525,8 @@ static int iss_net_configure(int index, char *init)
/* sysfs register */

if (!driver_registered) {
- platform_driver_register(&iss_net_driver);
+ if (platform_driver_register(&iss_net_driver))
+ goto err_free_netdev;
driver_registered = 1;
}

@@ -537,7 +537,8 @@ static int iss_net_configure(int index, char *init)
lp->pdev.id = index;
lp->pdev.name = DRIVER_NAME;
lp->pdev.dev.release = iss_net_pdev_release;
- platform_device_register(&lp->pdev);
+ if (platform_device_register(&lp->pdev))
+ goto err_free_netdev;
SET_NETDEV_DEV(dev, &lp->pdev.dev);

dev->netdev_ops = &iss_netdev_ops;
@@ -546,23 +547,20 @@ static int iss_net_configure(int index, char *init)
dev->irq = -1;

rtnl_lock();
- err = register_netdevice(dev);
- rtnl_unlock();
-
- if (err) {
+ if (register_netdevice(dev)) {
+ rtnl_unlock();
pr_err("%s: error registering net device!\n", dev->name);
- /* XXX: should we call ->remove() here? */
- free_netdev(dev);
- return 1;
+ platform_device_unregister(&lp->pdev);
+ return;
}
+ rtnl_unlock();

timer_setup(&lp->tl, iss_net_user_timer_expire, 0);

- return 0;
+ return;

-errout:
- /* FIXME: unregister; free, etc.. */
- return -EIO;
+err_free_netdev:
+ free_netdev(dev);
}

/* ------------------------------------------------------------------------- */
--
2.35.1