Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 97790
b: refs/heads/master
c: 6cfd53f
h: refs/heads/master
v: v3
  • Loading branch information
Paul Mundt authored and Linus Torvalds committed Jun 6, 2008
1 parent 35a4b0d commit a9d7a57
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 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: 6f09bdfc717a0e1a89a029001484d5a195faab64
refs/heads/master: 6cfd53fc03670c7a544a56d441eb1a6cc800d72b
30 changes: 26 additions & 4 deletions trunk/mm/nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,43 @@ EXPORT_SYMBOL(vmtruncate);
unsigned int kobjsize(const void *objp)
{
struct page *page;
int order = 0;

/*
* If the object we have should not have ksize performed on it,
* return size of 0
*/
if (!objp || (unsigned long)objp >= memory_end || !((page = virt_to_page(objp))))
if (!objp)
return 0;

if ((unsigned long)objp >= memory_end)
return 0;

page = virt_to_head_page(objp);
if (!page)
return 0;

/*
* If the allocator sets PageSlab, we know the pointer came from
* kmalloc().
*/
if (PageSlab(page))
return ksize(objp);

BUG_ON(page->index < 0);
BUG_ON(page->index >= MAX_ORDER);
/*
* The ksize() function is only guaranteed to work for pointers
* returned by kmalloc(). So handle arbitrary pointers, that we expect
* always to be compound pages, here.
*/
if (PageCompound(page))
order = compound_order(page);

return (PAGE_SIZE << page->index);
/*
* Finally, handle arbitrary pointers that don't set PageSlab.
* Default to 0-order in the case when we're unable to ksize()
* the object.
*/
return PAGE_SIZE << order;
}

/*
Expand Down

0 comments on commit a9d7a57

Please sign in to comment.