Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Akhil P Oommen <quic_akhilpo@quicinc.com>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: <linux-arm-msm@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Subject: Re: [PATCH v3 1/5] nvmem: core: fix bit offsets of more than one byte
Date: Thu, 9 Jan 2025 03:17:08 +0530	[thread overview]
Message-ID: <ae7f2d05-df0a-42e5-9e2e-586c35e5754d@quicinc.com> (raw)
In-Reply-To: <20250104-sar2130p-nvmem-v3-1-a94e0b7de2fa@linaro.org>

On 1/4/2025 11:49 AM, Dmitry Baryshkov wrote:
> If the NVMEM specifies a stride to access data, reading particular cell
> might require bit offset that is bigger than one byte. Rework NVMEM core
> code to support bit offsets of more than 8 bits.
> 
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
>  drivers/nvmem/core.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index d6494dfc20a7324bde6415776dcabbb0bfdd334b..c0af43a37195c3869507a203b370615309aeee67 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -834,7 +834,9 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod
>  		if (addr && len == (2 * sizeof(u32))) {
>  			info.bit_offset = be32_to_cpup(addr++);
>  			info.nbits = be32_to_cpup(addr);
> -			if (info.bit_offset >= BITS_PER_BYTE || info.nbits < 1) {
> +			if (info.bit_offset >= BITS_PER_BYTE * info.bytes ||
> +			    info.nbits < 1 ||
> +			    info.bit_offset + info.nbits >= BITS_PER_BYTE * info.bytes) {

Should it be ">" check instead of ">=" check here?
For eg: bit_offset = 7, nbits = 1 and info.bytes = 1 is valid, isn't it?

-Akhil

>  				dev_err(dev, "nvmem: invalid bits on %pOF\n", child);
>  				of_node_put(child);
>  				return -EINVAL;
> @@ -1627,21 +1629,29 @@ EXPORT_SYMBOL_GPL(nvmem_cell_put);
>  static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void *buf)
>  {
>  	u8 *p, *b;
> -	int i, extra, bit_offset = cell->bit_offset;
> +	int i, extra, bytes_offset;
> +	int bit_offset = cell->bit_offset;
>  
>  	p = b = buf;
> -	if (bit_offset) {
> +
> +	bytes_offset = bit_offset / BITS_PER_BYTE;
> +	b += bytes_offset;
> +	bit_offset %= BITS_PER_BYTE;
> +
> +	if (bit_offset % BITS_PER_BYTE) {
>  		/* First shift */
> -		*b++ >>= bit_offset;
> +		*p = *b++ >> bit_offset;
>  
>  		/* setup rest of the bytes if any */
>  		for (i = 1; i < cell->bytes; i++) {
>  			/* Get bits from next byte and shift them towards msb */
> -			*p |= *b << (BITS_PER_BYTE - bit_offset);
> +			*p++ |= *b << (BITS_PER_BYTE - bit_offset);
>  
> -			p = b;
> -			*b++ >>= bit_offset;
> +			*p = *b++ >> bit_offset;
>  		}
> +	} else if (p != b) {
> +		memmove(p, b, cell->bytes - bytes_offset);
> +		p += cell->bytes - 1;
>  	} else {
>  		/* point to the msb */
>  		p += cell->bytes - 1;
> 


  reply	other threads:[~2025-01-08 21:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-04  6:19 [PATCH v3 0/5] nvmem: qfprom: add Qualcomm SAR2130P support Dmitry Baryshkov
2025-01-04  6:19 ` [PATCH v3 1/5] nvmem: core: fix bit offsets of more than one byte Dmitry Baryshkov
2025-01-08 21:47   ` Akhil P Oommen [this message]
2025-01-09  4:30     ` Dmitry Baryshkov
2025-01-04  6:19 ` [PATCH v3 2/5] nvmem: core: verify cell's raw_len Dmitry Baryshkov
2025-01-04  6:19 ` [PATCH v3 3/5] nvmem: core: update raw_len if the bit reading is required Dmitry Baryshkov
2025-01-04  6:19 ` [PATCH v3 4/5] nvmem: qfprom: switch to 4-byte aligned reads Dmitry Baryshkov
2025-01-04  6:19 ` [PATCH v3 5/5] dt-bindings: nvmem: qcom,qfprom: Add SAR2130P compatible Dmitry Baryshkov
2025-01-07 15:14   ` Rob Herring (Arm)

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=ae7f2d05-df0a-42e5-9e2e-586c35e5754d@quicinc.com \
    --to=quic_akhilpo@quicinc.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@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