Re: [PATCH] i2c: add extra check to safe DMA buffer helper

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

 



On Sat, Mar 9, 2019 at 6:54 PM Wolfram Sang
<wsa+renesas@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> 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
> handle this situation nonetheless.
>
> Reported-by: Hsin-Yi Wang <hsinyi@xxxxxxxxxxxx>
> Fixes: e94bc5d18be0 ("i2c: add helpers to ease DMA handling")
> Signed-off-by: Wolfram Sang <wsa+renesas@xxxxxxxxxxxxxxxxxxxx>
> ---
>  drivers/i2c/i2c-core-base.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index cb6c5cb0df0b..22c8f38bf68c 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -2268,7 +2268,8 @@ EXPORT_SYMBOL(i2c_put_adapter);
>   */
>  u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
>  {

How about also printing some warning if threshold is zero? Since
caller might expect
that if msg->len >= threshold, they will get valid pointer. But they
will get valid pointer
if (msg->len, threshold) is (>0, 0) and NULL if (=0, 0). So warn them
that the threshold
is bogus.

> -       if (msg->len < threshold)
> +       /* also skip 0-length msgs for bogus thresholds of 0 */
> +       if (msg->len < threshold || msg->len == 0)
>                 return NULL;
>
>         if (msg->flags & I2C_M_DMA_SAFE)
> --
> 2.19.1
>



[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux