Re: [PATCH] [MTD] fix the conversion from dev to mtd_info

From: saeed bishara
Date: Thu Jul 30 2009 - 10:21:02 EST


ping?

On Tue, Jul 28, 2009 at 2:56 PM, Saeed Bishara<saeed@xxxxxxxxxxx> wrote:
> 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@xxxxxxxxxxx>
> ---
> Âdrivers/mtd/mtdcore.c  |  Â7 ++++---
> Âinclude/linux/mtd/mtd.h | Â Â2 +-
> Â2 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index fac54a3..00ebf7a 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -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;
> diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
> index 5675b63..0f32a9b 100644
> --- a/include/linux/mtd/mtd.h
> +++ b/include/linux/mtd/mtd.h
> @@ -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 majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/