mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Keith Owens <kaos@ocs.com.au>
To: Andrew Morton <akpm@osdl.org>
Cc: Jesper Juhl <jesper.juhl@gmail.com>,
	linux-kernel@vger.kernel.org, ambx1@neo.rr.com
Subject: Re: [PATCH][resend] fix resource leak in pnp card_probe()
Date: Sun, 14 May 2006 19:48:09 +1000	[thread overview]
Message-ID: <31862.1147600089@ocs3> (raw)
In-Reply-To: Your message of "Sun, 14 May 2006 02:38:33 MST." <20060514023833.649fde1d.akpm@osdl.org>

Andrew Morton (on Sun, 14 May 2006 02:38:33 -0700) wrote:
>If !drv->probe then there's not much point in doing the kmalloc and then
>immediately freeing it again.
>
>Like this?
>
>--- devel/drivers/pnp/card.c~pnp-card_probe-fix-memory-leak	2006-05-14 02:30:25.000000000 -0700
>+++ devel-akpm/drivers/pnp/card.c	2006-05-14 02:36:24.000000000 -0700
>@@ -60,30 +60,34 @@ static void card_remove_first(struct pnp
> 	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;

Memory leak of clink on next test.

>+
>+	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;
> }


  reply	other threads:[~2006-05-14  9:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-13 20:35 Jesper Juhl
2006-05-14  9:38 ` Andrew Morton
2006-05-14  9:48   ` Keith Owens [this message]
2006-05-14  9:58     ` Andrew Morton
2006-05-14 10:42   ` Jesper Juhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=31862.1147600089@ocs3 \
    --to=kaos@ocs.com.au \
    --cc=akpm@osdl.org \
    --cc=ambx1@neo.rr.com \
    --cc=jesper.juhl@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®