mtd: Introduce and use iteration macro for reading the MTD device table
PATCH v2 1/7 mtd: Introduce and use iteration macro for reading the MTD device table
Signed-off-by Ben Hutchings <[email protected]>
--- drivers/mtd/mtd_blkdevs.c | 10 ++++---- drivers/mtd/mtdcore.c | 54 ++++++++++++++++++++------------------------ drivers/mtd/mtdcore.h | 15 ++++++++++++ 3 files changed, 45 insertions(+), 34 deletions(-)
drivers/mtd/mtd_blkdevs.c +5 -5
@@ -335,7 +335,8 @@ static struct mtd_notifier blktrans_notifier = {int register_mtd_blktrans (struct mtd_blktrans_ops *tr) { -int ret, i; +struct mtd_info *mtd; +int ret;/* Register the notifier if/when the first device type is registered, to prevent the link/init ordering from fucking
@@ -389,10 +390,9 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)INIT_LIST_HEAD (&tr->devs);list_add (&tr->list, &blktrans_majors); -for (i=0 ; i<MAX_MTD_DEVICES ; i++) { -if (mtd_table[i] && mtd_table[i]->type !=MTD_ABSENT ) - tr->add_mtd (tr, mtd_table[i]); - } +mtd_for_each_device (mtd) +if (mtd->type !=MTD_ABSENT ) + tr->add_mtd (tr, mtd);mutex_unlock (&mtd_table_mutex);
drivers/mtd/mtdcore.c +25 -29
114 lines not on this page · raw message
drivers/mtd/mtdcore.h +15 -0
@@ -9,3 +9,18 @@extern struct mutex mtd_table_mutex;extern struct mtd_info *mtd_table[MAX_MTD_DEVICES ]; + +static inline struct mtd_info *__mtd_next_device (int i) +{ +while (i <MAX_MTD_DEVICES ) { +if (mtd_table[i]) +return mtd_table[i]; + i++; + } +return NULL ; +} + +#define mtd_for_each_device (mtd) \ + for ((mtd) = __mtd_next_device(0); \ + (mtd) != NULL; \ + (mtd) = __mtd_next_device(mtd->index + 1))
Signature · 7 lines
1.5.5 -- Ben Hutchings, Senior Software Engineer, Solarflare Communications Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.