Linux-ACPI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] ACPI / hotplug / PCI: fix memory leak in enable_slot()
@ 2021-03-25  7:26 Zhiqiang Liu
  2021-04-08 15:18 ` Rafael J. Wysocki
  2021-04-08 16:19 ` Bjorn Helgaas
  0 siblings, 2 replies; 4+ messages in thread
From: Zhiqiang Liu @ 2021-03-25  7:26 UTC (permalink / raw)
  To: rjw, lenb, bhelgaas
  Cc: linux-acpi, linux-pci, linux-kernel, linfeilong, liuzhiqiang26

From: Feilong Lin <linfeilong@huawei.com>

In enable_slot() in drivers/pci/hotplug/acpiphp_glue.c, if pci_get_slot()
will return NULL, we will do not set SLOT_ENABLED flag of slot. if one
device is found by calling pci_get_slot(), its reference count will be
increased. In this case, we did not call pci_dev_put() to decrement the
its reference count, the memory of the device (struct pci_dev type) will
leak.

Fix it by calling pci_dev_put() to decrement its reference count after that
pci_get_slot() returns a PCI device.

Signed-off-by: Feilong Lin <linfeilong@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
--
v2: rewrite subject and commit log as suggested by Bjorn Helgaas.
---
 drivers/pci/hotplug/acpiphp_glue.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 3365c93abf0e..f031302ad401 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
 			slot->flags &= ~SLOT_ENABLED;
 			continue;
 		}
+		pci_dev_put(dev);
 	}
 }

-- 
2.19.1


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

* Re: [PATCH v2] ACPI / hotplug / PCI: fix memory leak in enable_slot()
  2021-03-25  7:26 [PATCH v2] ACPI / hotplug / PCI: fix memory leak in enable_slot() Zhiqiang Liu
@ 2021-04-08 15:18 ` Rafael J. Wysocki
  2021-04-08 15:25   ` Bjorn Helgaas
  2021-04-08 16:19 ` Bjorn Helgaas
  1 sibling, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2021-04-08 15:18 UTC (permalink / raw)
  To: Zhiqiang Liu, Bjorn Helgaas
  Cc: Rafael J. Wysocki, Len Brown, ACPI Devel Maling List, Linux PCI,
	linux-kernel, linfeilong

On Thu, Mar 25, 2021 at 8:27 AM Zhiqiang Liu <liuzhiqiang26@huawei.com> wrote:
>
> From: Feilong Lin <linfeilong@huawei.com>
>
> In enable_slot() in drivers/pci/hotplug/acpiphp_glue.c, if pci_get_slot()
> will return NULL, we will do not set SLOT_ENABLED flag of slot. if one
> device is found by calling pci_get_slot(), its reference count will be
> increased. In this case, we did not call pci_dev_put() to decrement the
> its reference count, the memory of the device (struct pci_dev type) will
> leak.
>
> Fix it by calling pci_dev_put() to decrement its reference count after that
> pci_get_slot() returns a PCI device.
>
> Signed-off-by: Feilong Lin <linfeilong@huawei.com>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> --
> v2: rewrite subject and commit log as suggested by Bjorn Helgaas.

The fix is correct AFAICS, so

Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Bjorn, has this been applied already?  If not, do you want me to take
it or are you going to queue it up yourself?

> ---
>  drivers/pci/hotplug/acpiphp_glue.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
> index 3365c93abf0e..f031302ad401 100644
> --- a/drivers/pci/hotplug/acpiphp_glue.c
> +++ b/drivers/pci/hotplug/acpiphp_glue.c
> @@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
>                         slot->flags &= ~SLOT_ENABLED;
>                         continue;
>                 }
> +               pci_dev_put(dev);
>         }
>  }
>
> --
> 2.19.1
>

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

* Re: [PATCH v2] ACPI / hotplug / PCI: fix memory leak in enable_slot()
  2021-04-08 15:18 ` Rafael J. Wysocki
@ 2021-04-08 15:25   ` Bjorn Helgaas
  0 siblings, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2021-04-08 15:25 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Zhiqiang Liu, Bjorn Helgaas, Rafael J. Wysocki, Len Brown,
	ACPI Devel Maling List, Linux PCI, linux-kernel, linfeilong

On Thu, Apr 08, 2021 at 05:18:46PM +0200, Rafael J. Wysocki wrote:
> On Thu, Mar 25, 2021 at 8:27 AM Zhiqiang Liu <liuzhiqiang26@huawei.com> wrote:
> >
> > From: Feilong Lin <linfeilong@huawei.com>
> >
> > In enable_slot() in drivers/pci/hotplug/acpiphp_glue.c, if pci_get_slot()
> > will return NULL, we will do not set SLOT_ENABLED flag of slot. if one
> > device is found by calling pci_get_slot(), its reference count will be
> > increased. In this case, we did not call pci_dev_put() to decrement the
> > its reference count, the memory of the device (struct pci_dev type) will
> > leak.
> >
> > Fix it by calling pci_dev_put() to decrement its reference count after that
> > pci_get_slot() returns a PCI device.
> >
> > Signed-off-by: Feilong Lin <linfeilong@huawei.com>
> > Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> > --
> > v2: rewrite subject and commit log as suggested by Bjorn Helgaas.
> 
> The fix is correct AFAICS, so
> 
> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Bjorn, has this been applied already?  If not, do you want me to take
> it or are you going to queue it up yourself?

I'll pick it up; thanks for the review and the reminder!

> > ---
> >  drivers/pci/hotplug/acpiphp_glue.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
> > index 3365c93abf0e..f031302ad401 100644
> > --- a/drivers/pci/hotplug/acpiphp_glue.c
> > +++ b/drivers/pci/hotplug/acpiphp_glue.c
> > @@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
> >                         slot->flags &= ~SLOT_ENABLED;
> >                         continue;
> >                 }
> > +               pci_dev_put(dev);
> >         }
> >  }
> >
> > --
> > 2.19.1
> >

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

* Re: [PATCH v2] ACPI / hotplug / PCI: fix memory leak in enable_slot()
  2021-03-25  7:26 [PATCH v2] ACPI / hotplug / PCI: fix memory leak in enable_slot() Zhiqiang Liu
  2021-04-08 15:18 ` Rafael J. Wysocki
@ 2021-04-08 16:19 ` Bjorn Helgaas
  1 sibling, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2021-04-08 16:19 UTC (permalink / raw)
  To: Zhiqiang Liu
  Cc: rjw, lenb, bhelgaas, linux-acpi, linux-pci, linux-kernel, linfeilong

On Thu, Mar 25, 2021 at 03:26:00PM +0800, Zhiqiang Liu wrote:
> From: Feilong Lin <linfeilong@huawei.com>
> 
> In enable_slot() in drivers/pci/hotplug/acpiphp_glue.c, if pci_get_slot()
> will return NULL, we will do not set SLOT_ENABLED flag of slot. if one
> device is found by calling pci_get_slot(), its reference count will be
> increased. In this case, we did not call pci_dev_put() to decrement the
> its reference count, the memory of the device (struct pci_dev type) will
> leak.
> 
> Fix it by calling pci_dev_put() to decrement its reference count after that
> pci_get_slot() returns a PCI device.
> 
> Signed-off-by: Feilong Lin <linfeilong@huawei.com>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>

Applied with Rafael's reviewed-by to pci/hotplug for v5.13, thanks!

> --
> v2: rewrite subject and commit log as suggested by Bjorn Helgaas.
> ---
>  drivers/pci/hotplug/acpiphp_glue.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
> index 3365c93abf0e..f031302ad401 100644
> --- a/drivers/pci/hotplug/acpiphp_glue.c
> +++ b/drivers/pci/hotplug/acpiphp_glue.c
> @@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
>  			slot->flags &= ~SLOT_ENABLED;
>  			continue;
>  		}
> +		pci_dev_put(dev);
>  	}
>  }
> 
> -- 
> 2.19.1
> 

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25  7:26 [PATCH v2] ACPI / hotplug / PCI: fix memory leak in enable_slot() Zhiqiang Liu
2021-04-08 15:18 ` Rafael J. Wysocki
2021-04-08 15:25   ` Bjorn Helgaas
2021-04-08 16:19 ` Bjorn Helgaas

Linux-ACPI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-acpi/0 linux-acpi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-acpi linux-acpi/ https://lore.kernel.org/linux-acpi \
		linux-acpi@vger.kernel.org
	public-inbox-index linux-acpi

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-acpi


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git