File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1594,15 +1594,23 @@ EXPORT_SYMBOL_GPL(nvmem_cell_put);
15941594static void nvmem_shift_read_buffer_in_place (struct nvmem_cell_entry * cell , void * buf )
15951595{
15961596 u8 * p , * b ;
1597- int i , extra , bit_offset = cell -> bit_offset ;
1597+ int i , padding , extra , bit_offset = cell -> bit_offset ;
1598+ int bytes = cell -> bytes ;
15981599
15991600 p = b = buf ;
16001601 if (bit_offset ) {
1602+ padding = bit_offset /8 ;
1603+ if (padding ) {
1604+ memmove (buf , buf + padding , bytes - padding );
1605+ bit_offset -= BITS_PER_BYTE * padding ;
1606+ bytes -= padding ;
1607+ }
1608+
16011609 /* First shift */
16021610 * b ++ >>= bit_offset ;
16031611
16041612 /* setup rest of the bytes if any */
1605- for (i = 1 ; i < cell -> bytes ; i ++ ) {
1613+ for (i = 1 ; i < bytes ; i ++ ) {
16061614 /* Get bits from next byte and shift them towards msb */
16071615 * p |= * b << (BITS_PER_BYTE - bit_offset );
16081616
@@ -1615,7 +1623,7 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
16151623 }
16161624
16171625 /* result fits in less bytes */
1618- extra = cell -> bytes - DIV_ROUND_UP (cell -> nbits , BITS_PER_BYTE );
1626+ extra = bytes - DIV_ROUND_UP (cell -> nbits , BITS_PER_BYTE );
16191627 while (-- extra >= 0 )
16201628 * p -- = 0 ;
16211629
You can’t perform that action at this time.
0 commit comments