Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71a928c0 authored by Chris Malley's avatar Chris Malley Committed by David Woodhouse
Browse files

[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: default avatarChris Malley <mail@chrismalley.co.uk>
Reviewed-By: default avatarJörn Engel <joern@logfs.org>
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent 59018b6d
Loading
Loading
Loading
Loading
+10 −22
Original line number Original line Diff line number Diff line
@@ -210,7 +210,7 @@ static struct block_device_operations mtd_blktrans_ops = {
int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
{
{
	struct mtd_blktrans_ops *tr = new->tr;
	struct mtd_blktrans_ops *tr = new->tr;
	struct list_head *this;
	struct mtd_blktrans_dev *d;
	int last_devnum = -1;
	int last_devnum = -1;
	struct gendisk *gd;
	struct gendisk *gd;


@@ -219,8 +219,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
		BUG();
		BUG();
	}
	}


	list_for_each(this, &tr->devs) {
	list_for_each_entry(d, &tr->devs, list) {
		struct mtd_blktrans_dev *d = list_entry(this, struct mtd_blktrans_dev, list);
		if (new->devnum == -1) {
		if (new->devnum == -1) {
			/* Use first free number */
			/* Use first free number */
			if (d->devnum != last_devnum+1) {
			if (d->devnum != last_devnum+1) {
@@ -307,35 +306,26 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)


static void blktrans_notify_remove(struct mtd_info *mtd)
static void blktrans_notify_remove(struct mtd_info *mtd)
{
{
	struct list_head *this, *this2, *next;
	struct mtd_blktrans_ops *tr;

	struct mtd_blktrans_dev *dev, *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);


	list_for_each_entry(tr, &blktrans_majors, list)
		list_for_each_entry_safe(dev, next, &tr->devs, list)
			if (dev->mtd == mtd)
			if (dev->mtd == mtd)
				tr->remove_dev(dev);
				tr->remove_dev(dev);
}
}
	}
}


static void blktrans_notify_add(struct mtd_info *mtd)
static void blktrans_notify_add(struct mtd_info *mtd)
{
{
	struct list_head *this;
	struct mtd_blktrans_ops *tr;


	if (mtd->type == MTD_ABSENT)
	if (mtd->type == MTD_ABSENT)
		return;
		return;


	list_for_each(this, &blktrans_majors) {
	list_for_each_entry(tr, &blktrans_majors, list)
		struct mtd_blktrans_ops *tr = list_entry(this, struct mtd_blktrans_ops, list);

		tr->add_mtd(tr, mtd);
		tr->add_mtd(tr, mtd);
}
}


}

static struct mtd_notifier blktrans_notifier = {
static struct mtd_notifier blktrans_notifier = {
	.add = blktrans_notify_add,
	.add = blktrans_notify_add,
	.remove = blktrans_notify_remove,
	.remove = blktrans_notify_remove,
@@ -404,7 +394,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)


int deregister_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);
	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 */
	/* Remove it from the list of active majors */
	list_del(&tr->list);
	list_del(&tr->list);


	list_for_each_safe(this, next, &tr->devs) {
	list_for_each_entry_safe(dev, next, &tr->devs, list)
		struct mtd_blktrans_dev *dev = list_entry(this, struct mtd_blktrans_dev, list);
		tr->remove_dev(dev);
		tr->remove_dev(dev);
	}


	blk_cleanup_queue(tr->blkcore_priv->rq);
	blk_cleanup_queue(tr->blkcore_priv->rq);
	unregister_blkdev(tr->major, tr->name);
	unregister_blkdev(tr->major, tr->name);
+2 −4
Original line number Original line Diff line number Diff line
@@ -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);
			DEBUG(0, "mtd: Giving out device %d to %s\n",i, mtd->name);
			/* No need to get a refcount on the module containing
			/* No need to get a refcount on the module containing
			   the notifier, since we hold the mtd_table_mutex */
			   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);
				not->add(mtd);
			}


			mutex_unlock(&mtd_table_mutex);
			mutex_unlock(&mtd_table_mutex);
			/* We _know_ we aren't being removed, because
			/* 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
		/* No need to get a refcount on the module containing
		   the notifier, since we hold the mtd_table_mutex */
		   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);
			not->remove(mtd);
		}


		mtd_table[mtd->index] = NULL;
		mtd_table[mtd->index] = NULL;


+7 −16
Original line number Original line Diff line number Diff line
@@ -300,21 +300,14 @@ static int part_block_markbad (struct mtd_info *mtd, loff_t ofs)


int del_mtd_partitions(struct mtd_info *master)
int del_mtd_partitions(struct mtd_info *master)
{
{
	struct list_head *node;
	struct mtd_part *slave, *next;
	struct mtd_part *slave;


	for (node = mtd_partitions.next;
	list_for_each_entry_safe(slave, next, &mtd_partitions, list)
	     node != &mtd_partitions;
	     node = node->next) {
		slave = list_entry(node, struct mtd_part, list);
		if (slave->master == master) {
		if (slave->master == master) {
			struct list_head *prev = node->prev;
			list_del(&slave->list);
			__list_del(prev, node->next);
			if(slave->registered)
			if(slave->registered)
				del_mtd_device(&slave->mtd);
				del_mtd_device(&slave->mtd);
			kfree(slave);
			kfree(slave);
			node = prev;
		}
		}
		}


	return 0;
	return 0;
@@ -511,18 +504,16 @@ static LIST_HEAD(part_parsers);


static struct mtd_part_parser *get_partition_parser(const char *name)
static struct mtd_part_parser *get_partition_parser(const char *name)
{
{
	struct list_head *this;
	struct mtd_part_parser *p, *ret = NULL;
	void *ret = NULL;
	spin_lock(&part_parser_lock);


	list_for_each(this, &part_parsers) {
	spin_lock(&part_parser_lock);
		struct mtd_part_parser *p = list_entry(this, struct mtd_part_parser, list);


	list_for_each_entry(p, &part_parsers, list)
		if (!strcmp(p->name, name) && try_module_get(p->owner)) {
		if (!strcmp(p->name, name) && try_module_get(p->owner)) {
			ret = p;
			ret = p;
			break;
			break;
		}
		}
	}

	spin_unlock(&part_parser_lock);
	spin_unlock(&part_parser_lock);


	return ret;
	return ret;