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>
This commit is contained in:
committed by
David Woodhouse
parent
7699ad35ed
commit
6afc4fdb3e
@@ -66,7 +66,7 @@ static int mtd_cls_suspend(struct device *dev, pm_message_t state)
|
|||||||
{
|
{
|
||||||
struct mtd_info *mtd = dev_to_mtd(dev);
|
struct mtd_info *mtd = dev_to_mtd(dev);
|
||||||
|
|
||||||
if (mtd->suspend)
|
if (mtd && mtd->suspend)
|
||||||
return mtd->suspend(mtd);
|
return mtd->suspend(mtd);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
@@ -76,7 +76,7 @@ static int mtd_cls_resume(struct device *dev)
|
|||||||
{
|
{
|
||||||
struct mtd_info *mtd = dev_to_mtd(dev);
|
struct mtd_info *mtd = dev_to_mtd(dev);
|
||||||
|
|
||||||
if (mtd->resume)
|
if (mtd && mtd->resume)
|
||||||
mtd->resume(mtd);
|
mtd->resume(mtd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -298,6 +298,7 @@ int add_mtd_device(struct mtd_info *mtd)
|
|||||||
mtd->dev.class = &mtd_class;
|
mtd->dev.class = &mtd_class;
|
||||||
mtd->dev.devt = MTD_DEVT(i);
|
mtd->dev.devt = MTD_DEVT(i);
|
||||||
dev_set_name(&mtd->dev, "mtd%d", i);
|
dev_set_name(&mtd->dev, "mtd%d", i);
|
||||||
|
dev_set_drvdata(&mtd->dev, mtd);
|
||||||
if (device_register(&mtd->dev) != 0) {
|
if (device_register(&mtd->dev) != 0) {
|
||||||
mtd_table[i] = NULL;
|
mtd_table[i] = NULL;
|
||||||
break;
|
break;
|
||||||
|
@@ -251,7 +251,7 @@ struct mtd_info {
|
|||||||
|
|
||||||
static inline struct mtd_info *dev_to_mtd(struct device *dev)
|
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)
|
static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
|
||||||
|
Reference in New Issue
Block a user