From: Sven Peter <sven@svenpeter.dev>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Sven Peter <sven@svenpeter.dev>, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] nvmem: Handle reading nbits from cells with word_size > 8 correctly
Date: Sat, 12 Nov 2022 13:04:47 +0100 [thread overview]
Message-ID: <20221112120447.36877-2-sven@svenpeter.dev> (raw)
In-Reply-To: <20221112120447.36877-1-sven@svenpeter.dev>
Some nvmem controllers like Apple's eFuses or Nintendo's OTP have a cell
word size that's larger than one byte and cannot read anything smaller.
Round up cell->bytes correctly when accessing a subset of bits.
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
drivers/nvmem/core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index a5b8d6989f8e..6906de15b9b8 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -470,8 +470,8 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
cell->np = info->np;
if (cell->nbits)
- cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
- BITS_PER_BYTE);
+ cell->bytes = round_up(DIV_ROUND_UP(cell->nbits + cell->bit_offset,
+ BITS_PER_BYTE), nvmem->word_size);
if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
dev_err(&nvmem->dev,
@@ -718,9 +718,9 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
}
if (cell->nbits)
- cell->bytes = DIV_ROUND_UP(
+ cell->bytes = round_up(DIV_ROUND_UP(
cell->nbits + cell->bit_offset,
- BITS_PER_BYTE);
+ BITS_PER_BYTE), nvmem->word_size);
if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
dev_err(dev, "cell %s unaligned to nvmem stride %d\n",
--
2.25.1
prev parent reply other threads:[~2022-11-12 12:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-12 12:04 [PATCH 1/2] nvmem: Handle reading cells with bit offset > 8 Sven Peter
2022-11-12 12:04 ` Sven Peter [this message]
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=20221112120447.36877-2-sven@svenpeter.dev \
--to=sven@svenpeter.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivas.kandagatla@linaro.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
all inboxes | Powered by JetHome®