]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
auxdisplay: lcd2s: add error handling for i2c transfers
authorWang Jun <1742789905@qq.com>
Thu, 12 Mar 2026 14:51:36 +0000 (22:51 +0800)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 13 Mar 2026 10:00:06 +0000 (11:00 +0100)
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.

Signed-off-by: Wang Jun <1742789905@qq.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/auxdisplay/lcd2s.c

index defb0573e43c694bb0da1b8c771bc1ea9c588dbd..c7a9627287524508535c09641e3a122d88f07b59 100644 (file)
@@ -99,8 +99,13 @@ 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));
+       ret = lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
+       if (ret < 0)
+               return ret;
+       if (ret != sizeof(buf))
+               return -EIO;
        return 0;
 }
 
@@ -108,9 +113,13 @@ 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));
-
+       ret = lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
+       if (ret < 0)
+               return ret;
+       if (ret != sizeof(buf))
+               return -EIO;
        return 0;
 }