public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/6] drivers/pci: introduce missing kfree
@ 2009-02-08 21:45 Julia Lawall
  2009-02-09  1:21 ` Matthew Wilcox
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Julia Lawall @ 2009-02-08 21:45 UTC (permalink / raw)
  To: jbarnes, linux-pci, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

Error handling code following a kmalloc should free the allocated data.
Since the subsequent code that could provoke an error does not use the
allocated data, the allocation is just moved below it.

The semantic match that finds the problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@r exists@
local idexpression x;
statement S;
expression E;
identifier f,l;
position p1,p2;
expression *ptr != NULL;
@@

(
if ((x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...)) == NULL) S
|
x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
...
if (x == NULL) S
)
<... when != x
     when != if (...) { <+...x...+> }
x->f = E
...>
(
 return \(0\|<+...x...+>\|ptr\);
|
 return@p2 ...;
)

@script:python@
p1 << r.p1;
p2 << r.p2;
@@

print "* file: %s kmalloc %s return %s" % (p1[0].file,p1[0].line,p2[0].line)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
---
 drivers/pci/hotplug/pciehp_acpi.c   |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/hotplug/pciehp_acpi.c b/drivers/pci/hotplug/pciehp_acpi.c
index 21734c3..9604801 100644
--- a/drivers/pci/hotplug/pciehp_acpi.c
+++ b/drivers/pci/hotplug/pciehp_acpi.c
@@ -79,14 +79,15 @@ static int __init dummy_probe(struct pcie_device *dev)
 	struct slot *slot, *tmp;
 	struct pci_dev *pdev = dev->port;
 	struct pci_bus *pbus = pdev->subordinate;
-	if (!(slot = kzalloc(sizeof(*slot), GFP_KERNEL)))
-		return -ENOMEM;
 	/* Note: pciehp_detect_mode != PCIEHP_DETECT_ACPI here */
 	if (pciehp_get_hp_hw_control_from_firmware(pdev))
 		return -ENODEV;
 	if (!(pos = pci_find_capability(pdev, PCI_CAP_ID_EXP)))
 		return -ENODEV;
 	pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &slot_cap);
+	slot = kzalloc(sizeof(*slot), GFP_KERNEL);
+	if (!slot)
+		return -ENOMEM;
 	slot->number = slot_cap >> 19;
 	list_for_each_entry(tmp, &dummy_slots, slot_list) {
 		if (tmp->number == slot->number)

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

* Re: [PATCH 4/6] drivers/pci: introduce missing kfree
  2009-02-08 21:45 [PATCH 4/6] drivers/pci: introduce missing kfree Julia Lawall
@ 2009-02-09  1:21 ` Matthew Wilcox
  2009-02-09  4:26 ` Kenji Kaneshige
  2009-02-13 21:16 ` Jesse Barnes
  2 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2009-02-09  1:21 UTC (permalink / raw)
  To: Julia Lawall; +Cc: jbarnes, linux-pci, linux-kernel, kernel-janitors

On Sun, Feb 08, 2009 at 10:45:24PM +0100, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> Error handling code following a kmalloc should free the allocated data.
> Since the subsequent code that could provoke an error does not use the
> allocated data, the allocation is just moved below it.
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>

Reviewed-by: Matthew Wilcox <willy@linux.intel.com>

-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

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

* Re: [PATCH 4/6] drivers/pci: introduce missing kfree
  2009-02-08 21:45 [PATCH 4/6] drivers/pci: introduce missing kfree Julia Lawall
  2009-02-09  1:21 ` Matthew Wilcox
@ 2009-02-09  4:26 ` Kenji Kaneshige
  2009-02-13 21:16 ` Jesse Barnes
  2 siblings, 0 replies; 4+ messages in thread
From: Kenji Kaneshige @ 2009-02-09  4:26 UTC (permalink / raw)
  To: Julia Lawall; +Cc: jbarnes, linux-pci, linux-kernel, kernel-janitors

Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> Error handling code following a kmalloc should free the allocated data.
> Since the subsequent code that could provoke an error does not use the
> allocated data, the allocation is just moved below it.
> 
> The semantic match that finds the problem is as follows:
> (http://www.emn.fr/x-info/coccinelle/)
> 
> // <smpl>
> @r exists@
> local idexpression x;
> statement S;
> expression E;
> identifier f,l;
> position p1,p2;
> expression *ptr != NULL;
> @@
> 
> (
> if ((x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...)) == NULL) S
> |
> x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
> ...
> if (x == NULL) S
> )
> <... when != x
>      when != if (...) { <+...x...+> }
> x->f = E
> ...>
> (
>  return \(0\|<+...x...+>\|ptr\);
> |
>  return@p2 ...;
> )
> 
> @script:python@
> p1 << r.p1;
> p2 << r.p2;
> @@
> 
> print "* file: %s kmalloc %s return %s" % (p1[0].file,p1[0].line,p2[0].line)
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>
> ---
>  drivers/pci/hotplug/pciehp_acpi.c   |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/hotplug/pciehp_acpi.c b/drivers/pci/hotplug/pciehp_acpi.c
> index 21734c3..9604801 100644
> --- a/drivers/pci/hotplug/pciehp_acpi.c
> +++ b/drivers/pci/hotplug/pciehp_acpi.c
> @@ -79,14 +79,15 @@ static int __init dummy_probe(struct pcie_device *dev)
>  	struct slot *slot, *tmp;
>  	struct pci_dev *pdev = dev->port;
>  	struct pci_bus *pbus = pdev->subordinate;
> -	if (!(slot = kzalloc(sizeof(*slot), GFP_KERNEL)))
> -		return -ENOMEM;
>  	/* Note: pciehp_detect_mode != PCIEHP_DETECT_ACPI here */
>  	if (pciehp_get_hp_hw_control_from_firmware(pdev))
>  		return -ENODEV;
>  	if (!(pos = pci_find_capability(pdev, PCI_CAP_ID_EXP)))
>  		return -ENODEV;
>  	pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &slot_cap);
> +	slot = kzalloc(sizeof(*slot), GFP_KERNEL);
> +	if (!slot)
> +		return -ENOMEM;
>  	slot->number = slot_cap >> 19;
>  	list_for_each_entry(tmp, &dummy_slots, slot_list) {
>  		if (tmp->number == slot->number)

Thank you for fixing this!

Reviewed-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>

Thanks,
Kenji Kaneshige



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

* Re: [PATCH 4/6] drivers/pci: introduce missing kfree
  2009-02-08 21:45 [PATCH 4/6] drivers/pci: introduce missing kfree Julia Lawall
  2009-02-09  1:21 ` Matthew Wilcox
  2009-02-09  4:26 ` Kenji Kaneshige
@ 2009-02-13 21:16 ` Jesse Barnes
  2 siblings, 0 replies; 4+ messages in thread
From: Jesse Barnes @ 2009-02-13 21:16 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-pci, linux-kernel, kernel-janitors

On Sunday, February 8, 2009 1:45 pm Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
>
> Error handling code following a kmalloc should free the allocated data.
> Since the subsequent code that could provoke an error does not use the
> allocated data, the allocation is just moved below it.
>
> The semantic match that finds the problem is as follows:
> (http://www.emn.fr/x-info/coccinelle/)

Applied to my linux-next branch, thanks.
-- 
Jesse Barnes, Intel Open Source Technology Center

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

end of thread, other threads:[~2009-02-13 21:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-08 21:45 [PATCH 4/6] drivers/pci: introduce missing kfree Julia Lawall
2009-02-09  1:21 ` Matthew Wilcox
2009-02-09  4:26 ` Kenji Kaneshige
2009-02-13 21:16 ` Jesse Barnes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox