[RESEND PATCH 3/3] mtd/mtdblock: introduce helper macro blktrans_dev_to_mtdblk to wrap the conversion (mtd_blktrans_dev to mtdblk_dev)

Gu Zheng guz.fnst at cn.fujitsu.com
Tue Dec 2 18:20:21 PST 2014


Introduce helper macro blktrans_dev_to_mtdblk to wrap the conversion
(mtd_blktrans_dev to mtdblk_dev), just cleanup.

Signed-off-by: Gu Zheng <guz.fnst at cn.fujitsu.com>
---
 drivers/mtd/mtdblock.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index acc00f1..3af3d1c 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -50,6 +50,8 @@ struct mtdblk_dev {
 	enum CACHE_STATES cache_state;
 };
 
+#define blktrans_dev_to_mtdblk(dev) container_of(dev, struct mtdblk_dev, mbd)
+
 /*
  * Cache stuff...
  *
@@ -263,14 +265,16 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
 static int mtdblock_readsect(struct mtd_blktrans_dev *dev,
 			      unsigned long block, char *buf)
 {
-	struct mtdblk_dev *mtdblk = container_of(dev, struct mtdblk_dev, mbd);
+	struct mtdblk_dev *mtdblk = blktrans_dev_to_mtdblk(dev);
+
 	return do_cached_read(mtdblk, block<<9, 512, buf);
 }
 
 static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
 			      unsigned long block, char *buf)
 {
-	struct mtdblk_dev *mtdblk = container_of(dev, struct mtdblk_dev, mbd);
+	struct mtdblk_dev *mtdblk = blktrans_dev_to_mtdblk(dev);
+
 	if (unlikely(!mtdblk->cache_data && mtdblk->cache_size)) {
 		mtdblk->cache_data = vmalloc(mtdblk->mbd.mtd->erasesize);
 		if (!mtdblk->cache_data)
@@ -285,7 +289,7 @@ static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
 
 static int mtdblock_open(struct mtd_blktrans_dev *mbd)
 {
-	struct mtdblk_dev *mtdblk = container_of(mbd, struct mtdblk_dev, mbd);
+	struct mtdblk_dev *mtdblk = blktrans_dev_to_mtdblk(mbd);
 
 	pr_debug("mtdblock_open\n");
 
@@ -310,7 +314,7 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
 
 static void mtdblock_release(struct mtd_blktrans_dev *mbd)
 {
-	struct mtdblk_dev *mtdblk = container_of(mbd, struct mtdblk_dev, mbd);
+	struct mtdblk_dev *mtdblk = blktrans_dev_to_mtdblk(mbd);
 
 	pr_debug("mtdblock_release\n");
 
@@ -333,7 +337,7 @@ static void mtdblock_release(struct mtd_blktrans_dev *mbd)
 
 static int mtdblock_flush(struct mtd_blktrans_dev *dev)
 {
-	struct mtdblk_dev *mtdblk = container_of(dev, struct mtdblk_dev, mbd);
+	struct mtdblk_dev *mtdblk = blktrans_dev_to_mtdblk(dev);
 
 	mutex_lock(&mtdblk->cache_mutex);
 	write_cached_data(mtdblk);
-- 
1.7.7

.




More information about the linux-mtd mailing list