diff options
author | Julia Lawall <julia@diku.dk> | 2011-08-08 07:17:57 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2011-08-18 23:58:11 -0400 |
commit | a081da630d64acf132b2db1043c586b993d49da7 (patch) | |
tree | ed79ad186b940c18a298054a1a1e1ef431e8bc3f /drivers/ata | |
parent | e39c75cf3e045c2fb3988770b207dfd09c30d4ac (diff) |
drivers/ata/sata_dwc_460ex.c: add missing kfree
Currently, error handling code in this function calls the function
sata_dwc_port_stop, but this function has essentially no effect if hsdevp
has not been stored in ap, which is the case throughout this function. The
only effect is to print a debugging message including ap->print_id.
The code is rewritten to not call sata_dwc_port_stop, but instead to jump
to a local label that prints the original error message and the print_id
information. In the case where hsdevp has been already allocated (but not
yet stored in ap), this value is freed as well.
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>
Signed-off-by: Jeff Garzik <jgarzik@pobox.com>
Diffstat (limited to 'drivers/ata')
-rw-r--r-- | drivers/ata/sata_dwc_460ex.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c index 0a9a774a7e1e..5c4237452f50 100644 --- a/drivers/ata/sata_dwc_460ex.c +++ b/drivers/ata/sata_dwc_460ex.c | |||
@@ -1329,7 +1329,7 @@ static int sata_dwc_port_start(struct ata_port *ap) | |||
1329 | dev_err(ap->dev, "%s: dma_alloc_coherent failed\n", | 1329 | dev_err(ap->dev, "%s: dma_alloc_coherent failed\n", |
1330 | __func__); | 1330 | __func__); |
1331 | err = -ENOMEM; | 1331 | err = -ENOMEM; |
1332 | goto CLEANUP; | 1332 | goto CLEANUP_ALLOC; |
1333 | } | 1333 | } |
1334 | } | 1334 | } |
1335 | 1335 | ||
@@ -1349,15 +1349,13 @@ static int sata_dwc_port_start(struct ata_port *ap) | |||
1349 | /* Clear any error bits before libata starts issuing commands */ | 1349 | /* Clear any error bits before libata starts issuing commands */ |
1350 | clear_serror(); | 1350 | clear_serror(); |
1351 | ap->private_data = hsdevp; | 1351 | ap->private_data = hsdevp; |
1352 | dev_dbg(ap->dev, "%s: done\n", __func__); | ||
1353 | return 0; | ||
1352 | 1354 | ||
1355 | CLEANUP_ALLOC: | ||
1356 | kfree(hsdevp); | ||
1353 | CLEANUP: | 1357 | CLEANUP: |
1354 | if (err) { | 1358 | dev_dbg(ap->dev, "%s: fail. ap->id = %d\n", __func__, ap->print_id); |
1355 | sata_dwc_port_stop(ap); | ||
1356 | dev_dbg(ap->dev, "%s: fail\n", __func__); | ||
1357 | } else { | ||
1358 | dev_dbg(ap->dev, "%s: done\n", __func__); | ||
1359 | } | ||
1360 | |||
1361 | return err; | 1359 | return err; |
1362 | } | 1360 | } |
1363 | 1361 | ||