Skip to content

Commit bf263c3

Browse files
Wolfram SangWolfram Sang
authored andcommitted
i2c: add extra check to safe DMA buffer helper
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@chromium.org> Fixes: e94bc5d ("i2c: add helpers to ease DMA handling") Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Hsin-Yi Wang <hsinyi@chromium.org> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
1 parent c86da50 commit bf263c3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,8 @@ EXPORT_SYMBOL(i2c_put_adapter);
22582258
/**
22592259
* i2c_get_dma_safe_msg_buf() - get a DMA safe buffer for the given i2c_msg
22602260
* @msg: the message to be checked
2261-
* @threshold: the minimum number of bytes for which using DMA makes sense
2261+
* @threshold: the minimum number of bytes for which using DMA makes sense.
2262+
* Should at least be 1.
22622263
*
22632264
* Return: NULL if a DMA safe buffer was not obtained. Use msg->buf with PIO.
22642265
* Or a valid pointer to be used with DMA. After use, release it by
@@ -2268,7 +2269,11 @@ EXPORT_SYMBOL(i2c_put_adapter);
22682269
*/
22692270
u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
22702271
{
2271-
if (msg->len < threshold)
2272+
/* also skip 0-length msgs for bogus thresholds of 0 */
2273+
if (!threshold)
2274+
pr_debug("DMA buffer for addr=0x%02x with length 0 is bogus\n",
2275+
msg->addr);
2276+
if (msg->len < threshold || msg->len == 0)
22722277
return NULL;
22732278

22742279
if (msg->flags & I2C_M_DMA_SAFE)

0 commit comments

Comments
 (0)