Skip to content

Commit 30a0dee

Browse files
Julia Lawallgregkh
Julia Lawall
authored andcommitted
drivers/usb/host/isp1760-if.c: introduce missing kfree
drvdata needds to be freed before leaving the function in an error case. A simplified version of the semantic match that finds the problem is as follows: (http://coccinelle.lip6.fr) // <smpl> @r exists@ local idexpression x; statement S; identifier f1; position p1,p2; expression *ptr != NULL; @@ x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...); ... if (x == NULL) S <... when != x when != if (...) { <+...x...+> } x->f1 ...> ( 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> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 3c8c931 commit 30a0dee

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/usb/host/isp1760-if.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ static int of_isp1760_probe(struct platform_device *dev)
5656
return -ENOMEM;
5757

5858
ret = of_address_to_resource(dp, 0, &memory);
59-
if (ret)
60-
return -ENXIO;
59+
if (ret) {
60+
ret = -ENXIO;
61+
goto free_data;
62+
}
6163

6264
res_len = resource_size(&memory);
6365

6466
res = request_mem_region(memory.start, res_len, dev_name(&dev->dev));
65-
if (!res)
66-
return -EBUSY;
67+
if (!res) {
68+
ret = -EBUSY;
69+
goto free_data;
70+
}
6771

6872
if (of_irq_map_one(dp, 0, &oirq)) {
6973
ret = -ENODEV;
@@ -125,6 +129,7 @@ static int of_isp1760_probe(struct platform_device *dev)
125129
gpio_free(drvdata->rst_gpio);
126130
release_reg:
127131
release_mem_region(memory.start, res_len);
132+
free_data:
128133
kfree(drvdata);
129134
return ret;
130135
}

0 commit comments

Comments
 (0)