Skip to content

Commit 995a418

Browse files
blacksanxxandy-shev
authored andcommitted
auxdisplay: lcd2s: add error handling for i2c transfers
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>
1 parent 398c0c8 commit 995a418

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

drivers/auxdisplay/lcd2s.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,27 @@ static int lcd2s_print(struct charlcd *lcd, int c)
9999
{
100100
struct lcd2s_data *lcd2s = lcd->drvdata;
101101
u8 buf[2] = { LCD2S_CMD_WRITE, c };
102+
int ret;
102103

103-
lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
104+
ret = lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
105+
if (ret < 0)
106+
return ret;
107+
if (ret != sizeof(buf))
108+
return -EIO;
104109
return 0;
105110
}
106111

107112
static int lcd2s_gotoxy(struct charlcd *lcd, unsigned int x, unsigned int y)
108113
{
109114
struct lcd2s_data *lcd2s = lcd->drvdata;
110115
u8 buf[3] = { LCD2S_CMD_CUR_POS, y + 1, x + 1 };
116+
int ret;
111117

112-
lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
113-
118+
ret = lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
119+
if (ret < 0)
120+
return ret;
121+
if (ret != sizeof(buf))
122+
return -EIO;
114123
return 0;
115124
}
116125

0 commit comments

Comments
 (0)