Skip to content

Commit

Permalink
[PATCH] pnp: card_probe(): fix memory leak
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jesper Juhl authored and Linus Torvalds committed Jun 25, 2006
1 parent 552c034 commit a9adb8d
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions drivers/pnp/card.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit a9adb8d

Please sign in to comment.