[PATCH 06/10] i2c: stm32f7: Allocate smbus_buf separately for DMA safety
Lee Jones
lee at kernel.org
Thu Dec 3 10:31:10 PST 2026
smbus_buf is embedded directly inside struct stm32f7_i2c_msg (and thus
struct stm32f7_i2c_dev), sharing a CPU cacheline with adjacent driver
state. Passing it to dma_map_single() on non-coherent ARM/ARM64 SoCs
can corrupt adjacent fields during cache invalidation or corrupt DMA
data via concurrent CPU writes.
Allocate smbus_buf separately with devm_kzalloc() during probe so it is
isolated in its own DMA-safe allocation.
Fixes: 7ecc8cfde553 ("i2c: i2c-stm32f7: Add DMA support")
Closes: https://sashiko.dev/#/bug/linux-0de0fdd3-8e61-4777-a456-ad4761a2207c
Cc: stable at vger.kernel.org
Signed-off-by: Lee Jones <lee at kernel.org>
---
drivers/i2c/busses/i2c-stm32f7.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index 1ebb2e0bc1b0..720e1d46da09 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -285,7 +285,7 @@ struct stm32f7_i2c_msg {
bool smbus;
int size;
char read_write;
- u8 smbus_buf[I2C_SMBUS_BLOCK_MAX + 3] __aligned(4);
+ u8 *smbus_buf;
};
/**
@@ -2186,6 +2186,12 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
if (!i2c_dev)
return -ENOMEM;
+ i2c_dev->f7_msg.smbus_buf = devm_kzalloc(&pdev->dev,
+ I2C_SMBUS_BLOCK_MAX + 3,
+ GFP_KERNEL);
+ if (!i2c_dev->f7_msg.smbus_buf)
+ return -ENOMEM;
+
setup = of_device_get_match_data(&pdev->dev);
if (!setup)
return dev_err_probe(&pdev->dev, -ENODEV, "Can't get device data\n");
--
2.56.1.911.g883d8bcb20-goog
More information about the linux-arm-kernel
mailing list