linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pci/hotplug: fix potential memory leak in disable_slot()
@ 2021-03-21 15:51 Zhiqiang Liu
  2021-03-22  9:42 ` Niklas Schnelle
  0 siblings, 1 reply; 2+ messages in thread
From: Zhiqiang Liu @ 2021-03-21 15:51 UTC (permalink / raw)
  To: schnelle, gerald.schaefer, bhelgaas
  Cc: linux-s390, linux-pci, linux-kernel, linfeilong, liuzhiqiang26


In disable_slot(), if we obtain desired PCI device
successfully by calling pci_get_slot(), we should
call pci_dev_put() to release its reference.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Feilong Lin <linfeilong@huawei.com>
---
 drivers/pci/hotplug/s390_pci_hpc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/hotplug/s390_pci_hpc.c b/drivers/pci/hotplug/s390_pci_hpc.c
index c9e790c74051..999a34b6fd50 100644
--- a/drivers/pci/hotplug/s390_pci_hpc.c
+++ b/drivers/pci/hotplug/s390_pci_hpc.c
@@ -89,9 +89,11 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
 		return -EIO;

 	pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn);
-	if (pdev && pci_num_vf(pdev)) {
+	if (pdev) {
+		rc = pci_num_vf(pdev);
 		pci_dev_put(pdev);
-		return -EBUSY;
+		if (rc)
+			return -EBUSY;
 	}

 	zpci_remove_device(zdev);
-- 
2.19.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] pci/hotplug: fix potential memory leak in disable_slot()
  2021-03-21 15:51 [PATCH] pci/hotplug: fix potential memory leak in disable_slot() Zhiqiang Liu
@ 2021-03-22  9:42 ` Niklas Schnelle
  0 siblings, 0 replies; 2+ messages in thread
From: Niklas Schnelle @ 2021-03-22  9:42 UTC (permalink / raw)
  To: Zhiqiang Liu
  Cc: linux-s390, linux-pci, linux-kernel, linfeilong, gerald.schaefer,
	bhelgaas



On 21/03/2021 16:51, Zhiqiang Liu wrote:
> 
> In disable_slot(), if we obtain desired PCI device
> successfully by calling pci_get_slot(), we should
> call pci_dev_put() to release its reference.

Thanks for the patch! This should however be fixed independently by 
commit 0b13525c20fe ("s390/pci: fix leak of PCI device structure")
which was just added to v5.12-rc4 and will be backported to stable.
There were a few similar cases that also got fixed by that commit.

> 
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> Signed-off-by: Feilong Lin <linfeilong@huawei.com>
> ---
>   drivers/pci/hotplug/s390_pci_hpc.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/hotplug/s390_pci_hpc.c b/drivers/pci/hotplug/s390_pci_hpc.c
> index c9e790c74051..999a34b6fd50 100644
> --- a/drivers/pci/hotplug/s390_pci_hpc.c
> +++ b/drivers/pci/hotplug/s390_pci_hpc.c
> @@ -89,9 +89,11 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
>   		return -EIO;
> 
>   	pdev = pci_get_slot(zdev->zbus->bus, zdev->devfn);
> -	if (pdev && pci_num_vf(pdev)) {
> +	if (pdev) {
> +		rc = pci_num_vf(pdev);
>   		pci_dev_put(pdev);
> -		return -EBUSY;
> +		if (rc)
> +			return -EBUSY;
>   	}
> 
>   	zpci_remove_device(zdev);
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-22  9:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-21 15:51 [PATCH] pci/hotplug: fix potential memory leak in disable_slot() Zhiqiang Liu
2021-03-22  9:42 ` Niklas Schnelle

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