Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 60734
b: refs/heads/master
c: ef2ad80
h: refs/heads/master
v: v3
  • Loading branch information
Christoph Lameter authored and Linus Torvalds committed Jul 17, 2007
1 parent 03139ff commit 8f2e75b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 117 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: d45f39cb06610ea456e1d689149b9becacda8b40
refs/heads/master: ef2ad80c7d255ed0449eda947c2d700635b7e0f5
46 changes: 0 additions & 46 deletions trunk/mm/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -3725,52 +3725,6 @@ void *__kmalloc(size_t size, gfp_t flags)
EXPORT_SYMBOL(__kmalloc);
#endif

/**
* krealloc - reallocate memory. The contents will remain unchanged.
* @p: object to reallocate memory for.
* @new_size: how many bytes of memory are required.
* @flags: the type of memory to allocate.
*
* The contents of the object pointed to are preserved up to the
* lesser of the new and old sizes. If @p is %NULL, krealloc()
* behaves exactly like kmalloc(). If @size is 0 and @p is not a
* %NULL pointer, the object pointed to is freed.
*/
void *krealloc(const void *p, size_t new_size, gfp_t flags)
{
struct kmem_cache *cache, *new_cache;
void *ret;

if (unlikely(!p))
return kmalloc_track_caller(new_size, flags);

if (unlikely(!new_size)) {
kfree(p);
return NULL;
}

cache = virt_to_cache(p);
new_cache = __find_general_cachep(new_size, flags);

/*
* If new size fits in the current cache, bail out.
*/
if (likely(cache == new_cache))
return (void *)p;

/*
* We are on the slow-path here so do not use __cache_alloc
* because it bloats kernel text.
*/
ret = kmalloc_track_caller(new_size, flags);
if (ret) {
memcpy(ret, p, min(new_size, ksize(p)));
kfree(p);
}
return ret;
}
EXPORT_SYMBOL(krealloc);

/**
* kmem_cache_free - Deallocate an object
* @cachep: The cache the allocation was from.
Expand Down
33 changes: 0 additions & 33 deletions trunk/mm/slob.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,39 +446,6 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
}
EXPORT_SYMBOL(__kmalloc_node);

/**
* krealloc - reallocate memory. The contents will remain unchanged.
*
* @p: object to reallocate memory for.
* @new_size: how many bytes of memory are required.
* @flags: the type of memory to allocate.
*
* The contents of the object pointed to are preserved up to the
* lesser of the new and old sizes. If @p is %NULL, krealloc()
* behaves exactly like kmalloc(). If @size is 0 and @p is not a
* %NULL pointer, the object pointed to is freed.
*/
void *krealloc(const void *p, size_t new_size, gfp_t flags)
{
void *ret;

if (unlikely(!p))
return kmalloc_track_caller(new_size, flags);

if (unlikely(!new_size)) {
kfree(p);
return NULL;
}

ret = kmalloc_track_caller(new_size, flags);
if (ret) {
memcpy(ret, p, min(new_size, ksize(p)));
kfree(p);
}
return ret;
}
EXPORT_SYMBOL(krealloc);

void kfree(const void *block)
{
struct slob_page *sp;
Expand Down
37 changes: 0 additions & 37 deletions trunk/mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -2467,43 +2467,6 @@ int kmem_cache_shrink(struct kmem_cache *s)
}
EXPORT_SYMBOL(kmem_cache_shrink);

/**
* krealloc - reallocate memory. The contents will remain unchanged.
* @p: object to reallocate memory for.
* @new_size: how many bytes of memory are required.
* @flags: the type of memory to allocate.
*
* The contents of the object pointed to are preserved up to the
* lesser of the new and old sizes. If @p is %NULL, krealloc()
* behaves exactly like kmalloc(). If @size is 0 and @p is not a
* %NULL pointer, the object pointed to is freed.
*/
void *krealloc(const void *p, size_t new_size, gfp_t flags)
{
void *ret;
size_t ks;

if (unlikely(!p || p == ZERO_SIZE_PTR))
return kmalloc(new_size, flags);

if (unlikely(!new_size)) {
kfree(p);
return ZERO_SIZE_PTR;
}

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

ret = kmalloc(new_size, flags);
if (ret) {
memcpy(ret, p, min(new_size, ks));
kfree(p);
}
return ret;
}
EXPORT_SYMBOL(krealloc);

/********************************************************************
* Basic setup of slabs
*******************************************************************/
Expand Down
34 changes: 34 additions & 0 deletions trunk/mm/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,40 @@ void *kmemdup(const void *src, size_t len, gfp_t gfp)
}
EXPORT_SYMBOL(kmemdup);

/**
* krealloc - reallocate memory. The contents will remain unchanged.
* @p: object to reallocate memory for.
* @new_size: how many bytes of memory are required.
* @flags: the type of memory to allocate.
*
* The contents of the object pointed to are preserved up to the
* lesser of the new and old sizes. If @p is %NULL, krealloc()
* behaves exactly like kmalloc(). If @size is 0 and @p is not a
* %NULL pointer, the object pointed to is freed.
*/
void *krealloc(const void *p, size_t new_size, gfp_t flags)
{
void *ret;
size_t ks;

if (unlikely(!new_size)) {
kfree(p);
return NULL;
}

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));
kfree(p);
}
return ret;
}
EXPORT_SYMBOL(krealloc);

/*
* strndup_user - duplicate an existing string from user space
*
Expand Down

0 comments on commit 8f2e75b

Please sign in to comment.