All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc: m41t80: Check failure of i2c_transfer
@ 2021-12-23 10:10 Jiasheng Jiang
  0 siblings, 0 replies; only message in thread
From: Jiasheng Jiang @ 2021-12-23 10:10 UTC (permalink / raw)
  To: a.zummo, alexandre.belloni; +Cc: linux-rtc, linux-kernel, Jiasheng Jiang

Because the i2c_transfer could be failure and return nagative code or
other number but not the right number of messages executed.
Therefore, it should be better to check the return value and deal with
it.
This time, for the sake of convenience, I only fix one as an example.
If the patch is right, I will submit a new version including others,
like wdt_disable().

Fixes: 617780d290bd ("rtc: watchdog support for rtc-m41t80 driver")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/rtc/rtc-m41t80.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 89128fc29ccc..1efb689dc6a6 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -604,8 +604,9 @@ static int boot_flag;
  *	Reload counter one with the watchdog timeout. We don't bother reloading
  *	the cascade counter.
  */
-static void wdt_ping(void)
+static int wdt_ping(void)
 {
+	int ret;
 	unsigned char i2c_data[2];
 	struct i2c_msg msgs1[1] = {
 		{
@@ -634,7 +635,12 @@ static void wdt_ping(void)
 	if (clientdata->features & M41T80_FEATURE_WD)
 		i2c_data[1] &= ~M41T80_WATCHDOG_RB2;
 
-	i2c_transfer(save_client->adapter, msgs1, 1);
+	ret = i2c_transfer(save_client->adapter, msgs1, 1);
+	if (ret == 1)
+		return 0;
+	if (ret < 0)
+		return ret;
+	return -EIO;
 }
 
 /**
@@ -689,8 +695,12 @@ static void wdt_disable(void)
 static ssize_t wdt_write(struct file *file, const char __user *buf,
 			 size_t count, loff_t *ppos)
 {
+	int ret;
 	if (count) {
-		wdt_ping();
+		ret = wdt_ping();
+		if (ret)
+			return 0;
+
 		return 1;
 	}
 	return 0;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-23 10:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-23 10:10 [PATCH] rtc: m41t80: Check failure of i2c_transfer Jiasheng Jiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.