Skip to contentSkip to conversation

xen: fix memory leak in __xen_pcibk_add_pci_dev()

PATCH In review Daeseok Youn 2 participants 5 messages Mar 31, 2014 – Apr 1, 2014 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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'

---
 drivers/xen/xen-pciback/vpci.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/xen/xen-pciback/vpci.c +1 -0
index 3165ce3..657e50f 100644
@@ -130,6 +130,7 @@ static int __xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev,
 	err = -ENOMEM;
 	xenbus_dev_fatal(pdev->xdev, err,
 			 "No more space on root virtual PCI bus");
+	kfree(dev_entry);
 
 unlock:
 	mutex_unlock(&vpci_dev->lock);
Signature · 1 line
1.7.4.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 31.03.14 at 12:08, <[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'

albeit the solution is not ideal:

Quoted 11 lines
drivers/xen/xen-pciback/vpci.c +1 -0
@@ -130,6 +130,7 @@ static int __xen_pcibk_add_pci_dev(struct 
 xen_pcibk_device *pdev,
 	err = -ENOMEM;
 	xenbus_dev_fatal(pdev->xdev, err,
 			 "No more space on root virtual PCI bus");
+	kfree(dev_entry);
 
 unlock:

mutex_unlock(&vpci_dev->lock);

The kfree() invocation would better be placed outside the locked region (e.g. in an else to the "if (!err)" a little further down).

Jan

Reviewed-by on v1 1/1
#2 lore raw
In reply to Daeseok Youn
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 31.03.14 at 12:08, <[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'

albeit the solution is not ideal:

Quoted 11 lines
drivers/xen/xen-pciback/vpci.c +1 -0
@@ -130,6 +130,7 @@ static int __xen_pcibk_add_pci_dev(struct 
 xen_pcibk_device *pdev,
 	err = -ENOMEM;
 	xenbus_dev_fatal(pdev->xdev, err,
 			 "No more space on root virtual PCI bus");
+	kfree(dev_entry);
 
 unlock:

mutex_unlock(&vpci_dev->lock);

The kfree() invocation would better be placed outside the locked region (e.g. in an else to the "if (!err)" a little further down).

Jan

#3 lore raw

2014-04-01 16:23 GMT+09:00 Jan Beulich <[email protected]>:

Quoted 24 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 31.03.14 at 12:08, <[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'

albeit the solution is not ideal:

Quoted 9 lines
drivers/xen/xen-pciback/vpci.c +1 -0
@@ -130,6 +130,7 @@ static int __xen_pcibk_add_pci_dev(struct
 xen_pcibk_device *pdev,
      err = -ENOMEM;
      xenbus_dev_fatal(pdev->xdev, err,
                       "No more space on root virtual PCI bus");
+     kfree(dev_entry);
 
Quoted 5 lines
Quoted 2 lines
drivers/xen/xen-pciback/vpci.c +0 -0
 unlock:
      mutex_unlock(&vpci_dev->lock);

The kfree() invocation would better be placed outside the locked region (e.g. in an else to the "if (!err)" a little further down).

You're right.
I will change my patch as your comment and send it again.

Thanks for review.
Daeseok Youn

Quoted 3 lines

Jan

#4 lore raw
In reply to Jan Beulich

2014-04-01 16:23 GMT+09:00 Jan Beulich <[email protected]>:

Quoted 24 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 31.03.14 at 12:08, <[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'

albeit the solution is not ideal:

Quoted 9 lines
drivers/xen/xen-pciback/vpci.c +1 -0
@@ -130,6 +130,7 @@ static int __xen_pcibk_add_pci_dev(struct
 xen_pcibk_device *pdev,
      err = -ENOMEM;
      xenbus_dev_fatal(pdev->xdev, err,
                       "No more space on root virtual PCI bus");
+     kfree(dev_entry);
 
Quoted 5 lines
Quoted 2 lines
drivers/xen/xen-pciback/vpci.c +0 -0
 unlock:
      mutex_unlock(&vpci_dev->lock);

The kfree() invocation would better be placed outside the locked region (e.g. in an else to the "if (!err)" a little further down).

You're right.
I will change my patch as your comment and send it again.

Thanks for review.
Daeseok Youn

Quoted 3 lines

Jan