linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Navid Emamdoost <navid.emamdoost@gmail.com>
Cc: natechancellor@gmail.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org, emamd001@umn.edu
Subject: Re: [PATCH v2] PCI/IOV: Fix memory leak in pci_iov_add_virtfn()
Date: Tue, 26 Nov 2019 17:35:32 -0600	[thread overview]
Message-ID: <20191126233532.GA215615@google.com> (raw)
In-Reply-To: <20191125195255.23740-1-navid.emamdoost@gmail.com>

On Mon, Nov 25, 2019 at 01:52:52PM -0600, Navid Emamdoost wrote:
> In the implementation of pci_iov_add_virtfn() the allocated virtfn is
> leaked if pci_setup_device() fails. The error handling is not calling
> pci_stop_and_remove_bus_device(). Change the goto label to failed2.
> 
> Fixes: 156c55325d30 ("PCI: Check for pci_setup_device() failure in pci_iov_add_virtfn()")
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>

Applied to pci/virtualization for v5.6, thanks!

> ---
> Changes in v2:
> 	- rename the labels for error paths
> ---
>  drivers/pci/iov.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index b3f972e8cfed..deec9f9e0b61 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -187,10 +187,10 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id)
>  	sprintf(buf, "virtfn%u", id);
>  	rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf);
>  	if (rc)
> -		goto failed2;
> +		goto failed1;
>  	rc = sysfs_create_link(&virtfn->dev.kobj, &dev->dev.kobj, "physfn");
>  	if (rc)
> -		goto failed3;
> +		goto failed2;
>  
>  	kobject_uevent(&virtfn->dev.kobj, KOBJ_CHANGE);
>  
> @@ -198,11 +198,10 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id)
>  
>  	return 0;
>  
> -failed3:
> -	sysfs_remove_link(&dev->dev.kobj, buf);
>  failed2:
> -	pci_stop_and_remove_bus_device(virtfn);
> +	sysfs_remove_link(&dev->dev.kobj, buf);
>  failed1:
> +	pci_stop_and_remove_bus_device(virtfn);
>  	pci_dev_put(dev);
>  failed0:
>  	virtfn_remove_bus(dev->bus, bus);
> -- 
> 2.17.1
> 

  reply	other threads:[~2019-11-26 23:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 19:31 [PATCH] PCI/IOV: Fix memory leak in pci_iov_add_virtfn() Navid Emamdoost
2019-11-25 18:04 ` Nathan Chancellor
2019-11-25 19:33   ` Navid Emamdoost
2019-11-25 19:52   ` [PATCH v2] " Navid Emamdoost
2019-11-26 23:35     ` Bjorn Helgaas [this message]
2019-11-28  7:08     ` Markus Elfring

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=20191126233532.GA215615@google.com \
    --to=helgaas@kernel.org \
    --cc=emamd001@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=natechancellor@gmail.com \
    --cc=navid.emamdoost@gmail.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).