lkml.org 
[lkml]   [2011]   [Feb]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] lru_cache: Use correct type in sizeof for allocation
Date
This has no actual effect, since sizeof(struct hlist_head) ==
sizeof(struct hlist_head *), but it's still the wrong type to use.

The semantic match that finds this problem:
// <smpl>
@@
type T;
identifier x;
@@
T *x;
...
* x = kzalloc(... * sizeof(T*) * ..., ...);
// </smpl>

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>

---
lib/lru_cache.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

Note that in lc_reset, there is the line

memset(lc->lc_slot, 0, sizeof(struct hlist_head) * lc->nr_elements);

So this seems correct. But otherwise untested.

diff --git a/lib/lru_cache.c b/lib/lru_cache.c
index 270de9d..b312c8f 100644
--- a/lib/lru_cache.c
+++ b/lib/lru_cache.c
@@ -84,7 +84,7 @@ struct lru_cache *lc_create(const char *name, struct kmem_cache *cache,
if (e_count > LC_MAX_ACTIVE)
return NULL;

- slot = kzalloc(e_count * sizeof(struct hlist_head*), GFP_KERNEL);
+ slot = kzalloc(e_count * sizeof(struct hlist_head), GFP_KERNEL);
if (!slot)
goto out_fail;
element = kzalloc(e_count * sizeof(struct lc_element *), GFP_KERNEL);
--
1.7.3.4


\
 
 \ /
  Last update: 2011-02-20 23:47    [W:0.096 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site