Skip to content

Commit 4c11451

Browse files
andy-shevgregkh
authored andcommitted
regmap: spi: Fix potential off-by-one when calculating reserved size
[ Upstream commit d4ea1d5 ] If we ever meet a hardware that uses weird register bits and padding, we may end up in off-by-one error since x/8 + y/8 might not be equal to (x + y)/8 in some cases. bits pad x/8+y/8 (x+y)/8 4..7 0..3 0 0 // x + y from 4 up to 7 4..7 4..7 0 1 // x + y from 8 up to 11 4..7 8..11 1 1 // x + y from 12 up to 15 8..15 0..7 1 1 // x + y from 8 up to 15 8..15 8..15 2 2 // x + y from 16 up to 23 Fix this by using (x+y)/8. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://msgid.link/r/[email protected] Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 54a11ce commit 4c11451

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/base/regmap/regmap-spi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ static const struct regmap_bus *regmap_get_spi_bus(struct spi_device *spi,
122122
return ERR_PTR(-ENOMEM);
123123

124124
max_msg_size = spi_max_message_size(spi);
125-
reg_reserve_size = config->reg_bits / BITS_PER_BYTE
126-
+ config->pad_bits / BITS_PER_BYTE;
125+
reg_reserve_size = (config->reg_bits + config->pad_bits) / BITS_PER_BYTE;
127126
if (max_size + reg_reserve_size > max_msg_size)
128127
max_size -= reg_reserve_size;
129128

0 commit comments

Comments
 (0)