diff options
author | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2019-03-05 18:54:32 +0100 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2019-03-20 18:18:54 +0100 |
commit | ed5a81046bf7a1b665eb5bf178c4139503f4637e (patch) | |
tree | cb76317b5676c2fa504d755193ac8783a12364cf /drivers | |
parent | 0d7350316a2a773254cd261daa8d3f2c4dd38610 (diff) | |
download | linux-ed5a81046bf7a1b665eb5bf178c4139503f4637e.tar.bz2 |
i2c: rcar: sanity check for minimal DMA length
Use a macro for the hardcoded value and apply a build check. If it is
not met, the driver logic will not work anymore.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/i2c/busses/i2c-rcar.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index a7578f6da979..57083e91f2cf 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -85,6 +85,7 @@ /* ICFBSCR */ #define TCYC17 0x0f /* 17*Tcyc delay 1st bit between SDA and SCL */ +#define RCAR_MIN_DMA_LEN 8 #define RCAR_BUS_PHASE_START (MDBS | MIE | ESG) #define RCAR_BUS_PHASE_DATA (MDBS | MIE) @@ -412,8 +413,8 @@ static void rcar_i2c_dma(struct rcar_i2c_priv *priv) int len; /* Do various checks to see if DMA is feasible at all */ - if (IS_ERR(chan) || msg->len < 8 || !(msg->flags & I2C_M_DMA_SAFE) || - (read && priv->flags & ID_P_NO_RXDMA)) + if (IS_ERR(chan) || msg->len < RCAR_MIN_DMA_LEN || + !(msg->flags & I2C_M_DMA_SAFE) || (read && priv->flags & ID_P_NO_RXDMA)) return; if (read) { @@ -921,6 +922,9 @@ static int rcar_i2c_probe(struct platform_device *pdev) struct i2c_timings i2c_t; int irq, ret; + /* Otherwise logic will break because some bytes must always use PIO */ + BUILD_BUG_ON_MSG(RCAR_MIN_DMA_LEN < 3, "Invalid min DMA length"); + priv = devm_kzalloc(dev, sizeof(struct rcar_i2c_priv), GFP_KERNEL); if (!priv) return -ENOMEM; |