Skip to content

Commit d01c1de

Browse files
svenpeter42jannau
authored andcommitted
nvmem: allow bit offset > 8
Signed-off-by: Sven Peter <sven@svenpeter.dev>
1 parent 8e27ed3 commit d01c1de

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

drivers/nvmem/core.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,15 +1625,23 @@ EXPORT_SYMBOL_GPL(nvmem_cell_put);
16251625
static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void *buf)
16261626
{
16271627
u8 *p, *b;
1628-
int i, extra, bit_offset = cell->bit_offset;
1628+
int i, padding, extra, bit_offset = cell->bit_offset;
1629+
int bytes = cell->bytes;
16291630

16301631
p = b = buf;
16311632
if (bit_offset) {
1633+
padding = bit_offset/8;
1634+
if (padding) {
1635+
memmove(buf, buf + padding, bytes - padding);
1636+
bit_offset -= BITS_PER_BYTE * padding;
1637+
bytes -= padding;
1638+
}
1639+
16321640
/* First shift */
16331641
*b++ >>= bit_offset;
16341642

16351643
/* setup rest of the bytes if any */
1636-
for (i = 1; i < cell->bytes; i++) {
1644+
for (i = 1; i < bytes; i++) {
16371645
/* Get bits from next byte and shift them towards msb */
16381646
*p |= *b << (BITS_PER_BYTE - bit_offset);
16391647

@@ -1646,7 +1654,7 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
16461654
}
16471655

16481656
/* result fits in less bytes */
1649-
extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE);
1657+
extra = bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE);
16501658
while (--extra >= 0)
16511659
*p-- = 0;
16521660

0 commit comments

Comments
 (0)