Skip to content

Commit 6afc4fd

Browse files
Saeed BisharaDavid Woodhouse
authored andcommitted
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>
1 parent 7699ad3 commit 6afc4fd

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎drivers/mtd/mtdcore.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ static void mtd_release(struct device *dev)
6565
static int mtd_cls_suspend(struct device *dev, pm_message_t state)
6666
{
6767
struct mtd_info *mtd = dev_to_mtd(dev);
68-
69-
if (mtd->suspend)
68+
69+
if (mtd && mtd->suspend)
7070
return mtd->suspend(mtd);
7171
else
7272
return 0;
@@ -76,7 +76,7 @@ static int mtd_cls_resume(struct device *dev)
7676
{
7777
struct mtd_info *mtd = dev_to_mtd(dev);
7878

79-
if (mtd->resume)
79+
if (mtd && mtd->resume)
8080
mtd->resume(mtd);
8181
return 0;
8282
}
@@ -298,6 +298,7 @@ int add_mtd_device(struct mtd_info *mtd)
298298
mtd->dev.class = &mtd_class;
299299
mtd->dev.devt = MTD_DEVT(i);
300300
dev_set_name(&mtd->dev, "mtd%d", i);
301+
dev_set_drvdata(&mtd->dev, mtd);
301302
if (device_register(&mtd->dev) != 0) {
302303
mtd_table[i] = NULL;
303304
break;

‎include/linux/mtd/mtd.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ struct mtd_info {
251251

252252
static inline struct mtd_info *dev_to_mtd(struct device *dev)
253253
{
254-
return dev ? container_of(dev, struct mtd_info, dev) : NULL;
254+
return dev ? dev_get_drvdata(dev) : NULL;
255255
}
256256

257257
static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)

0 commit comments

Comments
 (0)