Patch "regmap: spi: Fix potential off-by-one when calculating reserved size" has been added to the 6.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    regmap: spi: Fix potential off-by-one when calculating reserved size

to the 6.6-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     regmap-spi-fix-potential-off-by-one-when-calculating.patch
and it can be found in the queue-6.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 2355b64dd1be6ff91b809fc882e9cb5026ce111e
Author: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>
Date:   Wed Jun 5 23:53:15 2024 +0300

    regmap: spi: Fix potential off-by-one when calculating reserved size
    
    [ Upstream commit d4ea1d504d2701ba04412f98dc00d45a104c52ab ]
    
    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@xxxxxxxxx>
    Link: https://msgid.link/r/20240605205315.19132-1-andy.shevchenko@xxxxxxxxx
    Signed-off-by: Mark Brown <broonie@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c
index 37ab23a9d034..7f14c5ed1e22 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;
 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux