Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 330418
b: refs/heads/master
c: e21827a
h: refs/heads/master
v: v3
  • Loading branch information
Ezequiel Garcia authored and Pekka Enberg committed Sep 4, 2012
1 parent 816c44c commit 584a6e5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5b74beb425e0eb009d16d4b9a0f55847a5f342fa
refs/heads/master: e21827aadd77e33833eeb393de2e8675e9b399e2
35 changes: 21 additions & 14 deletions trunk/mm/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ void *memdup_user(const void __user *src, size_t len)
}
EXPORT_SYMBOL(memdup_user);

static __always_inline void *__do_krealloc(const void *p, size_t new_size,
gfp_t flags)
{
void *ret;
size_t ks = 0;

if (p)
ks = ksize(p);

if (ks >= new_size)
return (void *)p;

ret = kmalloc_track_caller(new_size, flags);
if (ret && p)
memcpy(ret, p, ks);

return ret;
}

/**
* __krealloc - like krealloc() but don't free @p.
* @p: object to reallocate memory for.
Expand All @@ -117,23 +136,11 @@ EXPORT_SYMBOL(memdup_user);
*/
void *__krealloc(const void *p, size_t new_size, gfp_t flags)
{
void *ret;
size_t ks = 0;

if (unlikely(!new_size))
return ZERO_SIZE_PTR;

if (p)
ks = ksize(p);
return __do_krealloc(p, new_size, flags);

if (ks >= new_size)
return (void *)p;

ret = kmalloc_track_caller(new_size, flags);
if (ret && p)
memcpy(ret, p, ks);

return ret;
}
EXPORT_SYMBOL(__krealloc);

Expand All @@ -157,7 +164,7 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags)
return ZERO_SIZE_PTR;
}

ret = __krealloc(p, new_size, flags);
ret = __do_krealloc(p, new_size, flags);
if (ret && p != ret)
kfree(p);

Expand Down

0 comments on commit 584a6e5

Please sign in to comment.