diff options
author | Jesper Juhl <jesper.juhl@gmail.com> | 2006-06-25 05:47:17 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-25 10:01:01 -0700 |
commit | a9adb8dbcd7a337620862106f8c17aeb5e7278c7 (patch) | |
tree | c70b44cb6576c8034f52244af76a52c887146d4b | |
parent | 552c03483e49a69312c9e7384fda9282c991880a (diff) | |
download | blackbird-op-linux-a9adb8dbcd7a337620862106f8c17aeb5e7278c7.tar.gz blackbird-op-linux-a9adb8dbcd7a337620862106f8c17aeb5e7278c7.zip |
[PATCH] pnp: card_probe(): fix memory leak
We can leak `clink' if drv->probe == 0.
Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Cc: Adam Belay <ambx1@neo.rr.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | drivers/pnp/card.c | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c index bb19c64073c6..0b4adcb60df4 100644 --- a/drivers/pnp/card.c +++ b/drivers/pnp/card.c @@ -60,30 +60,34 @@ static void card_remove_first(struct pnp_dev * dev) card_remove(dev); } -static int card_probe(struct pnp_card * card, struct pnp_card_driver * drv) +static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv) { - const struct pnp_card_device_id *id = match_card(drv,card); - if (id) { - struct pnp_card_link * clink = pnp_alloc(sizeof(struct pnp_card_link)); - if (!clink) - return 0; - clink->card = card; - clink->driver = drv; - clink->pm_state = PMSG_ON; - if (drv->probe) { - if (drv->probe(clink, id)>=0) - return 1; - else { - struct pnp_dev * dev; - card_for_each_dev(card, dev) { - if (dev->card_link == clink) - pnp_release_card_device(dev); - } - kfree(clink); - } - } else - return 1; + const struct pnp_card_device_id *id; + struct pnp_card_link *clink; + struct pnp_dev *dev; + + if (!drv->probe) + return 0; + id = match_card(drv,card); + if (!id) + return 0; + + clink = pnp_alloc(sizeof(*clink)); + if (!clink) + return 0; + clink->card = card; + clink->driver = drv; + clink->pm_state = PMSG_ON; + + if (drv->probe(clink, id) >= 0) + return 1; + + /* Recovery */ + card_for_each_dev(card, dev) { + if (dev->card_link == clink) + pnp_release_card_device(dev); } + kfree(clink); return 0; } |