Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: 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.

Signed-off-by: Saeed Bishara <saeed@marvell.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

authored by

Saeed Bishara and committed by
David Woodhouse
6afc4fdb 7699ad35

+5 -4
+4 -3
drivers/mtd/mtdcore.c
··· 65 65 static int mtd_cls_suspend(struct device *dev, pm_message_t state) 66 66 { 67 67 struct mtd_info *mtd = dev_to_mtd(dev); 68 - 69 - if (mtd->suspend) 68 + 69 + if (mtd && mtd->suspend) 70 70 return mtd->suspend(mtd); 71 71 else 72 72 return 0; ··· 76 76 { 77 77 struct mtd_info *mtd = dev_to_mtd(dev); 78 78 79 - if (mtd->resume) 79 + if (mtd && mtd->resume) 80 80 mtd->resume(mtd); 81 81 return 0; 82 82 } ··· 298 298 mtd->dev.class = &mtd_class; 299 299 mtd->dev.devt = MTD_DEVT(i); 300 300 dev_set_name(&mtd->dev, "mtd%d", i); 301 + dev_set_drvdata(&mtd->dev, mtd); 301 302 if (device_register(&mtd->dev) != 0) { 302 303 mtd_table[i] = NULL; 303 304 break;
+1 -1
include/linux/mtd/mtd.h
··· 251 251 252 252 static inline struct mtd_info *dev_to_mtd(struct device *dev) 253 253 { 254 - return dev ? container_of(dev, struct mtd_info, dev) : NULL; 254 + return dev ? dev_get_drvdata(dev) : NULL; 255 255 } 256 256 257 257 static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)