Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp1188955pxw; Sat, 9 Apr 2022 14:44:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqxeYdZOIH532ZxdwC11mhLMJzcR+t7jzwhhokom6/v14vkELKpV0aAjYWv54hQq+fkcZ8 X-Received: by 2002:a05:6a00:2450:b0:4f7:bf07:c063 with SMTP id d16-20020a056a00245000b004f7bf07c063mr25693384pfj.51.1649540645255; Sat, 09 Apr 2022 14:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649540645; cv=none; d=google.com; s=arc-20160816; b=Toi4y0jx5YIzGJZG8Q1vHwdBJ4atLX94fP7iojuutpjwm3TI5GAZ2VNBC0nepOZdqH /iws8ZSytJ0pnolWpuF1w+QRLG4VAelHQ9G/XULlgPNcBq8GwcQ2zgZn05d73wqQiwhY 5WpBT4Qskt0TnMgkZHrdWNZEd9LCLOQKgoNgdq7bvMXMj/M+3ABEGA1j9BZt2Cz+pY6A OcmLG5b2+/iqcL1qnD2sPvC9L5ZPQLG0gKIZzwwcGrIL7ocNA6o9qwosrWn7K3WpE9oN YnDJoRr8uA9TcnfRKlthmJx18UTVaRUw6u9y9DjfYncteCxSajzFMu5DSDMiI+P8jvSW z+bA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=pA0w4O8CRiuXzvroFL62p9tDgX2SohP+G9Ok90h6Fcc=; b=Wbsj2n/OLCuedraN5QvEj1y3d8L64G8C8mNDh9PKMr036CDsGE3kPEVxUuCj6WqNV1 VzPwWbQY5sGYQ5eAFS0RZ9E1tz8OGOgwc3daagNFkB8NibNX869IxUAR8JxF37DPNso0 Nuy6ps6FEwFnnikXdpsId5Q2ZxzkLh7Jd41xzyKSvHDKhiXC5lT8jKnlYGi5vNSVwZKm J/pb6N+qOf4eV/du6L+ddR8EFabyWfDWeMXFJCrENTWijer4hqPERsTJwydAwqvCb/3o taRr6OrYUZzn3QLNBBPf+4KUcwICyVN4YNreWQ+W/EhDvIkwxrnqFh9s+Nox71PaJYC1 PYCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=L3Biklhb; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 n16-20020a170902e55000b00153b2d1654dsi4777218plf.341.2022.04.09.14.43.43; Sat, 09 Apr 2022 14:44:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=L3Biklhb; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 S237452AbiDIG1K (ORCPT + 69 others); Sat, 9 Apr 2022 02:27:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233998AbiDIG1I (ORCPT ); Sat, 9 Apr 2022 02:27:08 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A353638B1; Fri, 8 Apr 2022 23:25:02 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id s14so113328plk.8; Fri, 08 Apr 2022 23:25:02 -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:mime-version :content-transfer-encoding; bh=pA0w4O8CRiuXzvroFL62p9tDgX2SohP+G9Ok90h6Fcc=; b=L3BiklhbmiTW5WIODOPjQsK+EqQy7cAIB1x2Ta48ZFCfL4ylkePY8rt0k48ijrGnZi yixG4Dzh0uwl7HYOFM7N+jvM0QLUjtKWdA4yb2tPDqQk6EcusiqFXjMOhfl8Jll3ABuc zDDTkFd7lclif8zLg4LqGoqfkPhI/qwY8YJcTeuVnc/+n9mRAbI0WS19SP9HGW+/eExk 3QMpyEg2nHGqLpYREc01qy10tC2Vqro0SaIcXAh4xq4ZwiE6u9+8w4t+waUqLgmM34iY l3EkMkk1EhIX+gEuD4Wp2BK0aa4uKjbp3DYjNVA57eakqIhvLkV7URyfm0gg7kxs23Q8 PReQ== 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:mime-version :content-transfer-encoding; bh=pA0w4O8CRiuXzvroFL62p9tDgX2SohP+G9Ok90h6Fcc=; b=bxlqsgxb2fj4d1Z0iKItHO+eXub6Jhqg1BEx3uldIOXzB1Wm8JRvzEz7owas1is+3C nNt8YN8AzGOPa2ia+Ob6gUROGDN0zwV3R7OeYYKbQXAYdgD4xOkHDH0r7m1/Yd4c/9gY dkc8mMXuD0b0/hPqnL3Q0KRc+r9/VpwoMR4KxOx0csfqJuLaowrVdiqw1dyUna5IG5w1 CvlNyCw34cugMnXoGP7mvbNsgGKldZu+Bi4UVs1iqwLgSwO6+c+l5Wa2n2GrDjBHjnR8 FFzGrClHYHO1GTdZGm6SJhM246Ek7SJoJVF02aOu24l47tZcwEU9ZgfhmUVBRBO6pN3K 6Yuw== X-Gm-Message-State: AOAM533dFdYVXUr5RoJl2aa/uyH4lQCqUSKrkWijZh0BlQA+eHgxS4OZ JLgOsvhGykiHyxpV0cXITA== X-Received: by 2002:a17:90b:1e4e:b0:1c7:3507:30db with SMTP id pi14-20020a17090b1e4e00b001c7350730dbmr25713445pjb.39.1649485502117; Fri, 08 Apr 2022 23:25:02 -0700 (PDT) Received: from localhost.localdomain ([144.202.91.207]) by smtp.gmail.com with ESMTPSA id 8-20020a056a00070800b004e14ae3e8d7sm26387128pfl.164.2022.04.08.23.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Apr 2022 23:25:01 -0700 (PDT) From: Zheyu Ma To: stas.yakovlev@gmail.com, kvalo@kernel.org, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Zheyu Ma Subject: [PATCH] wireless: ipw2x00: Refine the error handling of ipw2100_pci_init_one() Date: Sat, 9 Apr 2022 14:24:49 +0800 Message-Id: <20220409062449.3752252-1-zheyuma97@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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-wireless@vger.kernel.org The driver should release resources in reverse order, i.e., the resources requested first should be released last, and the driver should adjust the order of error handling code by this rule. Signed-off-by: Zheyu Ma --- drivers/net/wireless/intel/ipw2x00/ipw2100.c | 34 +++++++++----------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/intel/ipw2x00/ipw2100.c b/drivers/net/wireless/intel/ipw2x00/ipw2100.c index 2ace2b27ecad..b10d10660eb8 100644 --- a/drivers/net/wireless/intel/ipw2x00/ipw2100.c +++ b/drivers/net/wireless/intel/ipw2x00/ipw2100.c @@ -6166,7 +6166,7 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev, printk(KERN_WARNING DRV_NAME "Error calling ioremap.\n"); err = -EIO; - goto fail; + goto out; } /* allocate and initialize our net_device */ @@ -6175,36 +6175,33 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev, printk(KERN_WARNING DRV_NAME "Error calling ipw2100_alloc_device.\n"); err = -ENOMEM; - goto fail; + goto fail_iounmap; } + priv = libipw_priv(dev); + pci_set_master(pci_dev); + pci_set_drvdata(pci_dev, priv); + /* set up PCI mappings for device */ err = pci_enable_device(pci_dev); if (err) { printk(KERN_WARNING DRV_NAME "Error calling pci_enable_device.\n"); - return err; + goto fail_dev; } - priv = libipw_priv(dev); - - pci_set_master(pci_dev); - pci_set_drvdata(pci_dev, priv); - err = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32)); if (err) { printk(KERN_WARNING DRV_NAME "Error calling pci_set_dma_mask.\n"); - pci_disable_device(pci_dev); - return err; + goto fail_disable; } err = pci_request_regions(pci_dev, DRV_NAME); if (err) { printk(KERN_WARNING DRV_NAME "Error calling pci_request_regions.\n"); - pci_disable_device(pci_dev); - return err; + goto fail_disable; } /* We disable the RETRY_TIMEOUT register (0x41) to keep @@ -6306,9 +6303,13 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev, out: return err; - fail_unlock: +fail_unlock: mutex_unlock(&priv->action_mutex); - fail: +fail: + pci_release_regions(pci_dev); +fail_disable: + pci_disable_device(pci_dev); +fail_dev: if (dev) { if (registered >= 2) unregister_netdev(dev); @@ -6334,11 +6335,8 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev, free_libipw(dev, 0); } - +fail_iounmap: pci_iounmap(pci_dev, ioaddr); - - pci_release_regions(pci_dev); - pci_disable_device(pci_dev); goto out; } -- 2.25.1