From nobody Sun Apr 19 04:03:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33258C433EF for ; Thu, 7 Jul 2022 02:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234798AbiGGCXD (ORCPT ); Wed, 6 Jul 2022 22:23:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230246AbiGGCXB (ORCPT ); Wed, 6 Jul 2022 22:23:01 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 895622F38D for ; Wed, 6 Jul 2022 19:22:56 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4LdgCd5c3Dz1DDN6; Thu, 7 Jul 2022 10:22:05 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 7 Jul 2022 10:22:51 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 7 Jul 2022 10:22:50 +0800 From: Yang Yingliang To: , CC: , Subject: [PATCH -next v2] xtensa: iss: fix handling error cases in iss_net_configure() Date: Thu, 7 Jul 2022 10:32:29 +0800 Message-ID: <20220707023229.2580893-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. And Change the return type of iss_net_configure() to void, because it's not= used. Fixes: 7282bee78798 ("[PATCH] xtensa: Architecture support for Tensilica Xt= ensa Part 8") Reported-by: Hulk Robot Signed-off-by: Yang Yingliang --- v2: change return type of iss_net_configure() to void --- arch/xtensa/platforms/iss/network.c | 33 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/arch/xtensa/platforms/iss/network.c b/arch/xtensa/platforms/is= s/network.c index fd84d4891758..aeb5828a639c 100644 --- a/arch/xtensa/platforms/iss/network.c +++ b/arch/xtensa/platforms/iss/network.c @@ -472,16 +472,15 @@ static const struct net_device_ops iss_netdev_ops =3D= { .ndo_set_rx_mode =3D iss_net_set_multicast_list, }; =20 -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; =20 dev =3D alloc_etherdev(sizeof(*lp)); if (dev =3D=3D NULL) { pr_err("eth_configure: failed to allocate device\n"); - return 1; + return; } =20 /* Initialize private element. */ @@ -509,7 +508,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; } =20 pr_info("Netdevice %d (%pM)\n", index, dev->dev_addr); @@ -517,7 +516,8 @@ static int iss_net_configure(int index, char *init) /* sysfs register */ =20 if (!driver_registered) { - platform_driver_register(&iss_net_driver); + if (platform_driver_register(&iss_net_driver)) + goto err_free_netdev; driver_registered =3D 1; } =20 @@ -527,7 +527,8 @@ static int iss_net_configure(int index, char *init) =20 lp->pdev.id =3D index; lp->pdev.name =3D DRIVER_NAME; - platform_device_register(&lp->pdev); + if (platform_device_register(&lp->pdev)) + goto err_free_netdev; SET_NETDEV_DEV(dev, &lp->pdev.dev); =20 dev->netdev_ops =3D &iss_netdev_ops; @@ -536,23 +537,21 @@ static int iss_net_configure(int index, char *init) dev->irq =3D -1; =20 rtnl_lock(); - err =3D 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; + goto err_unregister_device; } + rtnl_unlock(); =20 timer_setup(&lp->tl, iss_net_user_timer_expire, 0); =20 - return 0; + return; =20 -errout: - /* FIXME: unregister; free, etc.. */ - return -EIO; +err_unregister_device: + platform_device_unregister(&lp->pdev); +err_free_netdev: + free_netdev(dev); } =20 /* -----------------------------------------------------------------------= -- */ --=20 2.25.1