[PATCH (mtd-utils)] mtd_write: fall back to old method on ENOMEM
Brian Norris
computersforpeace at gmail.com
Mon Apr 23 02:31:50 EDT 2012
On Sun, Apr 22, 2012 at 10:45 PM, Voss, Nikolaus <N.Voss at weinmann.de> wrote:
> MEMWRITE ioctl tries to kmalloc the whole data. With usual
> eraseblock sizes of 128 KiB, on memory constrained systems
> this can easily lead to ENOMEM due to memory fragmentation
> even if there are plenty of free pages left e.g.:
>
> --------------------------------------------------------------
>
> libmtd: error!: MEMWRITE ioctl failed for eraseblock 55 (mtd6)
> error 12 (Cannot allocate memory)
> ubiformat: error!: cannot write eraseblock 55
> error 12 (Cannot allocate memory)
What version of mtd-utils are using? I don't think ubiformat should be
utilizing the MEMWRITE codepath anymore, since commit 71c76e7.
> ---
> lib/libmtd.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/lib/libmtd.c b/lib/libmtd.c
> index 9b247ae..9d24ef0 100644
> --- a/lib/libmtd.c
> +++ b/lib/libmtd.c
> @@ -1151,7 +1151,7 @@ int mtd_write(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb,
> ret = ioctl(fd, MEMWRITE, &ops);
> if (ret == 0)
> return 0;
> - else if (errno != ENOTTY && errno != EOPNOTSUPP)
> + else if (errno != ENOTTY && errno != EOPNOTSUPP && errno != ENOMEM)
> return mtd_ioctl_error(mtd, eb, "MEMWRITE");
>
> /* Fall back to old methods if necessary */
I'm not sure we want to go down the path of special cases for every
possible error; the "fall back" is because this ioctl doesn't exist on
older kernels. If MEMWRITE is causing real problems for the intended
use case (writing page data + OOB), then userspace or kernel-space
should be tweaked. But it's really not a problem AFAIK, since it's
real use is for page-at-a-time (data+OOB) writes from tools like
nandwrite.
Brian
More information about the linux-mtd
mailing list