* [PATCH] rtc: fix error checking in wdt_disable()
@ 2025-10-02 9:24 Alexandr Sapozhnkiov
2025-10-03 13:50 ` Markus Elfring
0 siblings, 1 reply; 2+ messages in thread
From: Alexandr Sapozhnkiov @ 2025-10-02 9:24 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Alexandr Sapozhnikov, linux-rtc, linux-kernel, lvc-project
From: Alexandr Sapozhnikov <alsp705@gmail.com>
The i2c_transfer() function may return an error.
Ignoring errors returned by functions is bad practice.
Especially when these functions perform core functionality.
What's the point of continuing to call the same function
after an error is returned?
If the second function call succeeds, data corruption will occur.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Alexandr Sapozhnikov <alsp705@gmail.com>
---
drivers/rtc/rtc-m41t80.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 0013bff0447d..b24d09c57816 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -677,11 +677,11 @@ static void wdt_disable(void)
};
i2c_data[0] = 0x09;
- i2c_transfer(save_client->adapter, msgs0, 2);
-
- i2c_data[0] = 0x09;
- i2c_data[1] = 0x00;
- i2c_transfer(save_client->adapter, msgs1, 1);
+ if (!i2c_transfer(save_client->adapter, msgs0, 2)) {
+ i2c_data[0] = 0x09;
+ i2c_data[1] = 0x00;
+ i2c_transfer(save_client->adapter, msgs1, 1);
+ }
}
/**
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] rtc: fix error checking in wdt_disable()
2025-10-02 9:24 [PATCH] rtc: fix error checking in wdt_disable() Alexandr Sapozhnkiov
@ 2025-10-03 13:50 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2025-10-03 13:50 UTC (permalink / raw)
To: Alexandr Sapozhnikov, linux-rtc, lvc-project; +Cc: LKML, Alexandre Belloni
> The i2c_transfer() function may return an error.
> Ignoring errors returned by functions is bad practice.
See also:
https://cwe.mitre.org/data/definitions/252.html
…
> If the second function call succeeds, data corruption will occur.
Should the function return values be checked for both passed messages?
* Would a corresponding imperative wording become helpful for an improved change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17#n94
* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
Regards,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-03 13:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-02 9:24 [PATCH] rtc: fix error checking in wdt_disable() Alexandr Sapozhnkiov
2025-10-03 13:50 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox