netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Zhang Changzhong <zhangchangzhong@huawei.com>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Julia Lawall <julia@diku.dk>,
	Pavel Cheblakov <P.B.Cheblakov@inp.nsk.su>,
	linux-can@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] can: sja1000: plx_pci: fix error handling path in plx_pci_add_card()
Date: Thu, 24 Nov 2022 15:46:38 +0100	[thread overview]
Message-ID: <20221124144638.kqbmksqntn2dugal@pengutronix.de> (raw)
In-Reply-To: <1669029031-7743-1-git-send-email-zhangchangzhong@huawei.com>

[-- Attachment #1: Type: text/plain, Size: 2192 bytes --]

On 21.11.2022 19:10:30, Zhang Changzhong wrote:
> If pci_iomap() or register_sja1000dev() fails, netdev will not be
> registered, but plx_pci_del_card() still deregisters the netdev.
> 
> 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.
> 
> Compile tested only.
> 
> Fixes: 951f2f960e5b ("drivers/net/can/sja1000/plx_pci.c: eliminate double free")
> Fixes: 24c4a3b29255 ("can: add support for CAN interface cards based on the PLX90xx PCI bridge")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
> ---
>  drivers/net/can/sja1000/plx_pci.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/can/sja1000/plx_pci.c b/drivers/net/can/sja1000/plx_pci.c
> index 5de1ebb..1158f5a 100644
> --- a/drivers/net/can/sja1000/plx_pci.c
> +++ b/drivers/net/can/sja1000/plx_pci.c
> @@ -678,6 +678,8 @@ static int plx_pci_add_card(struct pci_dev *pdev,
>  		if (!addr) {
>  			err = -ENOMEM;
>  			dev_err(&pdev->dev, "Failed to remap BAR%d\n", cm->bar);
> +			free_sja1000dev(dev);
> +			card->net_dev[i] = NULL;
>  			goto failure_cleanup;
>  		}
>  
> @@ -699,6 +701,9 @@ static int plx_pci_add_card(struct pci_dev *pdev,
>  			if (err) {
>  				dev_err(&pdev->dev, "Registering device failed "
>  					"(err=%d)\n", err);
> +				pci_iounmap(pdev, priv->reg_base);
> +				free_sja1000dev(dev);
> +				card->net_dev[i] = NULL;
>  				goto failure_cleanup;
>  			}
>  
> @@ -710,6 +715,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] = NULL;

There's quite some cleanup code doubling. Can you introduce a goto style
cleanup?

Marc

-- 
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 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2022-11-24 14:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-21 11:10 [PATCH] can: sja1000: plx_pci: fix error handling path in plx_pci_add_card() Zhang Changzhong
2022-11-24 14:46 ` Marc Kleine-Budde [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221124144638.kqbmksqntn2dugal@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=P.B.Cheblakov@inp.nsk.su \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=julia@diku.dk \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=wg@grandegger.com \
    --cc=zhangchangzhong@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).