[B/C] [PATCH 6/8] i2c: add extra check to safe DMA buffer helper
Kai-Heng Feng
kai.heng.feng at canonical.com
Thu Apr 25 04:43:35 UTC 2019
BugLink: https://bugs.launchpad.net/bugs/1787775
From: Wolfram Sang <wsa+renesas at sang-engineering.com>
Make sure we report 'no buffer' for 0-length messages. This can only
happen if threshold is set to 0 which is kind of bogus but we should
still handle this situation. Update the docs and add a debug message
to educate callers of this function.
Reported-by: Hsin-Yi Wang <hsinyi at chromium.org>
Fixes: e94bc5d18be0 ("i2c: add helpers to ease DMA handling")
Signed-off-by: Wolfram Sang <wsa+renesas at sang-engineering.com>
Reviewed-by: Hsin-Yi Wang <hsinyi at chromium.org>
Signed-off-by: Wolfram Sang <wsa at the-dreams.de>
(cherry picked from commit bf263c35b2ebe7f1674205f6b36487250299b5a7)
Signed-off-by: Kai-Heng Feng <kai.heng.feng at canonical.com>
---
drivers/i2c/i2c-core-base.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index b6d3dcb62992..16072efec762 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -2268,7 +2268,8 @@ EXPORT_SYMBOL(i2c_put_adapter);
/**
* i2c_get_dma_safe_msg_buf() - get a DMA safe buffer for the given i2c_msg
* @msg: the message to be checked
- * @threshold: the minimum number of bytes for which using DMA makes sense
+ * @threshold: the minimum number of bytes for which using DMA makes sense.
+ * Should at least be 1.
*
* Return: NULL if a DMA safe buffer was not obtained. Use msg->buf with PIO.
* Or a valid pointer to be used with DMA. After use, release it by
@@ -2278,7 +2279,11 @@ EXPORT_SYMBOL(i2c_put_adapter);
*/
u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
{
- if (msg->len < threshold)
+ /* also skip 0-length msgs for bogus thresholds of 0 */
+ if (!threshold)
+ pr_debug("DMA buffer for addr=0x%02x with length 0 is bogus\n",
+ msg->addr);
+ if (msg->len < threshold || msg->len == 0)
return NULL;
if (msg->flags & I2C_M_DMA_SAFE)
--
2.17.1
More information about the kernel-team
mailing list