Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp10634541rwb; Fri, 25 Nov 2022 06:27:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf7zhkork/0NxKmovWD0BqPE3wP1z68ejOMm9y6iMAA7EyqgztDrDg+pLdsIZwVp2aVplOug X-Received: by 2002:a17:902:ce90:b0:186:b46d:da5e with SMTP id f16-20020a170902ce9000b00186b46dda5emr19031228plg.92.1669386473986; Fri, 25 Nov 2022 06:27:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669386473; cv=none; d=google.com; s=arc-20160816; b=pXZ/b0SqIK8XEGdlVTrsjWcvoX4nsVzzj0wbSytENNqwJPI6+fo/bwJVmFRl6raPJK 6nDrxhq3XT6i44SApoPFAv7tu5YlzEeEjRWcd14D83wf642/M5RCQzsi22I2nXj4XTdQ 6PggKhDATI/D8bDLISN4wfaXa02OguKVkwUF0ebH/KIRNpOGCLc7ffgpbjtOa7TnRjX3 F17bJrTIoM9t5GofLA2JwAHwWDsxrWzUgzHBa1a6urTlN1bjJmejMMBIWdDk64ZGh0sQ OW9wGCJnrS0GL5SfqcCm50Ira3PAqA+rFl95VQVifj/+lxFwVYuJ7uOGNb7VdRMGq3Eo b4vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=a1zsrAKGnXFwdy/1ztFfJyX1M7pb02YkwVe2IMX8SNQ=; b=0FJEOEG+zc1zu0Uf9tdtlX6AQTPlZkusi2qrLwpddDsPP3zzEQWcb7/jaibZL+0qeH JeOwjWUGn4SAnMZW8oGGdoGN5SUEmOUE1kp+LLDiHhiAAQ5Z2VhxouqDZlkGFCZsIv+D kD5oEVzIJwqSx00KeERspqDRqfr7C7ZygE33MR5zmMBlRshhEjn87HPXhQgP7Ur6l0pc MFxKBEQaXBvQlibooNLLV4GKXlr5GOkh+Lnc0Ra0WAe9SVVZmol7A+bbNxm1iguUdA6r R/ea0xRy6pkBw7gpUxb9OIYlIKdFkmTHBXP/cxC6N/+zlOqFgX6vU2WUdHXuj86DyEa2 sIhQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a65580e000000b00460c67afbd9si3698064pgr.771.2022.11.25.06.27.43; Fri, 25 Nov 2022 06:27:53 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbiKYOOD (ORCPT + 85 others); Fri, 25 Nov 2022 09:14:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiKYON7 (ORCPT ); Fri, 25 Nov 2022 09:13:59 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B06A209B4 for ; Fri, 25 Nov 2022 06:13:59 -0800 (PST) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oyZSY-0001ux-7X; Fri, 25 Nov 2022 15:13:42 +0100 Received: from pengutronix.de (unknown [IPv6:2a03:f580:87bc:d400:339c:bb17:19c8:3a96]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 1EFA5129BF0; Fri, 25 Nov 2022 14:13:36 +0000 (UTC) Date: Fri, 25 Nov 2022 15:13:34 +0100 From: Marc Kleine-Budde To: Zhang Changzhong Cc: Wolfgang Grandegger , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Julia Lawall , Pavel Cheblakov , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] can: sja1000: plx_pci: fix error handling path in plx_pci_add_card() Message-ID: <20221125141334.yhnye7psko3pih5u@pengutronix.de> References: <1669383975-17332-1-git-send-email-zhangchangzhong@huawei.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mcxjcl67uddrktzz" Content-Disposition: inline In-Reply-To: <1669383975-17332-1-git-send-email-zhangchangzhong@huawei.com> X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 --mcxjcl67uddrktzz Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 25.11.2022 21:46:14, Zhang Changzhong wrote: > If pci_iomap() or register_sja1000dev() fails, netdev will not be > registered, but plx_pci_del_card() still deregisters the netdev. >=20 > To avoid this, let's free the netdev and clear card->net_dev[i] before > calling plx_pci_del_card(). In addition, add the missing pci_iounmap() > when the channel does not exist. >=20 > Compile tested only. >=20 > Fixes: 951f2f960e5b ("drivers/net/can/sja1000/plx_pci.c: eliminate double= free") > Fixes: 24c4a3b29255 ("can: add support for CAN interface cards based on t= he PLX90xx PCI bridge") > Signed-off-by: Zhang Changzhong > --- > v1->v2: switch to goto style fix. >=20 > drivers/net/can/sja1000/plx_pci.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/net/can/sja1000/plx_pci.c b/drivers/net/can/sja1000/= plx_pci.c > index 5de1ebb..134a8cb 100644 > --- a/drivers/net/can/sja1000/plx_pci.c > +++ b/drivers/net/can/sja1000/plx_pci.c > @@ -678,7 +678,7 @@ static int plx_pci_add_card(struct pci_dev *pdev, > if (!addr) { > err =3D -ENOMEM; > dev_err(&pdev->dev, "Failed to remap BAR%d\n", cm->bar); > - goto failure_cleanup; > + goto failure_free_dev; > } > =20 > priv->reg_base =3D addr + cm->offset; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > @@ -699,7 +699,7 @@ static int plx_pci_add_card(struct pci_dev *pdev, > if (err) { > dev_err(&pdev->dev, "Registering device failed " > "(err=3D%d)\n", err); > - goto failure_cleanup; > + goto failure_iounmap; > } > =20 > card->channels++; > @@ -710,6 +710,7 @@ static int plx_pci_add_card(struct pci_dev *pdev, > } else { > dev_err(&pdev->dev, "Channel #%d not detected\n", > i + 1); > + pci_iounmap(pdev, priv->reg_base); > free_sja1000dev(dev); > card->net_dev[i] =3D NULL; > } > @@ -738,6 +739,11 @@ static int plx_pci_add_card(struct pci_dev *pdev, > } > return 0; > =20 > +failure_iounmap: > + pci_iounmap(pdev, priv->reg_base); ^^^^^^^^^^^^^^ reg_base it not that what has been mapped, but with an offset. > +failure_free_dev: > + free_sja1000dev(dev); > + card->net_dev[i] =3D NULL; > failure_cleanup: > dev_err(&pdev->dev, "Error: %d. Cleaning Up.\n", err); Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | --mcxjcl67uddrktzz Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEBsvAIBsPu6mG7thcrX5LkNig010FAmOAzYsACgkQrX5LkNig 013gVAf/eoxKhqdlLtB4JTg3JaizhFwwl41YUevHC7Dlat2okHGtUnykIt2vCHeF EUAWo/MrsatxXMz7R/jtJvx5Qv+EzgI+uiqrjglnY1t/Ed0A2jG2iIR79prAicrq /XBXa7pVa0fXABPh3JfFpRIpesAabSVodfqSzmCUCY4m6sERDo7IyrbCzr1ofobX mNfquHUsph6/YtaGBThFngmW+7ocaCjqRJ8iqdZW5oH3ATzMX+7+8qbGJAdioFS4 PmxLkscOhMUZo3zGy8b8OiFEzGdDLqca1jCoXZjoui2/J6jQdfZK6fLkGIfFGff5 r1BWMocts1AFlB1KbK4p9kteDvnriw== =K+FC -----END PGP SIGNATURE----- --mcxjcl67uddrktzz--