* [PATCH] i2c: generic recovery: check SCL before SDA
@ 2017-10-05 12:44 Claudio Foellmi
2017-10-28 20:55 ` Wolfram Sang
0 siblings, 1 reply; 2+ messages in thread
From: Claudio Foellmi @ 2017-10-05 12:44 UTC (permalink / raw)
To: Wolfram Sang; +Cc: Claudio Foellmi, linux-i2c, linux-kernel
Move the check for a stuck SCL before the check for a high SDA.
This prevent false positives in the specific case that SDA is fine
and SCL is stuck, which previously returned 0.
Also check SDA again after the loop, if we can.
Together, these changes should lead to a lot more failed
recoveries being caught and returning error codes.
Signed-off-by: Claudio Foellmi <claudio.foellmi@ergon.ch>
---
I'm not sure if the null check for get_sda really is necessary
(are there really any drivers that can access scl but not sda?),
but I kept it in just in case.
drivers/i2c/i2c-core-base.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 56e4658..65a0415 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -205,9 +205,6 @@ static int i2c_generic_recovery(struct i2c_adapter *adap)
*/
while (i++ < RECOVERY_CLK_CNT * 2) {
if (val) {
- /* Break if SDA is high */
- if (bri->get_sda && bri->get_sda(adap))
- break;
/* SCL shouldn't be low here */
if (!bri->get_scl(adap)) {
dev_err(&adap->dev,
@@ -215,6 +212,9 @@ static int i2c_generic_recovery(struct i2c_adapter *adap)
ret = -EBUSY;
break;
}
+ /* Break if SDA is high */
+ if (bri->get_sda && bri->get_sda(adap))
+ break;
}
val = !val;
@@ -222,6 +222,10 @@ static int i2c_generic_recovery(struct i2c_adapter *adap)
ndelay(RECOVERY_NDELAY);
}
+ /* check if recovery actually succeeded */
+ if (bri->get_sda && !bri->get_sda(adap))
+ ret = -EBUSY;
+
if (bri->unprepare_recovery)
bri->unprepare_recovery(adap);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] i2c: generic recovery: check SCL before SDA
2017-10-05 12:44 [PATCH] i2c: generic recovery: check SCL before SDA Claudio Foellmi
@ 2017-10-28 20:55 ` Wolfram Sang
0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2017-10-28 20:55 UTC (permalink / raw)
To: Claudio Foellmi; +Cc: linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 748 bytes --]
On Thu, Oct 05, 2017 at 02:44:14PM +0200, Claudio Foellmi wrote:
> Move the check for a stuck SCL before the check for a high SDA.
> This prevent false positives in the specific case that SDA is fine
> and SCL is stuck, which previously returned 0.
>
> Also check SDA again after the loop, if we can.
> Together, these changes should lead to a lot more failed
> recoveries being caught and returning error codes.
>
> Signed-off-by: Claudio Foellmi <claudio.foellmi@ergon.ch>
Applied to for-next, thanks!
Huh, I thought we already fixed the add-SDA-check-after-loop, but seems
I was wrong :( I am not super happy with the now doubled SDA check, but
refactoring the whole loop is a seperate change IMO which can be done
later.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-10-28 20:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-05 12:44 [PATCH] i2c: generic recovery: check SCL before SDA Claudio Foellmi
2017-10-28 20:55 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox