* [PATCH] auxdisplay: lcd2s: add error handling for i2c transfers
@ 2026-03-10 2:02 Wang Jun
2026-03-10 10:17 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Wang Jun @ 2026-03-10 2:02 UTC (permalink / raw)
To: Andy Shevchenko, Geert Uytterhoeven
Cc: linux-kernel, Andrew Morton, Randy Dunlap, gszhai, 25125332,
25125283, 23120469, Wang Jun
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().
Signed-off-by: Wang Jun <1742789905@qq.com>
---
drivers/auxdisplay/lcd2s.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/drivers/auxdisplay/lcd2s.c b/drivers/auxdisplay/lcd2s.c
index defb0573e43c..c5f79baac132 100644
--- a/drivers/auxdisplay/lcd2s.c
+++ b/drivers/auxdisplay/lcd2s.c
@@ -99,19 +99,30 @@ 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;
}
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;
}
static int lcd2s_home(struct charlcd *lcd)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] auxdisplay: lcd2s: add error handling for i2c transfers
2026-03-10 2:02 [PATCH] auxdisplay: lcd2s: add error handling for i2c transfers Wang Jun
@ 2026-03-10 10:17 ` Andy Shevchenko
2026-03-12 13:25 ` [PATCH V2] " Wang Jun
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-03-10 10:17 UTC (permalink / raw)
To: Wang Jun
Cc: Andy Shevchenko, Geert Uytterhoeven, linux-kernel, Andrew Morton,
Randy Dunlap, gszhai, 25125332, 25125283, 23120469
On Tue, Mar 10, 2026 at 4:02 AM Wang Jun <1742789905@qq.com> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH V2] auxdisplay: lcd2s: add error handling for i2c transfers
2026-03-10 10:17 ` Andy Shevchenko
@ 2026-03-12 13:25 ` Wang Jun
2026-03-12 14:24 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Wang Jun @ 2026-03-12 13:25 UTC (permalink / raw)
To: Andy Shevchenko, Andy Shevchenko, Geert Uytterhoeven
Cc: linux-kernel, Andrew Morton, Randy Dunlap, gszhai, 25125332,
25125283, 23120469, Wang Jun
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>
---
drivers/auxdisplay/lcd2s.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/auxdisplay/lcd2s.c b/drivers/auxdisplay/lcd2s.c
index defb0573e43c..9ae5f48cbd6c 100644
--- a/drivers/auxdisplay/lcd2s.c
+++ b/drivers/auxdisplay/lcd2s.c
@@ -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 };
-
- lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
-
+ int ret;
+
+ ret = lcd2s_i2c_master_send(lcd2s->i2c, buf, sizeof(buf));
+ if (ret < 0)
+ return ret;
+ if (ret != sizeof(buf))
+ return -EIO;
return 0;
}
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2] auxdisplay: lcd2s: add error handling for i2c transfers
2026-03-12 13:25 ` [PATCH V2] " Wang Jun
@ 2026-03-12 14:24 ` Andy Shevchenko
2026-03-12 14:51 ` [PATCH v3] " Wang Jun
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-03-12 14:24 UTC (permalink / raw)
To: Wang Jun
Cc: Andy Shevchenko, Andy Shevchenko, Geert Uytterhoeven,
linux-kernel, Andrew Morton, Randy Dunlap, gszhai, 25125332,
25125283, 23120469
On Thu, Mar 12, 2026 at 09:25:02PM +0800, Wang Jun 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.
Why?
Where is the changelog if it's a v2?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3] auxdisplay: lcd2s: add error handling for i2c transfers
2026-03-12 14:24 ` Andy Shevchenko
@ 2026-03-12 14:51 ` Wang Jun
2026-03-13 10:02 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Wang Jun @ 2026-03-12 14:51 UTC (permalink / raw)
To: Andy Shevchenko, Andy Shevchenko, Geert Uytterhoeven
Cc: linux-kernel, Andrew Morton, Randy Dunlap, gszhai, 25125332,
25125283, 23120469, Wang Jun
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>
---
v3:
- Added changelog for v2 (pointed out by Andy)
- No code changes from v2
v2:
- Simplified error handling (removed redundant else) per Andy's suggestion
drivers/auxdisplay/lcd2s.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/auxdisplay/lcd2s.c b/drivers/auxdisplay/lcd2s.c
index defb0573e43c..c7a962728752 100644
--- a/drivers/auxdisplay/lcd2s.c
+++ b/drivers/auxdisplay/lcd2s.c
@@ -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;
}
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] auxdisplay: lcd2s: add error handling for i2c transfers
2026-03-12 14:51 ` [PATCH v3] " Wang Jun
@ 2026-03-13 10:02 ` Andy Shevchenko
0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-03-13 10:02 UTC (permalink / raw)
To: Wang Jun
Cc: Andy Shevchenko, Andy Shevchenko, Geert Uytterhoeven,
linux-kernel, Andrew Morton, Randy Dunlap, gszhai, 25125332,
25125283, 23120469
On Thu, Mar 12, 2026 at 10:51:36PM +0800, Wang Jun 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.
Pushed to my review and testing queue, thanks!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-13 10:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-10 2:02 [PATCH] auxdisplay: lcd2s: add error handling for i2c transfers Wang Jun
2026-03-10 10:17 ` Andy Shevchenko
2026-03-12 13:25 ` [PATCH V2] " Wang Jun
2026-03-12 14:24 ` Andy Shevchenko
2026-03-12 14:51 ` [PATCH v3] " Wang Jun
2026-03-13 10:02 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®