Skip to contentSkip to conversation

fix mm/util.c:krealloc()

PATCH In review Adrian Bunk 2 participants 2 messages Oct 19, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix mm/util.c:krealloc()

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

---

mm/util.c renamed from mm/util.c.old +2 -2
@@ -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;
 }
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Adrian Bunk

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