[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20211223101052.1283277-1-jiasheng@iscas.ac.cn>
Date: Thu, 23 Dec 2021 18:10:52 +0800
From: Jiasheng Jiang <jiasheng@...as.ac.cn>
To: a.zummo@...ertech.it, alexandre.belloni@...tlin.com
Cc: linux-rtc@...r.kernel.org, linux-kernel@...r.kernel.org,
Jiasheng Jiang <jiasheng@...as.ac.cn>
Subject: [PATCH] rtc: m41t80: Check failure of i2c_transfer
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@...as.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
Powered by blists - more mailing lists