nvmem: core: update cell->bytes after shifting bits
PATCH 1/1 nvmem: core: update cell->bytes after shifting bits
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.
--- drivers/nvmem/core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvmem/core.c +2 -0
@@ -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,
Signature · 1 line
2.43.0
Srinivas Kandagatla
maintainerQuoted 4 lines · Emil Renner Berthing
When support for bit offsets of more than one byte was added it unfortunately left the
cell->bytesvalue 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.
Quoted 1 line
Fixes 7a06ef751077 ("nvmem: core: fix bit offsets of more than one byte")
missing CC stable
Quoted 10 lines
Signed-off-by Emil Renner Berthing <[email protected]>--- drivers/nvmem/core.c | 2 ++ 1 file changed, 2 insertions(+)drivers/nvmem/core.c +0
-0
drivers/nvmem/core.c static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void · line 1644
Quoted 5 lines
drivers/nvmem/core.c +2
-0@@ -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> }
Quoted 2 lines
drivers/nvmem/core.c +0
-0static int __nvmem_cell_read(struct nvmem_device *nvmem,
Quoting Srinivas Kandagatla (2025-11-10 09:32:08)
Quoted 7 lines · Emil Renner Berthing
Quoted 4 lines
When support for bit offsets of more than one byte was added it unfortunately left the
cell->bytesvalue 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.
Quoted 8 lines
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