2014-04-01 10:16:08

by Daeseok Youn

[permalink] [raw]
Subject: [PATCH v2] xen: fix memory leak in __xen_pcibk_add_pci_dev()


It need to free dev_entry when it failed to assign to a new
slot on the virtual PCI bus.

smatch says:
drivers/xen/xen-pciback/vpci.c:142 __xen_pcibk_add_pci_dev() warn:
possible memory leak of 'dev_entry'

Signed-off-by: Daeseok Youn <[email protected]>
---
v2: The kfree() invocation is moved outside the locked region.

drivers/xen/xen-pciback/vpci.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/xen/xen-pciback/vpci.c b/drivers/xen/xen-pciback/vpci.c
index 3165ce3..51afff9 100644
--- a/drivers/xen/xen-pciback/vpci.c
+++ b/drivers/xen/xen-pciback/vpci.c
@@ -137,6 +137,8 @@ unlock:
/* Publish this device. */
if (!err)
err = publish_cb(pdev, 0, 0, PCI_DEVFN(slot, func), devid);
+ else
+ kfree(dev_entry);

out:
return err;
--
1.7.4.4


2014-04-01 10:48:32

by Jan Beulich

[permalink] [raw]
Subject: Re: [PATCH v2] xen: fix memory leak in __xen_pcibk_add_pci_dev()

>>> On 01.04.14 at 12:15, <[email protected]> wrote:

> It need to free dev_entry when it failed to assign to a new
> slot on the virtual PCI bus.
>
> smatch says:
> drivers/xen/xen-pciback/vpci.c:142 __xen_pcibk_add_pci_dev() warn:
> possible memory leak of 'dev_entry'
>
> Signed-off-by: Daeseok Youn <[email protected]>

As before
Reviewed-by: Jan Beulich <[email protected]>

> ---
> v2: The kfree() invocation is moved outside the locked region.
>
> drivers/xen/xen-pciback/vpci.c | 2 ++
> 1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/xen/xen-pciback/vpci.c b/drivers/xen/xen-pciback/vpci.c
> index 3165ce3..51afff9 100644
> --- a/drivers/xen/xen-pciback/vpci.c
> +++ b/drivers/xen/xen-pciback/vpci.c
> @@ -137,6 +137,8 @@ unlock:
> /* Publish this device. */
> if (!err)
> err = publish_cb(pdev, 0, 0, PCI_DEVFN(slot, func), devid);
> + else
> + kfree(dev_entry);
>
> out:
> return err;
> --
> 1.7.4.4


2014-04-03 11:55:33

by David Vrabel

[permalink] [raw]
Subject: Re: [PATCH v2] xen: fix memory leak in __xen_pcibk_add_pci_dev()

On 01/04/14 11:15, Daeseok Youn wrote:
>
> It need to free dev_entry when it failed to assign to a new
> slot on the virtual PCI bus.
>
> smatch says:
> drivers/xen/xen-pciback/vpci.c:142 __xen_pcibk_add_pci_dev() warn:
> possible memory leak of 'dev_entry'

Applied to devel/for-linus-3.15.

Thanks.

David