public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Adrian Bunk <bunk@kernel.org>
To: Christoph Lameter <clameter@sgi.com>
Cc: linux-kernel@vger.kernel.org
Subject: [2.6 patch] fix mm/util.c:krealloc()
Date: Fri, 19 Oct 2007 16:05:02 +0200	[thread overview]
Message-ID: <20071019140502.GD3778@stusta.de> (raw)

Commit ef8b4520bd9f8294ffce9abd6158085bde5dc902 added one NULL check for 
"p" in krealloc(), but that doesn't seem to be enough since there 
doesn't seem to be any guarantee that memcpy(ret, NULL, 0) works 
(spotted by the Coverity checker).

For making it clearer what happens this patch also removes the
pointless min().

Signed-off-by: Adrian Bunk <bunk@kernel.org>

---
--- linux-2.6/mm/util.c.old	2007-10-19 15:10:43.000000000 +0200
+++ linux-2.6/mm/util.c	2007-10-19 15:32:01.000000000 +0200
@@ -94,10 +94,10 @@ void *krealloc(const void *p, size_t new
 	if (ks >= new_size)
 		return (void *)p;
 
 	ret = kmalloc_track_caller(new_size, flags);
-	if (ret) {
-		memcpy(ret, p, min(new_size, ks));
+	if (ret && p) {
+		memcpy(ret, p, ks);
 		kfree(p);
 	}
 	return ret;
 }

             reply	other threads:[~2007-10-19 14:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-19 14:05 Adrian Bunk [this message]
2007-10-19 17:42 ` [2.6 patch] fix mm/util.c:krealloc() Christoph Lameter

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=20071019140502.GD3778@stusta.de \
    --to=bunk@kernel.org \
    --cc=clameter@sgi.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