From: Wang Jun <1742789905@qq.com>
To: Andy Shevchenko <andy@kernel.org>,
Geert Uytterhoeven <geert@linux-m68k.org>
Cc: linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
gszhai@bjtu.edu.cn, 25125332@bjtu.edu.cn, 25125283@bjtu.edu.cn,
23120469@bjtu.edu.cn, Wang Jun <1742789905@qq.com>
Subject: [PATCH] auxdisplay: lcd2s: add error handling for i2c transfers
Date: Tue, 10 Mar 2026 10:02:16 +0800 [thread overview]
Message-ID: <tencent_85C7A0061F0836B2AECE0B54977509DCEF06@qq.com> (raw)
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
next reply other threads:[~2026-03-10 2:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 2:02 Wang Jun [this message]
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
2026-03-10 11:13 [PATCH] " king
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_85C7A0061F0836B2AECE0B54977509DCEF06@qq.com \
--to=1742789905@qq.com \
--cc=23120469@bjtu.edu.cn \
--cc=25125283@bjtu.edu.cn \
--cc=25125332@bjtu.edu.cn \
--cc=akpm@linux-foundation.org \
--cc=andy@kernel.org \
--cc=geert@linux-m68k.org \
--cc=gszhai@bjtu.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®