Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pseries/iommu: Add missing kfree

At this point, window has not been stored anywhere, so it has to be freed
before leaving the function.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@exists@
local idexpression x;
statement S,S1;
expression E;
identifier fl;
expression *ptr != NULL;
@@

x = \(kmalloc\|kzalloc\|kcalloc\)(...);
...
if (x == NULL) S
<... when != x
when != if (...) { <+...kfree(x)...+> }
when any
when != true x == NULL
x->fl
...>
(
if (x == NULL) S1
|
if (...) { ... when != x
when forall
(
return \(0\|<+...x...+>\|ptr\);
|
* return ...;
)
}
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Acked-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Julia Lawall and committed by
Benjamin Herrenschmidt
7a19081f 6dece0eb

+5 -2
+5 -2
arch/powerpc/platforms/pseries/iommu.c
··· 939 939 if (ret) { 940 940 dev_info(&dev->dev, "failed to map direct window for %s: %d\n", 941 941 dn->full_name, ret); 942 - goto out_clear_window; 942 + goto out_free_window; 943 943 } 944 944 945 945 ret = prom_add_property(pdn, win64); 946 946 if (ret) { 947 947 dev_err(&dev->dev, "unable to add dma window property for %s: %d", 948 948 pdn->full_name, ret); 949 - goto out_clear_window; 949 + goto out_free_window; 950 950 } 951 951 952 952 window->device = pdn; ··· 957 957 958 958 dma_addr = of_read_number(&create.addr_hi, 2); 959 959 goto out_unlock; 960 + 961 + out_free_window: 962 + kfree(window); 960 963 961 964 out_clear_window: 962 965 remove_ddw(pdn);