* [PATCH v1 1/1] regmap: spi: Fix potential off-by-one when calculating reserved size
@ 2024-06-05 20:53 Andy Shevchenko
2024-06-06 16:43 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2024-06-05 20:53 UTC (permalink / raw)
To: Andy Shevchenko, linux-kernel
Cc: Mark Brown, Greg Kroah-Hartman, Rafael J. Wysocki
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 <andy.shevchenko@gmail.com>
---
drivers/base/regmap/regmap-spi.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c
index 094cf2a2ca3c..14b1d88997cb 100644
--- a/drivers/base/regmap/regmap-spi.c
+++ b/drivers/base/regmap/regmap-spi.c
@@ -122,8 +122,7 @@ static const struct regmap_bus *regmap_get_spi_bus(struct spi_device *spi,
return ERR_PTR(-ENOMEM);
max_msg_size = spi_max_message_size(spi);
- reg_reserve_size = config->reg_bits / BITS_PER_BYTE
- + config->pad_bits / BITS_PER_BYTE;
+ reg_reserve_size = (config->reg_bits + config->pad_bits) / BITS_PER_BYTE;
if (max_size + reg_reserve_size > max_msg_size)
max_size -= reg_reserve_size;
--
2.45.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v1 1/1] regmap: spi: Fix potential off-by-one when calculating reserved size
2024-06-05 20:53 [PATCH v1 1/1] regmap: spi: Fix potential off-by-one when calculating reserved size Andy Shevchenko
@ 2024-06-06 16:43 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2024-06-06 16:43 UTC (permalink / raw)
To: linux-kernel, Andy Shevchenko; +Cc: Greg Kroah-Hartman, Rafael J. Wysocki
On Wed, 05 Jun 2024 23:53:15 +0300, Andy Shevchenko wrote:
> 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
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] regmap: spi: Fix potential off-by-one when calculating reserved size
commit: d4ea1d504d2701ba04412f98dc00d45a104c52ab
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-06 16:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-05 20:53 [PATCH v1 1/1] regmap: spi: Fix potential off-by-one when calculating reserved size Andy Shevchenko
2024-06-06 16:43 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®