aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorChris Malley <mail@chrismalley.co.uk>2008-05-19 15:11:50 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2008-06-04 12:53:31 -0400
commit71a928c0e52cedc43747c64b96a5f74592ab678f (patch)
tree98f4862294a23b859af87f6df44e9668a3fbc133 /drivers
parent59018b6d2acabb114ab58637e6ab95ba424a89d0 (diff)
[MTD] Use list_for_each_entry[_safe] where appropriate.
Janitorial work to remove temporary pointers and make some functions a bit more readable. Signed-off-by: Chris Malley <mail@chrismalley.co.uk> Reviewed-By: Jörn Engel <joern@logfs.org> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/mtd_blkdevs.c32
-rw-r--r--drivers/mtd/mtdcore.c6
-rw-r--r--drivers/mtd/mtdpart.c23
3 files changed, 19 insertions, 42 deletions
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index a0ada45672d8..9ff007c4962c 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -210,7 +210,7 @@ static struct block_device_operations mtd_blktrans_ops = {
210int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) 210int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
211{ 211{
212 struct mtd_blktrans_ops *tr = new->tr; 212 struct mtd_blktrans_ops *tr = new->tr;
213 struct list_head *this; 213 struct mtd_blktrans_dev *d;
214 int last_devnum = -1; 214 int last_devnum = -1;
215 struct gendisk *gd; 215 struct gendisk *gd;
216 216
@@ -219,8 +219,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
219 BUG(); 219 BUG();
220 } 220 }
221 221
222 list_for_each(this, &tr->devs) { 222 list_for_each_entry(d, &tr->devs, list) {
223 struct mtd_blktrans_dev *d = list_entry(this, struct mtd_blktrans_dev, list);
224 if (new->devnum == -1) { 223 if (new->devnum == -1) {
225 /* Use first free number */ 224 /* Use first free number */
226 if (d->devnum != last_devnum+1) { 225 if (d->devnum != last_devnum+1) {
@@ -307,33 +306,24 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
307 306
308static void blktrans_notify_remove(struct mtd_info *mtd) 307static void blktrans_notify_remove(struct mtd_info *mtd)
309{ 308{
310 struct list_head *this, *this2, *next; 309 struct mtd_blktrans_ops *tr;
311 310 struct mtd_blktrans_dev *dev, *next;
312 list_for_each(this, &blktrans_majors) {
313 struct mtd_blktrans_ops *tr = list_entry(this, struct mtd_blktrans_ops, list);
314
315 list_for_each_safe(this2, next, &tr->devs) {
316 struct mtd_blktrans_dev *dev = list_entry(this2, struct mtd_blktrans_dev, list);
317 311
312 list_for_each_entry(tr, &blktrans_majors, list)
313 list_for_each_entry_safe(dev, next, &tr->devs, list)
318 if (dev->mtd == mtd) 314 if (dev->mtd == mtd)
319 tr->remove_dev(dev); 315 tr->remove_dev(dev);
320 }
321 }
322} 316}
323 317
324static void blktrans_notify_add(struct mtd_info *mtd) 318static void blktrans_notify_add(struct mtd_info *mtd)
325{ 319{
326 struct list_head *this; 320 struct mtd_blktrans_ops *tr;
327 321
328 if (mtd->type == MTD_ABSENT) 322 if (mtd->type == MTD_ABSENT)
329 return; 323 return;
330 324
331 list_for_each(this, &blktrans_majors) { 325 list_for_each_entry(tr, &blktrans_majors, list)
332 struct mtd_blktrans_ops *tr = list_entry(this, struct mtd_blktrans_ops, list);
333
334 tr->add_mtd(tr, mtd); 326 tr->add_mtd(tr, mtd);
335 }
336
337} 327}
338 328
339static struct mtd_notifier blktrans_notifier = { 329static struct mtd_notifier blktrans_notifier = {
@@ -404,7 +394,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
404 394
405int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr) 395int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
406{ 396{
407 struct list_head *this, *next; 397 struct mtd_blktrans_dev *dev, *next;
408 398
409 mutex_lock(&mtd_table_mutex); 399 mutex_lock(&mtd_table_mutex);
410 400
@@ -414,10 +404,8 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
414 /* Remove it from the list of active majors */ 404 /* Remove it from the list of active majors */
415 list_del(&tr->list); 405 list_del(&tr->list);
416 406
417 list_for_each_safe(this, next, &tr->devs) { 407 list_for_each_entry_safe(dev, next, &tr->devs, list)
418 struct mtd_blktrans_dev *dev = list_entry(this, struct mtd_blktrans_dev, list);
419 tr->remove_dev(dev); 408 tr->remove_dev(dev);
420 }
421 409
422 blk_cleanup_queue(tr->blkcore_priv->rq); 410 blk_cleanup_queue(tr->blkcore_priv->rq);
423 unregister_blkdev(tr->major, tr->name); 411 unregister_blkdev(tr->major, tr->name);
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 4373790401d3..a9d246949820 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -70,9 +70,8 @@ int add_mtd_device(struct mtd_info *mtd)
70 DEBUG(0, "mtd: Giving out device %d to %s\n",i, mtd->name); 70 DEBUG(0, "mtd: Giving out device %d to %s\n",i, mtd->name);
71 /* No need to get a refcount on the module containing 71 /* No need to get a refcount on the module containing
72 the notifier, since we hold the mtd_table_mutex */ 72 the notifier, since we hold the mtd_table_mutex */
73 list_for_each_entry(not, &mtd_notifiers, list) { 73 list_for_each_entry(not, &mtd_notifiers, list)
74 not->add(mtd); 74 not->add(mtd);
75 }
76 75
77 mutex_unlock(&mtd_table_mutex); 76 mutex_unlock(&mtd_table_mutex);
78 /* We _know_ we aren't being removed, because 77 /* We _know_ we aren't being removed, because
@@ -114,9 +113,8 @@ int del_mtd_device (struct mtd_info *mtd)
114 113
115 /* No need to get a refcount on the module containing 114 /* No need to get a refcount on the module containing
116 the notifier, since we hold the mtd_table_mutex */ 115 the notifier, since we hold the mtd_table_mutex */
117 list_for_each_entry(not, &mtd_notifiers, list) { 116 list_for_each_entry(not, &mtd_notifiers, list)
118 not->remove(mtd); 117 not->remove(mtd);
119 }
120 118
121 mtd_table[mtd->index] = NULL; 119 mtd_table[mtd->index] = NULL;
122 120
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 11b803cc405b..56a760a736a9 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -300,22 +300,15 @@ static int part_block_markbad (struct mtd_info *mtd, loff_t ofs)
300 300
301int del_mtd_partitions(struct mtd_info *master) 301int del_mtd_partitions(struct mtd_info *master)
302{ 302{
303 struct list_head *node; 303 struct mtd_part *slave, *next;
304 struct mtd_part *slave;
305 304
306 for (node = mtd_partitions.next; 305 list_for_each_entry_safe(slave, next, &mtd_partitions, list)
307 node != &mtd_partitions;
308 node = node->next) {
309 slave = list_entry(node, struct mtd_part, list);
310 if (slave->master == master) { 306 if (slave->master == master) {
311 struct list_head *prev = node->prev; 307 list_del(&slave->list);
312 __list_del(prev, node->next);
313 if(slave->registered) 308 if(slave->registered)
314 del_mtd_device(&slave->mtd); 309 del_mtd_device(&slave->mtd);
315 kfree(slave); 310 kfree(slave);
316 node = prev;
317 } 311 }
318 }
319 312
320 return 0; 313 return 0;
321} 314}
@@ -511,18 +504,16 @@ static LIST_HEAD(part_parsers);
511 504
512static struct mtd_part_parser *get_partition_parser(const char *name) 505static struct mtd_part_parser *get_partition_parser(const char *name)
513{ 506{
514 struct list_head *this; 507 struct mtd_part_parser *p, *ret = NULL;
515 void *ret = NULL;
516 spin_lock(&part_parser_lock);
517 508
518 list_for_each(this, &part_parsers) { 509 spin_lock(&part_parser_lock);
519 struct mtd_part_parser *p = list_entry(this, struct mtd_part_parser, list);
520 510
511 list_for_each_entry(p, &part_parsers, list)
521 if (!strcmp(p->name, name) && try_module_get(p->owner)) { 512 if (!strcmp(p->name, name) && try_module_get(p->owner)) {
522 ret = p; 513 ret = p;
523 break; 514 break;
524 } 515 }
525 } 516
526 spin_unlock(&part_parser_lock); 517 spin_unlock(&part_parser_lock);
527 518
528 return ret; 519 return ret;