regressions.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] w1: w1_therm: fix locking behavior in convert_t
@ 2023-04-27 11:21 Stefan Wahren
  2023-05-08  8:59 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Wahren @ 2023-04-27 11:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Krzysztof Kozlowski, Akira Shimahara, Ivan Zaentsev
  Cc: Stefan Wahren, Michael Heimpold, regressions, linux-kernel,
	Stefan Wahren

The commit 67b392f7b8ed ("w1_therm: optimizing temperature read timings")
accidentially inverted the logic for lock handling of the bus mutex.

Before:
  pullup -> release lock before sleep
  no pullup -> release lock after sleep

After:
  pullup -> release lock after sleep
  no pullup -> release lock before sleep

This cause spurious measurements of 85 degree (powerup value) on the
Tarragon board with connected 1-w temperature sensor
(w1_therm.w1_strong_pull=0).

In the meantime a new feature for polling the conversion
completion has been integrated in these branches with
commit 021da53e65fd ("w1: w1_therm: Add sysfs entries to control
conversion time and driver features"). But this feature isn't
available for parasite power mode, so handle this separately.

Link: https://lore.kernel.org/regressions/2023042645-attentive-amends-7b0b@gregkh/T/
Fixes: 67b392f7b8ed ("w1_therm: optimizing temperature read timings")
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
 drivers/w1/slaves/w1_therm.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 067692626cf0..99c58bd9d2df 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -1159,29 +1159,26 @@ static int convert_t(struct w1_slave *sl, struct therm_info *info)
 
 			w1_write_8(dev_master, W1_CONVERT_TEMP);
 
-			if (strong_pullup) { /*some device need pullup */
+			if (SLAVE_FEATURES(sl) & W1_THERM_POLL_COMPLETION) {
+				ret = w1_poll_completion(dev_master, W1_POLL_CONVERT_TEMP);
+				if (ret) {
+					dev_dbg(&sl->dev, "%s: Timeout\n", __func__);
+					goto mt_unlock;
+				}
+				mutex_unlock(&dev_master->bus_mutex);
+			} else if (!strong_pullup) { /*no device need pullup */
 				sleep_rem = msleep_interruptible(t_conv);
 				if (sleep_rem != 0) {
 					ret = -EINTR;
 					goto mt_unlock;
 				}
 				mutex_unlock(&dev_master->bus_mutex);
-			} else { /*no device need pullup */
-				if (SLAVE_FEATURES(sl) & W1_THERM_POLL_COMPLETION) {
-					ret = w1_poll_completion(dev_master, W1_POLL_CONVERT_TEMP);
-					if (ret) {
-						dev_dbg(&sl->dev, "%s: Timeout\n", __func__);
-						goto mt_unlock;
-					}
-					mutex_unlock(&dev_master->bus_mutex);
-				} else {
-					/* Fixed delay */
-					mutex_unlock(&dev_master->bus_mutex);
-					sleep_rem = msleep_interruptible(t_conv);
-					if (sleep_rem != 0) {
-						ret = -EINTR;
-						goto dec_refcnt;
-					}
+			} else { /*some device need pullup */
+				mutex_unlock(&dev_master->bus_mutex);
+				sleep_rem = msleep_interruptible(t_conv);
+				if (sleep_rem != 0) {
+					ret = -EINTR;
+					goto dec_refcnt;
 				}
 			}
 			ret = read_scratchpad(sl, info);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RFC] w1: w1_therm: fix locking behavior in convert_t
  2023-04-27 11:21 [PATCH RFC] w1: w1_therm: fix locking behavior in convert_t Stefan Wahren
@ 2023-05-08  8:59 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 2+ messages in thread
From: Krzysztof Kozlowski @ 2023-05-08  8:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Akira Shimahara, Ivan Zaentsev, Stefan Wahren
  Cc: Krzysztof Kozlowski, Stefan Wahren, Michael Heimpold,
	regressions, linux-kernel


On Thu, 27 Apr 2023 13:21:52 +0200, Stefan Wahren wrote:
> The commit 67b392f7b8ed ("w1_therm: optimizing temperature read timings")
> accidentially inverted the logic for lock handling of the bus mutex.
> 
> Before:
>   pullup -> release lock before sleep
>   no pullup -> release lock after sleep
> 
> [...]

Applied, thanks!

[1/1] w1: w1_therm: fix locking behavior in convert_t
      https://git.kernel.org/krzk/linux-w1/c/dca5480ab7b77a889088ab7cac81934604510ac7

Best regards,
-- 
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-08  9:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-27 11:21 [PATCH RFC] w1: w1_therm: fix locking behavior in convert_t Stefan Wahren
2023-05-08  8:59 ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).