From: yangerkun <yangerkun@huawei.com>
To: <zhongguohua1@huawei.com>, <joern@lazybastard.org>,
<miquel.raynal@bootlin.com>, <richard@nod.at>,
<patrick@baymotion.com>, <linux-mtd@lists.infradead.org>
Cc: yangerkun@huawei.com, yi.zhang@huawei.com
Subject: [PATCH] mtd: phram: use div_u64_rem to stop overwrite len in phram_setup
Date: Wed, 30 Dec 2020 10:17:18 +0800 [thread overview]
Message-ID: <20201230021718.2043147-1-yangerkun@huawei.com> (raw)
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.
Fixes: ffad560394de ("mtd: phram: Allow the user to set the erase page size.")
Signed-off-by: yangerkun <yangerkun@huawei.com>
---
drivers/mtd/devices/phram.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index cfd170946ba4..6e72b0abcb71 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -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,9 @@ static int phram_setup(const char *val)
}
}
+ 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;
}
--
2.25.4
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next reply other threads:[~2020-12-30 2:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-30 2:17 yangerkun [this message]
2021-01-04 10:08 ` [PATCH] mtd: phram: use div_u64_rem to stop overwrite len in phram_setup Miquel Raynal
2021-01-04 10:18 ` Miquel Raynal
2021-01-25 5:48 ` yangerkun
2021-01-25 8:28 ` Miquel Raynal
2021-01-25 8:36 ` yangerkun
2021-01-25 8:53 ` Miquel Raynal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201230021718.2043147-1-yangerkun@huawei.com \
--to=yangerkun@huawei.com \
--cc=joern@lazybastard.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=patrick@baymotion.com \
--cc=richard@nod.at \
--cc=yi.zhang@huawei.com \
--cc=zhongguohua1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox