Re: Question on mtd devices with zero erasesize

Boris Brezillon
2017-12-07T09:34:37Z

+David (the mtd-utils maintainer)

Hi Antonio

On Wed, 6 Dec 2017 14:28:25 +0100
Antonio Borneo <borneo.antonio@gmail.com> wrote:

> Hi,
> I have searched in the mailing list archives but didn't found such topic.
>
> In mainline kernel there are already few RAM based mtd devices; the
> concept of "erase unit" (sector or page) does not always apply to
> them.
> At least two of such devices set the field "erasesize" to zero (or,
> better, do not set it at all and left it to zero):
> - drivers/mtd/devices/ms02-nv.c
> - drivers/mtd/devices/mchp23k256.c
>
> The following is tested with mchp23k256 only.
> Of course I read zero from /sys/class/mtd/mtdX/erasesize
> The tool mdtinfo core-dumps for division by zero when it try to
> compute the number of erase units by dividing device size by
> erasesize.
>
> What would be the proper fix?

Fix mtd-utils to check if MTD_NO_ERASE is set
in /sys/class/mtd/mtdX/flags. If it's not, then the device does not
support erase, and erasesize is likely to be 0. In this case, you
should not try to divide something by erasesize.

>
> First of all, is erasesize=1 correct in this case, or for some reason
> it is better to use another value?

No it's not. We should fix the tools instead of declaring a fake
erasesize.

>
> Then, is the driver that is supposed to provide a non-zero value for erasesize?

Nope.

> Or is the mtd framework that should check the value set by the driver
> and eventually replace it with a minimum erasesize?

And No.

> Or is the userland that has to accept the zero value?

I think this is the correct answer. We'll keep drivers that were
declaring an ->erasesize of 1, just to not break existing users, but
new drivers for devices that simply don't support the erase operation
should stop implementing dummy erase methods, should set erasesize to 0
and set the MTD_NO_ERASE flag.

And of course, mtd-utils should be fixed to gracefully handle the
MTD_NO_ERASE/erasesize=0 case.

Regards,

Boris