Commit 83208e10 authored by Michał Kępień's avatar Michał Kępień Committed by Miquel Raynal

mtdchar: use kvmalloc() for potentially large allocations

mtdchar_write_ioctl() calls kmalloc() with the 'size' argument set to
the smaller of two values: the write request's data/OOB length provided
by user space and the erase block size of the MTD device.  If the latter
is large, kmalloc() may not be able to serve such allocation requests.
Use kvmalloc() instead.  Correspondingly, replace kfree() calls with
kvfree() calls.
Suggested-by: default avatarRichard Weinberger <richard@nod.at>
Signed-off-by: default avatarMichał Kępień <kernel@kempniu.pl>
Acked-by: default avatarRichard Weinberger <richard@nod.at>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220516070601.11428-3-kernel@kempniu.pl
parent a1eda864
...@@ -623,16 +623,16 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd, ...@@ -623,16 +623,16 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd,
datbuf_len = min_t(size_t, req.len, mtd->erasesize); datbuf_len = min_t(size_t, req.len, mtd->erasesize);
if (datbuf_len > 0) { if (datbuf_len > 0) {
datbuf = kmalloc(datbuf_len, GFP_KERNEL); datbuf = kvmalloc(datbuf_len, GFP_KERNEL);
if (!datbuf) if (!datbuf)
return -ENOMEM; return -ENOMEM;
} }
oobbuf_len = min_t(size_t, req.ooblen, mtd->erasesize); oobbuf_len = min_t(size_t, req.ooblen, mtd->erasesize);
if (oobbuf_len > 0) { if (oobbuf_len > 0) {
oobbuf = kmalloc(oobbuf_len, GFP_KERNEL); oobbuf = kvmalloc(oobbuf_len, GFP_KERNEL);
if (!oobbuf) { if (!oobbuf) {
kfree(datbuf); kvfree(datbuf);
return -ENOMEM; return -ENOMEM;
} }
} }
...@@ -682,8 +682,8 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd, ...@@ -682,8 +682,8 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd,
usr_oob += ops.oobretlen; usr_oob += ops.oobretlen;
} }
kfree(datbuf); kvfree(datbuf);
kfree(oobbuf); kvfree(oobbuf);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment