public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] nvmem: core: update cell->bytes after shifting bits
@ 2025-09-30 14:22 Emil Renner Berthing
  2025-11-10  8:32 ` Srinivas Kandagatla
  0 siblings, 1 reply; 3+ messages in thread
From: Emil Renner Berthing @ 2025-09-30 14:22 UTC (permalink / raw)
  To: linux-kernel
  Cc: Srinivas Kandagatla, Samuel Holland, Dmitry Baryshkov,
	Greg Kroah-Hartman

When support for bit offsets of more than one byte was added it
unfortunately left the cell->bytes value at the number of bytes read
including the offset. Make sure to update it to the proper number of
meaningful bytes in the returned data.

Fixes: 7a06ef751077 ("nvmem: core: fix bit offsets of more than one byte")
Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
---
 drivers/nvmem/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 387c88c55259..5f6d22545e39 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1640,6 +1640,8 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
 	/* clear msb bits if any leftover in the last byte */
 	if (cell->nbits % BITS_PER_BYTE)
 		*p &= GENMASK((cell->nbits % BITS_PER_BYTE) - 1, 0);
+
+	cell->bytes = (p - (u8 *)buf) + 1;
 }
 
 static int __nvmem_cell_read(struct nvmem_device *nvmem,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] nvmem: core: update cell->bytes after shifting bits
  2025-09-30 14:22 [PATCH v1] nvmem: core: update cell->bytes after shifting bits Emil Renner Berthing
@ 2025-11-10  8:32 ` Srinivas Kandagatla
  2025-11-13 11:36   ` Emil Renner Berthing
  0 siblings, 1 reply; 3+ messages in thread
From: Srinivas Kandagatla @ 2025-11-10  8:32 UTC (permalink / raw)
  To: Emil Renner Berthing, linux-kernel
  Cc: Srinivas Kandagatla, Samuel Holland, Dmitry Baryshkov,
	Greg Kroah-Hartman



On 9/30/25 3:22 PM, Emil Renner Berthing wrote:
> When support for bit offsets of more than one byte was added it
> unfortunately left the cell->bytes value at the number of bytes read
> including the offset. Make sure to update it to the proper number of
> meaningful bytes in the returned data.
Sorry somehow I missed this patch.

If the number of bytes are different to the bytes that are part of cell
then the parsing code seems to have missed some cases, which is the
right place to fix.

Can you share more details on the values that you pass as part of the
cell definition.

> Fixes: 7a06ef751077 ("nvmem: core: fix bit offsets of more than one byte")

missing CC stable

> Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
> ---
>  drivers/nvmem/core.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 387c88c55259..5f6d22545e39 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -1640,6 +1640,8 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
>  	/* clear msb bits if any leftover in the last byte */
>  	if (cell->nbits % BITS_PER_BYTE)
>  		*p &= GENMASK((cell->nbits % BITS_PER_BYTE) - 1, 0);
> +
> +	cell->bytes = (p - (u8 *)buf) + 1;
cell bytes can only be updated during parsing time not during every
access time.


--srini>  }
>  
>  static int __nvmem_cell_read(struct nvmem_device *nvmem,


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] nvmem: core: update cell->bytes after shifting bits
  2025-11-10  8:32 ` Srinivas Kandagatla
@ 2025-11-13 11:36   ` Emil Renner Berthing
  0 siblings, 0 replies; 3+ messages in thread
From: Emil Renner Berthing @ 2025-11-13 11:36 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-kernel
  Cc: Samuel Holland, Dmitry Baryshkov, Greg Kroah-Hartman

Quoting Srinivas Kandagatla (2025-11-10 09:32:08)
>
>
> On 9/30/25 3:22 PM, Emil Renner Berthing wrote:
> > When support for bit offsets of more than one byte was added it
> > unfortunately left the cell->bytes value at the number of bytes read
> > including the offset. Make sure to update it to the proper number of
> > meaningful bytes in the returned data.
> Sorry somehow I missed this patch.
>
> If the number of bytes are different to the bytes that are part of cell
> then the parsing code seems to have missed some cases, which is the
> right place to fix.
>
> Can you share more details on the values that you pass as part of the
> cell definition.

Yes, the node effectively looks like this:

sid: efuse@3006000 {
        compatible = "allwinner,sun20i-d1-sid";
        reg = <0x3006000 0x1000>;
        #address-cells = <1>;
        #size-cells = <1>;

        ths_calib: ths-calib@14 {
                reg = <0x14 0x4>;
        };

        bg_trim: bg-trim@28 {
                reg = <0x28 0x4>;
                bits = <16 8>;
        };
};

/Emil

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-13 11:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-30 14:22 [PATCH v1] nvmem: core: update cell->bytes after shifting bits Emil Renner Berthing
2025-11-10  8:32 ` Srinivas Kandagatla
2025-11-13 11:36   ` Emil Renner Berthing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox