Skip to contentSkip to conversation

fix the conversion from dev to mtd_info

PATCH In review Saeed Bishara 2 participants 2 messages Jul 28, 2009 – Jul 30, 2009 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix the conversion from dev to mtd_info

The patch fixes a bug when converting dev to mtd_info by using the drvdata of the dev, the previous code used
container_of(dev, struct mtd_info, dev), but won't work for the mtdXro devices as they created without being contained inside mtd_info structure.

---
 drivers/mtd/mtdcore.c   |    7 ++++---
 include/linux/mtd/mtd.h |    2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/mtd/mtdcore.c +4 -3
index fac54a3..00ebf7a 100644
@@ -65,8 +65,8 @@ static void mtd_release(struct device *dev)
 static int mtd_cls_suspend(struct device *dev, pm_message_t state)
 {
 	struct mtd_info *mtd = dev_to_mtd(dev);
-	
-	if (mtd->suspend)
+
+	if (mtd && mtd->suspend)
 		return mtd->suspend(mtd);
 	else
 		return 0;
@@ -76,7 +76,7 @@ static int mtd_cls_resume(struct device *dev)
 {
 	struct mtd_info *mtd = dev_to_mtd(dev);
 	
-	if (mtd->resume)
+	if (mtd && mtd->resume)
 		mtd->resume(mtd);
 	return 0;
 }
@@ -298,6 +298,7 @@ int add_mtd_device(struct mtd_info *mtd)
 			mtd->dev.class = &mtd_class;
 			mtd->dev.devt = MTD_DEVT(i);
 			dev_set_name(&mtd->dev, "mtd%d", i);
+			dev_set_drvdata(&mtd->dev, mtd);
 			if (device_register(&mtd->dev) != 0) {
 				mtd_table[i] = NULL;
 				break;
include/linux/mtd/mtd.h +1 -1
index 5675b63..0f32a9b 100644
@@ -251,7 +251,7 @@ struct mtd_info {
 
 static inline struct mtd_info *dev_to_mtd(struct device *dev)
 {
-	return dev ? container_of(dev, struct mtd_info, dev) : NULL;
+	return dev ? dev_get_drvdata(dev) : NULL;
 }
 
 static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
Signature · 1 line
1.6.0.4
#1 lore raw

ping?

Quoted 65 lines · Saeed Bishara

The patch fixes a bug when converting dev to mtd_info by using the drvdata of the dev, the previous code used
container_of(dev, struct mtd_info, dev), but won't work for the mtdXro devices as they created without being contained inside mtd_info structure.

---
 drivers/mtd/mtdcore.c   |    7 ++++---
 include/linux/mtd/mtd.h |    2 +-

 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/mtd/mtdcore.c +2 -2
index fac54a3..00ebf7a 100644
@@ -65,8 +65,8 @@ static void mtd_release(struct device *dev)
  static int mtd_cls_suspend(struct device *dev, pm_message_t state)
  {
        struct mtd_info *mtd = dev_to_mtd(dev);
-
-       if (mtd->suspend)
+
+       if (mtd && mtd->suspend)
                return mtd->suspend(mtd);

       else
               return 0;

drivers/mtd/mtdcore.c +2 -1
@@ -76,7 +76,7 @@ static int mtd_cls_resume(struct device *dev)
  {
        struct mtd_info *mtd = dev_to_mtd(dev);
 
-       if (mtd->resume)
+       if (mtd && mtd->resume)
                mtd->resume(mtd);
        return 0;
  }
@@ -298,6 +298,7 @@ int add_mtd_device(struct mtd_info *mtd)
                        mtd->dev.class = &mtd_class;
                        mtd->dev.devt = MTD_DEVT(i);
                        dev_set_name(&mtd->dev, "mtd%d", i);
+                       dev_set_drvdata(&mtd->dev, mtd);
                        if (device_register(&mtd->dev) != 0) {
                                mtd_table[i] = NULL;
                                break;
include/linux/mtd/mtd.h +1 -2
index 5675b63..0f32a9b 100644
@@ -251,7 +251,7 @@ struct mtd_info {
 
  static inline struct mtd_info *dev_to_mtd(struct device *dev)
  {
-       return dev ? container_of(dev, struct mtd_info, dev) : NULL;
+       return dev ? dev_get_drvdata(dev) : NULL;
  }
 
  static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
--

1.6.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/