Re: [PATCH] auxdisplay: lcd2s: add error handling for i2c transfers

From: Andy Shevchenko

Date: Tue Mar 10 2026 - 06:18:25 EST


On Tue, Mar 10, 2026 at 4:02 AM Wang Jun <1742789905@xxxxxx> wrote:
>
> The lcd2s_print() and lcd2s_gotoxy() functions currently ignore the
> return value of lcd2s_i2c_master_send(), which can fail. This can lead
> to silent data loss or incorrect cursor positioning.
>
> Add proper error checking: if the number of bytes sent does not match
> the expected length, return -EIO; otherwise propagate any error code
> from the I2C transfer.

> Also fix the missing return statement in lcd2s_gotoxy().

This is not correct. The return statement is there, the error checking is not.

...

> static int lcd2s_print(struct charlcd *lcd, int c)
> {
> struct lcd2s_data *lcd2s = lcd->drvdata;
> u8 buf[2] = { LCD2S_CMD_WRITE, c };
> + int ret;
>
> - lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
> - return 0;
> + ret = lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
> + if (ret == sizeof(buf))
> + return 0;
> + else if (ret < 0)
> + return ret;
> + else
> + return -EIO;

Drop redundant 'else':s and use the usual pattern, id est check for
errors first.

> }
>
> static int lcd2s_gotoxy(struct charlcd *lcd, unsigned int x, unsigned int y)
> {
> struct lcd2s_data *lcd2s = lcd->drvdata;
> u8 buf[3] = { LCD2S_CMD_CUR_POS, y + 1, x + 1 };
> + int ret;
>
> - lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
> -
> - return 0;
> + ret = lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
> + if (ret == sizeof(buf))
> + return 0;
> + else if (ret < 0)
> + return ret;
> + else
> + return -EIO;
> }

Same for above.

--
With Best Regards,
Andy Shevchenko