]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[MTD] Use list_for_each_entry[_safe] where appropriate.
authorChris Malley <mail@chrismalley.co.uk>
Mon, 19 May 2008 19:11:50 +0000 (20:11 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Wed, 4 Jun 2008 16:53:31 +0000 (17:53 +0100)
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>
drivers/mtd/mtd_blkdevs.c
drivers/mtd/mtdcore.c
drivers/mtd/mtdpart.c

index a0ada45672d8bcdc24dcf6ff2e6051f6ecdbcfe1..9ff007c4962c9f3c58868385729a915ba6b28222 100644 (file)
@@ -210,7 +210,7 @@ static struct block_device_operations mtd_blktrans_ops = {
 int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
 {
        struct mtd_blktrans_ops *tr = new->tr;
-       struct list_head *this;
+       struct mtd_blktrans_dev *d;
        int last_devnum = -1;
        struct gendisk *gd;
 
@@ -219,8 +219,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
                BUG();
        }
 
-       list_for_each(this, &tr->devs) {
-               struct mtd_blktrans_dev *d = list_entry(this, struct mtd_blktrans_dev, list);
+       list_for_each_entry(d, &tr->devs, list) {
                if (new->devnum == -1) {
                        /* Use first free number */
                        if (d->devnum != last_devnum+1) {
@@ -307,33 +306,24 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
 
 static void blktrans_notify_remove(struct mtd_info *mtd)
 {
-       struct list_head *this, *this2, *next;
-
-       list_for_each(this, &blktrans_majors) {
-               struct mtd_blktrans_ops *tr = list_entry(this, struct mtd_blktrans_ops, list);
-
-               list_for_each_safe(this2, next, &tr->devs) {
-                       struct mtd_blktrans_dev *dev = list_entry(this2, struct mtd_blktrans_dev, list);
+       struct mtd_blktrans_ops *tr;
+       struct mtd_blktrans_dev *dev, *next;
 
+       list_for_each_entry(tr, &blktrans_majors, list)
+               list_for_each_entry_safe(dev, next, &tr->devs, list)
                        if (dev->mtd == mtd)
                                tr->remove_dev(dev);
-               }
-       }
 }
 
 static void blktrans_notify_add(struct mtd_info *mtd)
 {
-       struct list_head *this;
+       struct mtd_blktrans_ops *tr;
 
        if (mtd->type == MTD_ABSENT)
                return;
 
-       list_for_each(this, &blktrans_majors) {
-               struct mtd_blktrans_ops *tr = list_entry(this, struct mtd_blktrans_ops, list);
-
+       list_for_each_entry(tr, &blktrans_majors, list)
                tr->add_mtd(tr, mtd);
-       }
-
 }
 
 static struct mtd_notifier blktrans_notifier = {
@@ -404,7 +394,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
 
 int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
 {
-       struct list_head *this, *next;
+       struct mtd_blktrans_dev *dev, *next;
 
        mutex_lock(&mtd_table_mutex);
 
@@ -414,10 +404,8 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
        /* Remove it from the list of active majors */
        list_del(&tr->list);
 
-       list_for_each_safe(this, next, &tr->devs) {
-               struct mtd_blktrans_dev *dev = list_entry(this, struct mtd_blktrans_dev, list);
+       list_for_each_entry_safe(dev, next, &tr->devs, list)
                tr->remove_dev(dev);
-       }
 
        blk_cleanup_queue(tr->blkcore_priv->rq);
        unregister_blkdev(tr->major, tr->name);
index 4373790401d3931ac75d456fb908ba59a6cc8ad6..a9d246949820a9b0b61aef86061ddf341be21f92 100644 (file)
@@ -70,9 +70,8 @@ int add_mtd_device(struct mtd_info *mtd)
                        DEBUG(0, "mtd: Giving out device %d to %s\n",i, mtd->name);
                        /* No need to get a refcount on the module containing
                           the notifier, since we hold the mtd_table_mutex */
-                       list_for_each_entry(not, &mtd_notifiers, list) {
+                       list_for_each_entry(not, &mtd_notifiers, list)
                                not->add(mtd);
-                       }
 
                        mutex_unlock(&mtd_table_mutex);
                        /* We _know_ we aren't being removed, because
@@ -114,9 +113,8 @@ int del_mtd_device (struct mtd_info *mtd)
 
                /* No need to get a refcount on the module containing
                   the notifier, since we hold the mtd_table_mutex */
-               list_for_each_entry(not, &mtd_notifiers, list) {
+               list_for_each_entry(not, &mtd_notifiers, list)
                        not->remove(mtd);
-               }
 
                mtd_table[mtd->index] = NULL;
 
index 11b803cc405bd8e5f5e5a09650af8c9e572b3d6f..56a760a736a93ccac5e4554db6fb8e1c6feb5c9d 100644 (file)
@@ -300,22 +300,15 @@ static int part_block_markbad (struct mtd_info *mtd, loff_t ofs)
 
 int del_mtd_partitions(struct mtd_info *master)
 {
-       struct list_head *node;
-       struct mtd_part *slave;
+       struct mtd_part *slave, *next;
 
-       for (node = mtd_partitions.next;
-            node != &mtd_partitions;
-            node = node->next) {
-               slave = list_entry(node, struct mtd_part, list);
+       list_for_each_entry_safe(slave, next, &mtd_partitions, list)
                if (slave->master == master) {
-                       struct list_head *prev = node->prev;
-                       __list_del(prev, node->next);
+                       list_del(&slave->list);
                        if(slave->registered)
                                del_mtd_device(&slave->mtd);
                        kfree(slave);
-                       node = prev;
                }
-       }
 
        return 0;
 }
@@ -511,18 +504,16 @@ static LIST_HEAD(part_parsers);
 
 static struct mtd_part_parser *get_partition_parser(const char *name)
 {
-       struct list_head *this;
-       void *ret = NULL;
-       spin_lock(&part_parser_lock);
+       struct mtd_part_parser *p, *ret = NULL;
 
-       list_for_each(this, &part_parsers) {
-               struct mtd_part_parser *p = list_entry(this, struct mtd_part_parser, list);
+       spin_lock(&part_parser_lock);
 
+       list_for_each_entry(p, &part_parsers, list)
                if (!strcmp(p->name, name) && try_module_get(p->owner)) {
                        ret = p;
                        break;
                }
-       }
+
        spin_unlock(&part_parser_lock);
 
        return ret;