File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1612,15 +1612,23 @@ EXPORT_SYMBOL_GPL(nvmem_cell_put);
16121612static void nvmem_shift_read_buffer_in_place (struct nvmem_cell_entry * cell , void * buf )
16131613{
16141614 u8 * p , * b ;
1615- int i , extra , bit_offset = cell -> bit_offset ;
1615+ int i , padding , extra , bit_offset = cell -> bit_offset ;
1616+ int bytes = cell -> bytes ;
16161617
16171618 p = b = buf ;
16181619 if (bit_offset ) {
1620+ padding = bit_offset /8 ;
1621+ if (padding ) {
1622+ memmove (buf , buf + padding , bytes - padding );
1623+ bit_offset -= BITS_PER_BYTE * padding ;
1624+ bytes -= padding ;
1625+ }
1626+
16191627 /* First shift */
16201628 * b ++ >>= bit_offset ;
16211629
16221630 /* setup rest of the bytes if any */
1623- for (i = 1 ; i < cell -> bytes ; i ++ ) {
1631+ for (i = 1 ; i < bytes ; i ++ ) {
16241632 /* Get bits from next byte and shift them towards msb */
16251633 * p |= * b << (BITS_PER_BYTE - bit_offset );
16261634
@@ -1633,7 +1641,7 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
16331641 }
16341642
16351643 /* result fits in less bytes */
1636- extra = cell -> bytes - DIV_ROUND_UP (cell -> nbits , BITS_PER_BYTE );
1644+ extra = bytes - DIV_ROUND_UP (cell -> nbits , BITS_PER_BYTE );
16371645 while (-- extra >= 0 )
16381646 * p -- = 0 ;
16391647
You can’t perform that action at this time.
0 commit comments