File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1622,15 +1622,23 @@ EXPORT_SYMBOL_GPL(nvmem_cell_put);
16221622static void nvmem_shift_read_buffer_in_place (struct nvmem_cell_entry * cell , void * buf )
16231623{
16241624 u8 * p , * b ;
1625- int i , extra , bit_offset = cell -> bit_offset ;
1625+ int i , padding , extra , bit_offset = cell -> bit_offset ;
1626+ int bytes = cell -> bytes ;
16261627
16271628 p = b = buf ;
16281629 if (bit_offset ) {
1630+ padding = bit_offset /8 ;
1631+ if (padding ) {
1632+ memmove (buf , buf + padding , bytes - padding );
1633+ bit_offset -= BITS_PER_BYTE * padding ;
1634+ bytes -= padding ;
1635+ }
1636+
16291637 /* First shift */
16301638 * b ++ >>= bit_offset ;
16311639
16321640 /* setup rest of the bytes if any */
1633- for (i = 1 ; i < cell -> bytes ; i ++ ) {
1641+ for (i = 1 ; i < bytes ; i ++ ) {
16341642 /* Get bits from next byte and shift them towards msb */
16351643 * p |= * b << (BITS_PER_BYTE - bit_offset );
16361644
@@ -1643,7 +1651,7 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
16431651 }
16441652
16451653 /* result fits in less bytes */
1646- extra = cell -> bytes - DIV_ROUND_UP (cell -> nbits , BITS_PER_BYTE );
1654+ extra = bytes - DIV_ROUND_UP (cell -> nbits , BITS_PER_BYTE );
16471655 while (-- extra >= 0 )
16481656 * p -- = 0 ;
16491657
You can’t perform that action at this time.
0 commit comments