public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [2.6 patch] fix mm/util.c:krealloc()
@ 2007-10-19 14:05 Adrian Bunk
  2007-10-19 17:42 ` Christoph Lameter
  0 siblings, 1 reply; 2+ messages in thread
From: Adrian Bunk @ 2007-10-19 14:05 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [2.6 patch] fix mm/util.c:krealloc()
  2007-10-19 14:05 [2.6 patch] fix mm/util.c:krealloc() Adrian Bunk
@ 2007-10-19 17:42 ` Christoph Lameter
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Lameter @ 2007-10-19 17:42 UTC (permalink / raw)
  To: Adrian Bunk; +Cc: linux-kernel

On Fri, 19 Oct 2007, Adrian Bunk wrote:

> 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().

Acked-by: Chriustoph Lameter <clameter@sgi.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-10-19 17:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-19 14:05 [2.6 patch] fix mm/util.c:krealloc() Adrian Bunk
2007-10-19 17:42 ` Christoph Lameter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox