Skip to content

Commit 159ec1f

Browse files
crquanneilbrown
authored andcommitted
md: use list_for_each_entry macro directly
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 <crquan@gmail.com> Signed-off-by: NeilBrown <neilb@suse.de>
1 parent ccacc7d commit 159ec1f

10 files changed

Lines changed: 60 additions & 94 deletions

File tree

drivers/md/bitmap.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,14 @@ static struct page *read_sb_page(mddev_t *mddev, long offset,
215215
/* choose a good rdev and read the page from there */
216216

217217
mdk_rdev_t *rdev;
218-
struct list_head *tmp;
219218
sector_t target;
220219

221220
if (!page)
222221
page = alloc_page(GFP_KERNEL);
223222
if (!page)
224223
return ERR_PTR(-ENOMEM);
225224

226-
rdev_for_each(rdev, tmp, mddev) {
225+
list_for_each_entry(rdev, &mddev->disks, same_set) {
227226
if (! test_bit(In_sync, &rdev->flags)
228227
|| test_bit(Faulty, &rdev->flags))
229228
continue;

drivers/md/faulty.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ static int reconfig(mddev_t *mddev, int layout, int chunk_size)
283283
static int run(mddev_t *mddev)
284284
{
285285
mdk_rdev_t *rdev;
286-
struct list_head *tmp;
287286
int i;
288287

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

299-
rdev_for_each(rdev, tmp, mddev)
298+
list_for_each_entry(rdev, &mddev->disks, same_set)
300299
conf->rdev = rdev;
301300

302301
mddev->array_sectors = mddev->size * 2;

drivers/md/linear.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
105105
int i, nb_zone, cnt;
106106
sector_t min_sectors;
107107
sector_t curr_sector;
108-
struct list_head *tmp;
109108

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

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

0 commit comments

Comments
 (0)