File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1382,15 +1382,23 @@ EXPORT_SYMBOL_GPL(nvmem_cell_put);
13821382static void nvmem_shift_read_buffer_in_place (struct nvmem_cell_entry * cell , void * buf )
13831383{
13841384 u8 * p , * b ;
1385- int i , extra , bit_offset = cell -> bit_offset ;
1385+ int i , padding , extra , bit_offset = cell -> bit_offset ;
1386+ int bytes = cell -> bytes ;
13861387
13871388 p = b = buf ;
13881389 if (bit_offset ) {
1390+ padding = bit_offset /8 ;
1391+ if (padding ) {
1392+ memmove (buf , buf + padding , bytes - padding );
1393+ bit_offset -= BITS_PER_BYTE * padding ;
1394+ bytes -= padding ;
1395+ }
1396+
13891397 /* First shift */
13901398 * b ++ >>= bit_offset ;
13911399
13921400 /* setup rest of the bytes if any */
1393- for (i = 1 ; i < cell -> bytes ; i ++ ) {
1401+ for (i = 1 ; i < bytes ; i ++ ) {
13941402 /* Get bits from next byte and shift them towards msb */
13951403 * p |= * b << (BITS_PER_BYTE - bit_offset );
13961404
@@ -1403,7 +1411,7 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
14031411 }
14041412
14051413 /* result fits in less bytes */
1406- extra = cell -> bytes - DIV_ROUND_UP (cell -> nbits , BITS_PER_BYTE );
1414+ extra = bytes - DIV_ROUND_UP (cell -> nbits , BITS_PER_BYTE );
14071415 while (-- extra >= 0 )
14081416 * p -- = 0 ;
14091417
You can’t perform that action at this time.
0 commit comments