diff mbox series

[v2] PCI/IOV: Fix memory leak in pci_iov_add_virtfn()

Message ID 20191125195255.23740-1-navid.emamdoost@gmail.com
State New
Delegated to: Bjorn Helgaas
Headers show
Series [v2] PCI/IOV: Fix memory leak in pci_iov_add_virtfn() | expand

Commit Message

Navid Emamdoost Nov. 25, 2019, 7:52 p.m. UTC
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>
---
Changes in v2:
	- rename the labels for error paths
---
 drivers/pci/iov.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Bjorn Helgaas Nov. 26, 2019, 11:35 p.m. UTC | #1
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
>
Markus Elfring Nov. 28, 2019, 7:08 a.m. UTC | #2
> 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.

Would it be nicer to rename numbered labels also according to the
Linux coding style?

Regards,
Markus
diff mbox series

Patch

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