Skip to content

Commit 83208e1

Browse files
kempniumiquelraynal
authored andcommitted
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: Richard Weinberger <richard@nod.at> Signed-off-by: Michał Kępień <kernel@kempniu.pl> Acked-by: Richard Weinberger <richard@nod.at> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20220516070601.11428-3-kernel@kempniu.pl
1 parent a1eda86 commit 83208e1

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

drivers/mtd/mtdchar.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,16 +623,16 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd,
623623

624624
datbuf_len = min_t(size_t, req.len, mtd->erasesize);
625625
if (datbuf_len > 0) {
626-
datbuf = kmalloc(datbuf_len, GFP_KERNEL);
626+
datbuf = kvmalloc(datbuf_len, GFP_KERNEL);
627627
if (!datbuf)
628628
return -ENOMEM;
629629
}
630630

631631
oobbuf_len = min_t(size_t, req.ooblen, mtd->erasesize);
632632
if (oobbuf_len > 0) {
633-
oobbuf = kmalloc(oobbuf_len, GFP_KERNEL);
633+
oobbuf = kvmalloc(oobbuf_len, GFP_KERNEL);
634634
if (!oobbuf) {
635-
kfree(datbuf);
635+
kvfree(datbuf);
636636
return -ENOMEM;
637637
}
638638
}
@@ -682,8 +682,8 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd,
682682
usr_oob += ops.oobretlen;
683683
}
684684

685-
kfree(datbuf);
686-
kfree(oobbuf);
685+
kvfree(datbuf);
686+
kvfree(oobbuf);
687687

688688
return ret;
689689
}

0 commit comments

Comments
 (0)