DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] bus/pci: fix bus info memleak during PCI scan
@ 2022-11-18 13:35 Tomasz Zawadzki
  2022-11-21  8:44 ` David Marchand
  0 siblings, 1 reply; 3+ messages in thread
From: Tomasz Zawadzki @ 2022-11-18 13:35 UTC (permalink / raw)
  To: Bruce Richardson, David Marchand; +Cc: dev, Tomasz Zawadzki

During pci_scan_one() for devices that were already registered
the pci_common_set() is called to set some of the fields again.

This resulted in bus_info allocation leaking, so this patch
ensures they are always freed beforehand.

Fixes: 8f4de2dba9b9 ("bus/pci: fill bus specific information")

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
---
 drivers/bus/pci/pci_common.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 9901c34f4e..9a866055e8 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -114,6 +114,7 @@ pci_common_set(struct rte_pci_device *dev)
 		/* Otherwise, it uses the internal, canonical form. */
 		dev->device.name = dev->name;
 
+	free(dev->bus_info);
 	if (asprintf(&dev->bus_info, "vendor_id=%"PRIx16", device_id=%"PRIx16,
 			dev->id.vendor_id, dev->id.device_id) != -1)
 		dev->device.bus_info = dev->bus_info;
-- 
2.38.1


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

* Re: [PATCH] bus/pci: fix bus info memleak during PCI scan
  2022-11-18 13:35 [PATCH] bus/pci: fix bus info memleak during PCI scan Tomasz Zawadzki
@ 2022-11-21  8:44 ` David Marchand
  2022-11-22  9:30   ` David Marchand
  0 siblings, 1 reply; 3+ messages in thread
From: David Marchand @ 2022-11-21  8:44 UTC (permalink / raw)
  To: Tomasz Zawadzki; +Cc: Bruce Richardson, dev

On Fri, Nov 18, 2022 at 2:36 PM Tomasz Zawadzki
<tomasz.zawadzki@intel.com> wrote:
>
> During pci_scan_one() for devices that were already registered
> the pci_common_set() is called to set some of the fields again.
>
> This resulted in bus_info allocation leaking, so this patch
> ensures they are always freed beforehand.
>
> Fixes: 8f4de2dba9b9 ("bus/pci: fill bus specific information")
>
> Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
> ---
>  drivers/bus/pci/pci_common.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
> index 9901c34f4e..9a866055e8 100644
> --- a/drivers/bus/pci/pci_common.c
> +++ b/drivers/bus/pci/pci_common.c
> @@ -114,6 +114,7 @@ pci_common_set(struct rte_pci_device *dev)
>                 /* Otherwise, it uses the internal, canonical form. */
>                 dev->device.name = dev->name;
>
> +       free(dev->bus_info);
>         if (asprintf(&dev->bus_info, "vendor_id=%"PRIx16", device_id=%"PRIx16,
>                         dev->id.vendor_id, dev->id.device_id) != -1)
>                 dev->device.bus_info = dev->bus_info;

Indeed, good catch.

The bus_info content is constant for a given device, there is no need
to free and reallocate.
WDYT of:

@@ -114,8 +114,9 @@ pci_common_set(struct rte_pci_device *dev)
                /* Otherwise, it uses the internal, canonical form. */
                dev->device.name = dev->name;

-       if (asprintf(&dev->bus_info, "vendor_id=%"PRIx16", device_id=%"PRIx16,
-                       dev->id.vendor_id, dev->id.device_id) != -1)
+       if (dev->bus_info != NULL ||
+                       asprintf(&dev->bus_info, "vendor_id=%"PRIx16",
device_id=%"PRIx16,
+                               dev->id.vendor_id, dev->id.device_id) != -1)
                dev->device.bus_info = dev->bus_info;
 }


-- 
David Marchand


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

* Re: [PATCH] bus/pci: fix bus info memleak during PCI scan
  2022-11-21  8:44 ` David Marchand
@ 2022-11-22  9:30   ` David Marchand
  0 siblings, 0 replies; 3+ messages in thread
From: David Marchand @ 2022-11-22  9:30 UTC (permalink / raw)
  To: Tomasz Zawadzki; +Cc: Bruce Richardson, dev

On Mon, Nov 21, 2022 at 9:44 AM David Marchand
<david.marchand@redhat.com> wrote:
>
> On Fri, Nov 18, 2022 at 2:36 PM Tomasz Zawadzki
> <tomasz.zawadzki@intel.com> wrote:
> >
> > During pci_scan_one() for devices that were already registered
> > the pci_common_set() is called to set some of the fields again.
> >
> > This resulted in bus_info allocation leaking, so this patch
> > ensures they are always freed beforehand.
> >
> > Fixes: 8f4de2dba9b9 ("bus/pci: fill bus specific information")
> >
> > Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>

I sent https://patchwork.dpdk.org/project/dpdk/patch/20221121111209.2396341-1-david.marchand@redhat.com/
as an alternative.
Can you have a look?


Thanks.

-- 
David Marchand


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

end of thread, other threads:[~2022-11-22  9:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18 13:35 [PATCH] bus/pci: fix bus info memleak during PCI scan Tomasz Zawadzki
2022-11-21  8:44 ` David Marchand
2022-11-22  9:30   ` David Marchand

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