Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3431405imw; Thu, 7 Jul 2022 01:25:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uSxq16p8O/Ok0/mUopz0VD4oR9ZFuUNp3NXyNWPnizb2ItioGOlS9qFS3VQhJm2iQR4Gz9 X-Received: by 2002:a17:90b:1b07:b0:1ec:c617:a314 with SMTP id nu7-20020a17090b1b0700b001ecc617a314mr3652845pjb.214.1657182300822; Thu, 07 Jul 2022 01:25:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657182300; cv=none; d=google.com; s=arc-20160816; b=0CkujZ2mTdGFXfdadtMKCjLhGEBXfkkN3NdQc5tuIaVBj5/NMwqIroD8VDInsANpRf /rysfHYkEtI4yVbiEEGvg1uZPt6fEqZA3aws3mE4lwcxj00xIbe04wZmBtIno/82AWdk LDwL847IYfwIDiHlNMBZoXUUgDuqQaD+OISLX7S9ztTl/30gPruOCPmhF1IPeqm/bR0s s31ZjC8K90w+xbbkdrzLwMIURp47ESMD8DHMLkIBRqqn8jqZ0fXR5/HFP1Zsj+KuB62b C2u25nGbvGD6nwtr6/oeUcsLl/jKIJIxeR/bQBMpHNS/QFWiDcbThe2/luZ6U+myVSfe 4u+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=j6z46hiTjAFvo7B2XUi7zY5HtGJndA6IMLx4jpxUBEs=; b=FfrAwQRNAkW42gllZWeyCBnFrZzuDppTJpbxwfC4RR8HJAjEUozDIgduzbiKStbBUN oO5pMUJjhzmiCEjYik2H2aYGnxvgpphNE04+GUGkH1AViT7LRfdlGmgFamGzHBdAHrdj fu9lIVY1ruy3gk7trc1ZGcf9nhvVM/rPtv/z8ka5XbASaw64vOXQDidm/x2aE0x2lhwz 59AxaeE8ypf32HwrjkJ7FNQNWbPczQsO/ZPOUGDXIxscuGlZwj2PmhBkLJazWzxcnREH 9zGYjGUm+5h+QRA7419S2BcXJKqX0psVYKKEzHxxGzz+CvNh8c9Dj3Gpg0qyqXrfgWm9 zSYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bvUt6Y9q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s5-20020a170902988500b0016a22de096bsi48140872plp.337.2022.07.07.01.24.48; Thu, 07 Jul 2022 01:25:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bvUt6Y9q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235253AbiGGIIO (ORCPT + 99 others); Thu, 7 Jul 2022 04:08:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235225AbiGGIIF (ORCPT ); Thu, 7 Jul 2022 04:08:05 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A87C533E1D for ; Thu, 7 Jul 2022 01:08:04 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id q82so9936246pgq.6 for ; Thu, 07 Jul 2022 01:08:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j6z46hiTjAFvo7B2XUi7zY5HtGJndA6IMLx4jpxUBEs=; b=bvUt6Y9q5nJpoMf/TkNjPflp+QVRATuQJM+2Uz7UJqp5EPiPO9hm1iPptdnP29Trgf GF8WQsnxlTuUGqBNzyeIrVmI5q9W6vwey6WxSeyrkaqn60+So2cU+4e08ECU+TrKbmXB 5USm+ODMNCXqVHy+ehQtT/1Qpj942xdwA2svdpclRz1B3embRd28Tk6pE/rlKQMOEtx5 jLNtHAz91agwo3TMpRDlobNcVwJm0b5wPOIQ/11YylkiN8qgEbpBHnwsH0MziF35SVc4 WS8fvK93/1WmrbX0ZJPqzX3hKzOKncxEvYWolJjp1eRxtfzR/tZMeBw8nZd4Oj82TPtw XBCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j6z46hiTjAFvo7B2XUi7zY5HtGJndA6IMLx4jpxUBEs=; b=sfF5dW9VlHC524GeB7dt8PccCR0iyOClGdmbZb+dxzkWpjKnklz9PvW2sh/fb94cDv YKWgld618K6LeS0VQyNlCyAK4bpEyw1+lXN5anlY6sa3hRe7qKoCfZW4SCgLXRR2mXP4 A+SZN9EjTOtcbKPTy8bj+iI9Ui8zOfJTqIAv6ZdHQHWk6aY81HPaPqzZoE7ZLda2U9xC z6XKaiZfrBR72jLZWvSGdPyoF0Cg9ZL3R7M2v5vRxZvDo5KvaNjwaFIycVbfLThlwR6y AtdjoKi1nSTPhSmSd+Q71ZGPRaP580dRsGZQRl39zwjBlPlpQAdArMtjtKqBgrike7bG u5MA== X-Gm-Message-State: AJIora9Zzqeeak/1yu3AMj42JOGDrx0BuyKKFrjMK28aoC3vKLDbq9tg ZqjZyCXCn/3w0SLAe2vTaZU= X-Received: by 2002:a63:4343:0:b0:411:e30c:fad8 with SMTP id q64-20020a634343000000b00411e30cfad8mr28570543pga.278.1657181284242; Thu, 07 Jul 2022 01:08:04 -0700 (PDT) Received: from octofox.hsd1.ca.comcast.net ([2601:641:401:1d20:a3e3:ea8c:2267:a237]) by smtp.gmail.com with ESMTPSA id p4-20020a170902e74400b0016c0c82e85csm1377374plf.75.2022.07.07.01.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 01:08:03 -0700 (PDT) From: Max Filippov To: linux-xtensa@linux-xtensa.org Cc: Chris Zankel , linux-kernel@vger.kernel.org, Yang Yingliang , Hulk Robot , Max Filippov Subject: [PATCH v3 3/3] xtensa: iss: fix handling error cases in iss_net_configure() Date: Thu, 7 Jul 2022 01:08:01 -0700 Message-Id: <20220707080801.3496148-4-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220707080801.3496148-1-jcmvbkbc@gmail.com> References: <20220707080801.3496148-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, FROM_LOCAL_NOVOWEL,HK_RANDOM_ENVFROM,HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yang Yingliang 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 Signed-off-by: Yang Yingliang Signed-off-by: Max Filippov --- Changes v2->v3: - drop err_unregister_device label and return after calling platform_device_unregister in case of register_netdevice failure Changes v1->v2: - change return type of iss_net_configure() to void 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 2a22e80a488d..9ac46ab3a296 100644 --- a/arch/xtensa/platforms/iss/network.c +++ b/arch/xtensa/platforms/iss/network.c @@ -475,16 +475,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. */ @@ -511,7 +510,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); @@ -519,14 +518,16 @@ 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; } 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; @@ -535,23 +536,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.30.2