File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1552,15 +1552,23 @@ EXPORT_SYMBOL_GPL(nvmem_cell_put);
15521552static void nvmem_shift_read_buffer_in_place (struct nvmem_cell_entry * cell , void * buf )
15531553{
15541554 u8 * p , * b ;
1555- int i , extra , bit_offset = cell -> bit_offset ;
1555+ int i , padding , extra , bit_offset = cell -> bit_offset ;
1556+ int bytes = cell -> bytes ;
15561557
15571558 p = b = buf ;
15581559 if (bit_offset ) {
1560+ padding = bit_offset /8 ;
1561+ if (padding ) {
1562+ memmove (buf , buf + padding , bytes - padding );
1563+ bit_offset -= BITS_PER_BYTE * padding ;
1564+ bytes -= padding ;
1565+ }
1566+
15591567 /* First shift */
15601568 * b ++ >>= bit_offset ;
15611569
15621570 /* setup rest of the bytes if any */
1563- for (i = 1 ; i < cell -> bytes ; i ++ ) {
1571+ for (i = 1 ; i < bytes ; i ++ ) {
15641572 /* Get bits from next byte and shift them towards msb */
15651573 * p |= * b << (BITS_PER_BYTE - bit_offset );
15661574
@@ -1573,7 +1581,7 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
15731581 }
15741582
15751583 /* result fits in less bytes */
1576- extra = cell -> bytes - DIV_ROUND_UP (cell -> nbits , BITS_PER_BYTE );
1584+ extra = bytes - DIV_ROUND_UP (cell -> nbits , BITS_PER_BYTE );
15771585 while (-- extra >= 0 )
15781586 * p -- = 0 ;
15791587
You can’t perform that action at this time.
0 commit comments