Skip to content

Commit

Permalink
md: use list_for_each_entry macro directly
Browse files Browse the repository at this point in the history
The rdev_for_each macro defined in <linux/raid/md_k.h> is identical to
list_for_each_entry_safe, from <linux/list.h>, it should be defined to
use list_for_each_entry_safe, instead of reinventing the wheel.

But some calls to each_entry_safe don't really need a safe version,
just a direct list_for_each_entry is enough, this could save a temp
variable (tmp) in every function that used rdev_for_each.

In this patch, most rdev_for_each loops are replaced by list_for_each_entry,
totally save many tmp vars; and only in the other situations that will call
list_del to delete an entry, the safe version is used.

Signed-off-by: Cheng Renquan <[email protected]>
Signed-off-by: NeilBrown <[email protected]>
  • Loading branch information
crquan authored and neilbrown committed Jan 8, 2009
1 parent ccacc7d commit 159ec1f
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 94 deletions.
3 changes: 1 addition & 2 deletions drivers/md/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,14 @@ static struct page *read_sb_page(mddev_t *mddev, long offset,
/* choose a good rdev and read the page from there */

mdk_rdev_t *rdev;
struct list_head *tmp;
sector_t target;

if (!page)
page = alloc_page(GFP_KERNEL);
if (!page)
return ERR_PTR(-ENOMEM);

rdev_for_each(rdev, tmp, mddev) {
list_for_each_entry(rdev, &mddev->disks, same_set) {
if (! test_bit(In_sync, &rdev->flags)
|| test_bit(Faulty, &rdev->flags))
continue;
Expand Down
3 changes: 1 addition & 2 deletions drivers/md/faulty.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ static int reconfig(mddev_t *mddev, int layout, int chunk_size)
static int run(mddev_t *mddev)
{
mdk_rdev_t *rdev;
struct list_head *tmp;
int i;

conf_t *conf = kmalloc(sizeof(*conf), GFP_KERNEL);
Expand All @@ -296,7 +295,7 @@ static int run(mddev_t *mddev)
}
conf->nfaults = 0;

rdev_for_each(rdev, tmp, mddev)
list_for_each_entry(rdev, &mddev->disks, same_set)
conf->rdev = rdev;

mddev->array_sectors = mddev->size * 2;
Expand Down
3 changes: 1 addition & 2 deletions drivers/md/linear.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
int i, nb_zone, cnt;
sector_t min_sectors;
sector_t curr_sector;
struct list_head *tmp;

conf = kzalloc (sizeof (*conf) + raid_disks*sizeof(dev_info_t),
GFP_KERNEL);
Expand All @@ -115,7 +114,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
cnt = 0;
conf->array_sectors = 0;

rdev_for_each(rdev, tmp, mddev) {
list_for_each_entry(rdev, &mddev->disks, same_set) {
int j = rdev->raid_disk;
dev_info_t *disk = conf->disks + j;

Expand Down
Loading

0 comments on commit 159ec1f

Please sign in to comment.