mtd: phram: use div_u64_rem to stop overwrite len in phram_setup
Subsystems (2)
PATCH v2 1/1 mtd: phram: use div_u64_rem to stop overwrite len in phram_setup
We now support user to set erase page size, and use do_div between len and erase size to determine the reasonableness for the erase size. However, do_div is a macro and will overwrite the value of len. Which results a mtd device with unexcepted size. Fix it by use div_u64_rem.
--- drivers/mtd/devices/phram.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/devices/phram.c +5 -1
@@ -222,6 +222,7 @@ static int phram_setup(const char *val)uint64_t start;uint64_t len;uint64_t erasesize =PAGE_SIZE ; +uint32_t rem;int i, ret;if (strnlen (val,sizeof (buf)) >=sizeof (buf))
@@ -263,8 +264,11 @@ static int phram_setup(const char *val) } } +if (erasesize) +div_u64_rem (len, (uint32_t )erasesize, &rem); +if (len ==0 || erasesize ==0 || erasesize > len - || erasesize >UINT_MAX ||do_div (len, (uint32_t )erasesize) !=0 ) { + || erasesize >UINT_MAX || rem) {parse_err ("illegal erasesize or len\n" ); goto error; }
Signature · 6 lines
2.25.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 7 lines · yangerkun
We now support user to set erase page size, and use
do_divbetween len and erase size to determine the reasonableness for the erase size. However,do_divis a macro and will overwrite the value of len. Which results a mtd device with unexcepted size. Fix it by usediv_u64_rem.Fixes ffad560394de ("mtd: phram: Allow the user to set the erase page size.")Signed-off-by yangerkun <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.
Miquel
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/