Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-2.6.git] / mm / util.c
index bf340d8..8f18683 100644 (file)
--- a/mm/util.c
+++ b/mm/util.c
@@ -81,20 +81,22 @@ EXPORT_SYMBOL(kmemdup);
 void *krealloc(const void *p, size_t new_size, gfp_t flags)
 {
        void *ret;
-       size_t ks;
+       size_t ks = 0;
 
        if (unlikely(!new_size)) {
                kfree(p);
                return ZERO_SIZE_PTR;
        }
 
-       ks = ksize(p);
+       if (p)
+               ks = ksize(p);
+
        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;