From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 7/7] nvmem: regmap: Fix nvmem size
Date: Tue, 2 Jan 2024 18:01:00 +0100 [thread overview]
Message-ID: <20240102170100.1596372-8-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240102170100.1596372-1-a.fatoum@pengutronix.de>
From: Robin van der Gracht <robin@protonic.nl>
We should add 1 to the max_register index since counting is zero based.
i.e. the stm32mp151 bsec has registers 0 - 95 with reg_stride 4.
Size should be (95 + 1) * 4 = 384 bytes otherwise we can't access bsec
register 95 (last one).
regmap_size_bytes() does take the +1 into account so we can use that.
Fixes: b4abbd8a6cbb ("nvmem: add nvmem_regmap_register helper")
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v2 was here: https://lore.barebox.org/barebox/20240102105330.GA1318922@pengutronix.de/T/#t
v2 -> v3:
- use regmap_size_bytes() without multiplication with stride after
fixing its implementation.
---
drivers/nvmem/regmap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nvmem/regmap.c b/drivers/nvmem/regmap.c
index fa5405d7a86a..24712fbb0f33 100644
--- a/drivers/nvmem/regmap.c
+++ b/drivers/nvmem/regmap.c
@@ -38,7 +38,7 @@ static int nvmem_regmap_read(void *ctx, unsigned offset, void *buf, size_t bytes
skip_bytes = offset & (stride - 1);
rbytes = roundup(bytes + skip_bytes, stride);
- if (roffset + rbytes > stride * regmap_get_max_register(map))
+ if (roffset + rbytes > regmap_size_bytes(map))
return -EINVAL;
for (i = roffset; i < roffset + rbytes; i += stride) {
@@ -78,7 +78,7 @@ nvmem_regmap_register_with_pp(struct regmap *map, const char *name,
config.priv = map;
config.stride = 1;
config.word_size = 1;
- config.size = regmap_get_max_register(map) * regmap_get_reg_stride(map);
+ config.size = regmap_size_bytes(map);
config.cell_post_process = cell_post_process;
config.reg_write = nvmem_regmap_write;
config.reg_read = nvmem_regmap_read;
--
2.39.2
next prev parent reply other threads:[~2024-01-02 17:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-02 17:00 [PATCH master 0/7] regmap: fix size of regmap-backed cdev and nvmem Ahmad Fatoum
2024-01-02 17:00 ` [PATCH master 1/7] regmap: fix calculation of regmap size when reg_stride != 1 Ahmad Fatoum
2024-01-02 17:00 ` [PATCH master 2/7] nvmem: bsec: correct regmap's max_register Ahmad Fatoum
2024-01-08 10:29 ` Robin van der Gracht
2024-01-08 10:44 ` Ahmad Fatoum
2024-01-08 11:17 ` Robin van der Gracht
2024-01-08 12:48 ` Robin van der Gracht
2024-01-11 7:35 ` Ahmad Fatoum
2024-01-02 17:00 ` [PATCH master 3/7] nvmem: startfive-otp: " Ahmad Fatoum
2024-01-02 17:00 ` [PATCH master 4/7] nvmem: imx-ocotp-ele: " Ahmad Fatoum
2024-01-02 17:00 ` [PATCH master 5/7] nvmem: ocotp: " Ahmad Fatoum
2024-01-02 17:00 ` [PATCH master 6/7] nvmem: ocotp: align OCOTP bank count with Linux Ahmad Fatoum
2024-01-02 17:01 ` Ahmad Fatoum [this message]
2024-01-08 9:43 ` [PATCH master 0/7] regmap: fix size of regmap-backed cdev and nvmem Sascha Hauer
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=20240102170100.1596372-8-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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