All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Jones <davej@redhat.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Fix leak in PNP interface code.
Date: Wed, 1 Sep 2004 21:40:35 +0100	[thread overview]
Message-ID: <20040901204035.GC10829@redhat.com> (raw)
In-Reply-To: <200409011551.i81FpKj2000605@delerium.codemonkey.org.uk>

On Wed, Sep 01, 2004 at 04:51:20PM +0100, Dave Jones wrote:
 > Spotted with the source checker from Coverity.com.
 > 
 > Signed-off-by: Dave Jones <davej@redhat.com>
 > 
 > 
 > diff -urpN --exclude-from=/home/davej/.exclude bk-linus/drivers/pnp/interface.c linux-2.6/drivers/pnp/interface.c
 > --- bk-linus/drivers/pnp/interface.c	2004-06-03 13:40:04.000000000 +0100
 > +++ linux-2.6/drivers/pnp/interface.c	2004-06-03 13:42:25.000000000 +0100
 > @@ -244,8 +244,10 @@ static ssize_t pnp_show_current_resource
 >  				pnp_alloc(sizeof(pnp_info_buffer_t));
 >  	if (!buffer)
 >  		return -ENOMEM;
 > -	if (!dev)
 > +	if (!dev) {
 > +		kfree(buffer);
 >  		return -EINVAL;
 > +	}
 >  	buffer->len = PAGE_SIZE;
 >  	buffer->buffer = buf;
 >  	buffer->curr = buffer->buffer;
 > -

Joe Perches pointed out that it may be better to just avoid the
allocation completely if !dev, which makes perfect sense to me.

Signed-off-by: Dave Jones <davej@redhat.com>


--- 1/drivers/pnp/interface.c~	2004-09-01 21:37:37.572983736 +0100
+++ 2/drivers/pnp/interface.c	2004-09-01 21:38:41.056332800 +0100
@@ -240,12 +240,14 @@
 {
 	struct pnp_dev *dev = to_pnp_dev(dmdev);
 	int i, ret;
-	pnp_info_buffer_t *buffer = (pnp_info_buffer_t *)
-				pnp_alloc(sizeof(pnp_info_buffer_t));
-	if (!buffer)
-		return -ENOMEM;
+	pnp_info_buffer_t *buffer;
+
 	if (!dev)
 		return -EINVAL;
+
+	buffer = (pnp_info_buffer_t *) pnp_alloc(sizeof(pnp_info_buffer_t));
+	if (!buffer)
+		return -ENOMEM;
 	buffer->len = PAGE_SIZE;
 	buffer->buffer = buf;
 	buffer->curr = buffer->buffer;

      reply	other threads:[~2004-09-01 20:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-01 15:51 [PATCH] Fix leak in PNP interface code Dave Jones
2004-09-01 20:40 ` Dave Jones [this message]

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=20040901204035.GC10829@redhat.com \
    --to=davej@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.