[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20250530123934.2574748-27-sashal@kernel.org>
Date: Fri, 30 May 2025 08:39:33 -0400
From: Sasha Levin <sashal@...nel.org>
To: patches@...ts.linux.dev,
stable@...r.kernel.org
Cc: Svyatoslav Ryhel <clamor95@...il.com>,
Sebastian Reichel <sebastian.reichel@...labora.com>,
Sasha Levin <sashal@...nel.org>,
sre@...nel.org,
linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH AUTOSEL 6.14 27/28] power: supply: max17040: adjust thermal channel scaling
From: Svyatoslav Ryhel <clamor95@...il.com>
[ Upstream commit d055f51731744243b244aafb1720f793a5b61f7b ]
IIO thermal channel is in millidegree while power supply framework expects
decidegree values. Adjust scaling to get correct readings.
Signed-off-by: Svyatoslav Ryhel <clamor95@...il.com>
Link: https://lore.kernel.org/r/20250430060239.12085-2-clamor95@gmail.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@...labora.com>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
**YES** This commit should be backported to stable kernel trees. Here's
my extensive analysis: ## Code Analysis The commit fixes a **units
conversion bug** in the max17040 power supply driver's temperature
reporting. Specifically: ### The Problem The original code in
`max17040_get_property()` for `POWER_SUPPLY_PROP_TEMP` was: ```c
iio_read_channel_processed_scale(chip->channel_temp, &val->intval, 10);
``` ### The Fix The corrected code is: ```c
iio_read_channel_processed(chip->channel_temp, &val->intval);
val->intval /= 100; /bin /bin.usr-is-merged /boot /dev /etc /home /init
/lib /lib.usr-is-merged /lib64 /lost+found /media /mnt /opt /proc /root
/run /sbin /sbin.usr-is-merged /snap /srv /sys /tmp /usr /var Convert
from milli- to deci-degree model/ prompt/ src/ target/ ``` ### Units
Mismatch Issue According to the power supply class documentation found
in `/home/sasha/linux/Documentation/power/power_supply_class.rst`: >
"All voltages, currents, charges, energies, time and **temperatures** in
µV, µA, µAh, µWh, seconds and **tenths of degree Celsius** unless
otherwise stated." The power supply framework expects temperatures in
**tenths of degree Celsius** (decidegrees), but IIO thermal channels
typically return values in **millidegrees Celsius**. ### Mathematical
Analysis - IIO thermal channel: returns millidegrees (1/1000 °C) - Power
supply framework expects: decidegrees (1/10 °C) - Required conversion:
millidegrees ÷ 100 = decidegrees - Old code: Applied a scale of 10,
which would convert from decidegrees to degrees (wrong direction) - New
code: Divides by 100, correctly converting from millidegrees to
decidegrees ### Confirmation from Kernel Sources Looking at
`max17042_battery.c` (similar chip), line 109 shows the correct pattern:
```c /bin /bin.usr-is-merged /boot /dev /etc /home /init /lib /lib.usr-
is-merged /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin
/sbin.usr-is-merged /snap /srv /sys /tmp /usr /var The value is
converted into deci-centigrade scale model/ prompt/ src/ target/ *temp =
*temp 0001-Fix-Clippy-warnings.patch 0002-Enhance-inference-prompt-to-
utilize-CVEKERNELDIR-whe.patch 0003-Update-to-latest-version-of-
clap.patch Cargo.lock Cargo.toml LICENSE README.md
analyze_merge_commit.sh io_uring_analysis.txt ksmbd_analysis.txt
merge_commit_analysis.txt model prompt src target test_gpio_cleanup.txt
test_patch.txt 10 / 256; ``` This confirms that power supply drivers
should output temperatures in deci-centigrade (decidegrees). ## Backport
Suitability Assessment **1. Bug Fix**: ✅ Yes - This fixes incorrect
temperature readings **2. Small and Contained**: ✅ Yes - Only 3 lines
changed in one function **3. Clear Side Effects**: ✅ No major side
effects - only corrects temperature values **4. Architectural Changes**:
✅ No - Simple unit conversion fix **5. Critical Subsystem**: ✅ Limited
impact - only affects optional temperature reporting **6. Stable Tree
Mention**: ❌ No explicit mention, but meets criteria **7. Stable Tree
Rules**: ✅ Important bugfix with minimal regression risk ## Risk
Assessment - **Regression Risk**: Very low - only affects temperature
readings when IIO thermal channel is present - **User Impact**: High for
affected users - wrong temperature readings could affect thermal
management - **Code Complexity**: Minimal - straightforward arithmetic
fix ## Historical Context The thermal channel support was added in
commit `814755c48f8b` (July 2023), and this scaling bug has been present
since then. The fix addresses a fundamental units mismatch that would
cause incorrect temperature reporting for any system using the IIO
thermal channel feature. This is exactly the type of contained,
important bugfix that stable trees are designed for.
drivers/power/supply/max17040_battery.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
index 51310f6e4803b..c1640bc6accd2 100644
--- a/drivers/power/supply/max17040_battery.c
+++ b/drivers/power/supply/max17040_battery.c
@@ -410,8 +410,9 @@ static int max17040_get_property(struct power_supply *psy,
if (!chip->channel_temp)
return -ENODATA;
- iio_read_channel_processed_scale(chip->channel_temp,
- &val->intval, 10);
+ iio_read_channel_processed(chip->channel_temp, &val->intval);
+ val->intval /= 100; /* Convert from milli- to deci-degree */
+
break;
default:
return -EINVAL;
--
2.39.5
Powered by blists - more mailing lists