Skip to contentSkip to conversation

turn BUG_ON for out of bound in mb_cache_entry_find_first/mb_cache_entry_find_next

PATCH In review Wang Sheng-Hui 2 participants 3 messages Jul 18, 2010 – Jul 19, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 turn BUG_ON for out of bound in mb_cache_entry_find_first/mb_cache_entry_find_next

In mb_cache_entry_find_first/mb_cache_entry_find_next, macro mb_assert is used to do assertion on index, but it just prints KERN_ERR info if defined.
Currently, only ext2/ext3/ext4 use the function with index set 0. But for potential usage by other subsystems, I think we shoud report BUG if we got some index out of bound here.

Following patch is against 2.6.35-rc3, and should be applied after the first patch.Please check it.

---
 fs/mbcache.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/mbcache.c +0 -0
index 5697d9e..ed25979 100644
@@ -614,7 +614,7 @@ mb_cache_entry_find_first(struct mb_cache *cache,

int index,
struct list_head *l;
struct mb_cache_entry *ce;

- mb_assert(index < mb_cache_indexes(cache));
+ BUG_ON((index < 0) || (index >= mb_cache_indexes(cache)));
spin_lock(&mb_cache_spinlock);
l = cache->c_indexes_hash[index][bucket].next;
ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
@@ -652,7 +652,7 @@ mb_cache_entry_find_next(struct mb_cache_entry *prev, int index,
struct list_head *l;
struct mb_cache_entry *ce;

- mb_assert(index < mb_cache_indexes(cache));
+ BUG_ON((index < 0) || (index >= mb_cache_indexes(cache)));
spin_lock(&mb_cache_spinlock);
l = prev->e_indexes[index].o_list.next;
ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],

Signature · 13 lines
1.7.1.1



-- 
Thanks and Regards,
shenghui

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#1 lore raw
Quoted 11 lines · 在 2010年7月18日 下午9:57,Wang Sheng-Hui <[email protected]> 写道:

In mb_cache_entry_find_first/mb_cache_entry_find_next, macro mb_assert is used to do assertion on index, but it just prints KERN_ERR info if defined.
Currently, only ext2/ext3/ext4 use the function with index set 0. But for potential usage by other subsystems, I think we shoud report BUG if we got some index out of bound here.

Following patch is against 2.6.35-rc3, and should be applied after the first patch.Please check it.

Sorry, made a typo. It's against 2.6.35-rc5.

Signature · 2 lines
Thanks and Best Regards,
shenghui
#2 lore raw

Re: [PATCH 2/2] turn BUG_ON for out of bound in

In reply to Wang Sheng-Hui
Quoted 3 lines · shenghui

Sorry. Will you recommend to me one mail client? I have been suffering reformat by client these days. Thanks,

Mutt, or Alpine will be a very good choice.

This can be also useful:

Documentation/SubmittingPatches
Documentation/email-clients.txt

Cheers
-Lukas

Quoted 32 lines

---
fs/mbcache.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
fs/mbcache.c +1 -1
index 5697d9e..5f96b82 100644
@@ -614,7 +614,7 @@ mb_cache_entry_find_first(struct mb_cache *cache, int
 index,
 	struct list_head *l;
 	struct mb_cache_entry *ce;
 
-	mb_assert(index < mb_cache_indexes(cache));
+	BUG_ON(!(index < mb_cache_indexes(cache)));
 	spin_lock(&mb_cache_spinlock);
 	l = cache->c_indexes_hash[index][bucket].next;
	ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
fs/mbcache.c +1 -1
@@ -652,7 +652,7 @@ mb_cache_entry_find_next(struct mb_cache_entry *prev, int
 index,
 	struct list_head *l;
 	struct mb_cache_entry *ce;
 
-	mb_assert(index < mb_cache_indexes(cache));
+	BUG_ON(!(index < mb_cache_indexes(cache)));
 	spin_lock(&mb_cache_spinlock);
 	l = prev->e_indexes[index].o_list.next;
	ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],