[PATCH 1/3] mbcache: use list_for_each_entry*

From: Namhyung Kim
Date: Tue Dec 07 2010 - 05:09:35 EST


Convert list_for_each*() + list_entry() to list_for_each_entry*().

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxx>
---
fs/mbcache.c | 36 ++++++++++++++----------------------
1 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/fs/mbcache.c b/fs/mbcache.c
index 9344474..0477c71 100644
--- a/fs/mbcache.c
+++ b/fs/mbcache.c
@@ -278,21 +278,18 @@ void
mb_cache_shrink(struct block_device *bdev)
{
LIST_HEAD(free_list);
- struct list_head *l, *ltmp;
+ struct mb_cache_entry *ce, *tmp;

spin_lock(&mb_cache_spinlock);
- list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
- struct mb_cache_entry *ce =
- list_entry(l, struct mb_cache_entry, e_lru_list);
+ list_for_each_entry_safe(ce, tmp, &mb_cache_lru_list, e_lru_list) {
if (ce->e_bdev == bdev) {
list_move_tail(&ce->e_lru_list, &free_list);
__mb_cache_entry_unhash(ce);
}
}
spin_unlock(&mb_cache_spinlock);
- list_for_each_safe(l, ltmp, &free_list) {
- __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
- e_lru_list), GFP_KERNEL);
+ list_for_each_entry_safe(ce, tmp, &free_list, e_lru_list) {
+ __mb_cache_entry_forget(ce, GFP_KERNEL);
}
}

@@ -308,12 +305,10 @@ void
mb_cache_destroy(struct mb_cache *cache)
{
LIST_HEAD(free_list);
- struct list_head *l, *ltmp;
+ struct mb_cache_entry *ce, *tmp;

spin_lock(&mb_cache_spinlock);
- list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
- struct mb_cache_entry *ce =
- list_entry(l, struct mb_cache_entry, e_lru_list);
+ list_for_each_entry_safe(ce, tmp, &mb_cache_lru_list, e_lru_list) {
if (ce->e_cache == cache) {
list_move_tail(&ce->e_lru_list, &free_list);
__mb_cache_entry_unhash(ce);
@@ -322,9 +317,8 @@ mb_cache_destroy(struct mb_cache *cache)
list_del(&cache->c_cache_list);
spin_unlock(&mb_cache_spinlock);

- list_for_each_safe(l, ltmp, &free_list) {
- __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
- e_lru_list), GFP_KERNEL);
+ list_for_each_entry_safe(ce, tmp, &free_list, e_lru_list) {
+ __mb_cache_entry_forget(ce, GFP_KERNEL);
}

if (atomic_read(&cache->c_entry_count) > 0) {
@@ -398,16 +392,16 @@ mb_cache_entry_insert(struct mb_cache_entry *ce, struct block_device *bdev,
{
struct mb_cache *cache = ce->e_cache;
unsigned int bucket;
- struct list_head *l;
+ struct list_head *block_list;
+ struct mb_cache_entry *entry;
int error = -EBUSY;

bucket = hash_long((unsigned long)bdev + (block & 0xffffffff),
cache->c_bucket_bits);
+ block_list = &cache->c_block_hash[bucket];
spin_lock(&mb_cache_spinlock);
- list_for_each_prev(l, &cache->c_block_hash[bucket]) {
- struct mb_cache_entry *ce =
- list_entry(l, struct mb_cache_entry, e_block_list);
- if (ce->e_bdev == bdev && ce->e_block == block)
+ list_for_each_entry_reverse(entry, block_list, e_block_list) {
+ if (entry->e_bdev == bdev && entry->e_block == block)
goto out;
}
__mb_cache_entry_unhash(ce);
@@ -468,14 +462,12 @@ mb_cache_entry_get(struct mb_cache *cache, struct block_device *bdev,
sector_t block)
{
unsigned int bucket;
- struct list_head *l;
struct mb_cache_entry *ce;

bucket = hash_long((unsigned long)bdev + (block & 0xffffffff),
cache->c_bucket_bits);
spin_lock(&mb_cache_spinlock);
- list_for_each(l, &cache->c_block_hash[bucket]) {
- ce = list_entry(l, struct mb_cache_entry, e_block_list);
+ list_for_each_entry(ce, &cache->c_block_hash[bucket], e_block_list) {
if (ce->e_bdev == bdev && ce->e_block == block) {
DEFINE_WAIT(wait);

--
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/