Skip to contentSkip to conversation

iio: flow: slf3s: disable regulator if measurement restart fails

PATCH Superseded Li Youhong 3 participants 3 messages Sep 1 – Sep 4

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Li Youhong

author
#0 lore raw

PATCH 1/1 iio: flow: slf3s: disable regulator if measurement restart fails

From: Li Youhong <[email protected]>

slf3s_resume() enables the vdd regulator and then starts continuous measurement. If slf3s_start_meas() fails, resume returns an error while leaving the regulator enabled. Disable vdd on that path so a failed resume does not leave the supply on.

Fixes d240b0b8a1ce ("iio: flow: add Sensirion SLF3S liquid flow sensor driver")
---
 drivers/iio/flow/slf3s.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/flow/slf3s.c +5 -1
index dfa7c1409045..9b63ceb3768a 100644
@@ -487,7 +487,11 @@ static int slf3s_resume(struct device *dev)
 
 	fsleep(SLF3S_POWER_UP_DELAY_US);
 
-	return slf3s_start_meas(sf, sf->medium);
+	ret = slf3s_start_meas(sf, sf->medium);
+	if (ret)
+		regulator_disable(sf->vdd);
+
+	return ret;
 }
 
 static DEFINE_SIMPLE_DEV_PM_OPS(slf3s_pm_ops, slf3s_suspend, slf3s_resume);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 4 lines · Li Youhong

slf3s_resume() enables the vdd regulator and then starts continuous measurement. If slf3s_start_meas() fails, resume returns an error while leaving the regulator enabled. Disable vdd on that path so a failed resume does not leave the supply on.

In the scope of resume/suspend path this looks okay, but let's imagine how it may work without this change. So, if resume fails, device will be in suspend mode until it gets another resume attempt, right? Will it be achievable at all? If so, then the regulator reference counting will go sideways. That's what your patch is probably fixing? Needs a bit more of an explanation in the commit message.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Li Youhong
Quoted 32 lines · Li Youhong

From: Li Youhong <[email protected]>

slf3s_resume() enables the vdd regulator and then starts continuous measurement. If slf3s_start_meas() fails, resume returns an error while leaving the regulator enabled. Disable vdd on that path so a failed resume does not leave the supply on.

Fixes d240b0b8a1ce ("iio: flow: add Sensirion SLF3S liquid flow sensor driver")
---
 drivers/iio/flow/slf3s.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/flow/slf3s.c +5 -1
index dfa7c1409045..9b63ceb3768a 100644
@@ -487,7 +487,11 @@ static int slf3s_resume(struct device *dev)
 
 	fsleep(SLF3S_POWER_UP_DELAY_US);
 
-	return slf3s_start_meas(sf, sf->medium);
+	ret = slf3s_start_meas(sf, sf->medium);
+	if (ret)
+		regulator_disable(sf->vdd);
+
+	return ret;
 }
 
 static DEFINE_SIMPLE_DEV_PM_OPS(slf3s_pm_ops, slf3s_suspend, slf3s_resume);
Signature · 1 line
2.25.1

Fixes the unbalanced regulator refcount across resume retries, as described.