Skip to content

Commit

Permalink
mtd: fix the conversion from dev to mtd_info
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Saeed Bishara authored and David Woodhouse committed Aug 3, 2009
1 parent 7699ad3 commit 6afc4fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions drivers/mtd/mtdcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/linux/mtd/mtd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6afc4fd

Please sign in to comment.