From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795022642; b=mLDu2lOyJDAOCgzt3DTMSaHsOuNNRW3HaPJmf1vPSD/h2uesOfQLfsuRuTV/n1srO+dW +NiErJsNFo0EUhSBx+XMnFs8b8cxXbDbWjqvJNCeW2Xf+LQMOpE+oeqjXg51Z/kbjmh4L fiH5W6tVXKhHlgKh8ChK5xgjyunem5hROHu6BJX4LpcAE5vWrCJpJQganew5FttpU67oE ajlzh+u3xMaW27RAyz5yTdbiOhBR0ZZG7d19Nf8P/msq6U/aECShSQP5dIaENX3MMaWMc FRGJklTjARyC/EgFYLgVQmNeE6Pii8tGlcfzRRHMUdiOnUIgkP11/9On8hI2mZIxWhA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795022642; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=3u0OqU/AI8erDPCxgIJwoF0PsDn+pUzAiko2bGqUOic=; b=r3zaB7gBIK+En/etojgfjyCT19iQVwQUzuAXWdi1i7LN52jgXgMM/ONDAquiRMChqoON v5cMaJIUhTXQUFuc6p1B/rPoxH73U4PS4OLtGiyc81twMhdsUGkeQzqh71wGLORre3o8Y gw7GDOxeHCDBM5dEa1Q7U9tUgcG/oCfKmeTh7BMjBdY9/SnLy2vY2PRjAhhiQB0vdFTf3 F1XOGTFftpx5gLcK7LZxCwtsNZ9Je7PKp8rRX70pITus+dJPpHDq+uF1pcDAq9QnG+761 LrNkFv5bFdhwGWUZrj/alnGr4nF9VO/esICHePPejwU8cMxxhTO/5AfuEOUTglHtaqA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=nkCRkKoU; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AA5160A260C; Wed, 18 Nov 2026 17:24:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=nkCRkKoU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 160E31F000CC; Wed, 18 Nov 2026 17:24:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795022641; bh=3u0OqU/AI8erDPCxgIJwoF0PsDn+pUzAiko2bGqUOic=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nkCRkKoU7+3G5pfYrtB8GVMSZLAzGaEVer/oZ77AcicacW7wJfGauxzFnpYqFzxoh 3naPiUIszt052+S8rOtq0iCBvIMxCYzAzJGZ54oxcosxthfo9cFbK8IPmYy4n56t4M N9+nRWP/id+VYpI8NvsPvJDAoWijR5GAOWu0rHtU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Guenter Roeck , Sasha Levin Subject: [PATCH 6.18 0084/2151] hwmon: (tmp108) Fix initial conversion delay and wait until ready Date: Wed, 18 Nov 2026 15:30:19 +0100 Message-ID: <20261118150124.846755846@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150121.603863898@linuxfoundation.org> References: <20261118150121.603863898@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guenter Roeck [ Upstream commit 7cd60538073e465310c94b2a2f0ea8d2f03768ef ] In tmp108_common_probe(), the driver only adds the 30 ms conversion delay (TMP108_CONVERSION_TIME_MS) to ready_time if the sensor was previously in TMP108_MODE_SHUTDOWN. However, the TMP108 hardware defaults to continuous conversion mode (TMP108_MODE_CONTINUOUS) upon power-on reset, including immediately after enabling the vcc supply regulator during probe, while the temperature register retains its power-on reset value of 0x0000 (0°C) until the first conversion completes. Because the initial mode is not shutdown, the delay is bypassed and early reads via thermal zone registration or sysfs before the first conversion finishes return an uninitialized 0°C reading. In addition, returning -EAGAIN from tmp108_read() while waiting for a conversion to complete after probe or resume can trigger an unnecessary tight retry loop in callers or fail initial reads. Unconditionally set ready_time to TMP108_CONVERSION_TIME_MS ahead in tmp108_common_probe(), track ready_time as ktime_t, and wait for the remaining conversion time in tmp108_read() using usleep_range() instead of returning -EAGAIN. Reported-by: Sashiko Fixes: 66e1c9171339 ("hwmon: Add Texas Instruments TMP108 temperature sensor driver.") Cc: stable@vger.kernel.org Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/tmp108.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c index b298fae9296c6..530f679898992 100644 --- a/drivers/hwmon/tmp108.c +++ b/drivers/hwmon/tmp108.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -74,7 +74,7 @@ struct tmp108 { struct regmap *regmap; u16 orig_config; - u64 ready_time; + ktime_t ready_time; }; /* convert 12-bit TMP108 register value to milliCelsius */ @@ -95,6 +95,7 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type, struct tmp108 *tmp108 = dev_get_drvdata(dev); unsigned int regval; int err, hyst; + s64 delay; if (type == hwmon_chip) { if (attr == hwmon_chip_update_interval) { @@ -124,12 +125,10 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type, switch (attr) { case hwmon_temp_input: - /* Is it too early to return a conversion ? */ - if (time_before64(get_jiffies_64(), tmp108->ready_time)) { - dev_dbg(dev, "%s: Conversion not ready yet..\n", - __func__); - return -EAGAIN; - } + /* Wait if it is too early to return a conversion */ + delay = ktime_us_delta(tmp108->ready_time, ktime_get()); + if (delay > 0) + usleep_range(delay, delay + 1000); err = regmap_read(tmp108->regmap, TMP108_REG_TEMP, ®val); if (err < 0) return err; @@ -362,11 +361,8 @@ static int tmp108_common_probe(struct device *dev, struct regmap *regmap, char * return err; } - tmp108->ready_time = get_jiffies_64(); - if ((tmp108->orig_config & TMP108_CONF_MODE_MASK) == - TMP108_MODE_SHUTDOWN) - tmp108->ready_time += - msecs_to_jiffies(TMP108_CONVERSION_TIME_MS); + tmp108->ready_time = ktime_add_ms(ktime_get(), + TMP108_CONVERSION_TIME_MS); err = devm_add_action_or_reset(dev, tmp108_restore_config, tmp108); if (err) { @@ -413,8 +409,8 @@ static int tmp108_resume(struct device *dev) err = regmap_update_bits(tmp108->regmap, TMP108_REG_CONF, TMP108_CONF_MODE_MASK, TMP108_MODE_CONTINUOUS); - tmp108->ready_time = get_jiffies_64() + - msecs_to_jiffies(TMP108_CONVERSION_TIME_MS); + tmp108->ready_time = ktime_add_ms(ktime_get(), + TMP108_CONVERSION_TIME_MS); return err; } -- 2.53.0