From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Svyatoslav Ryhel <clamor95@gmail.com>,
Sebastian Reichel <sebastian.reichel@collabora.com>,
Sasha Levin <sashal@kernel.org>,
sre@kernel.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 6.12 25/26] power: supply: max17040: adjust thermal channel scaling
Date: Fri, 30 May 2025 08:40:11 -0400 [thread overview]
Message-ID: <20250530124012.2575409-25-sashal@kernel.org> (raw)
In-Reply-To: <20250530124012.2575409-1-sashal@kernel.org>
From: Svyatoslav Ryhel <clamor95@gmail.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@gmail.com>
Link: https://lore.kernel.org/r/20250430060239.12085-2-clamor95@gmail.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Sasha Levin <sashal@kernel.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
next prev parent reply other threads:[~2025-05-30 12:40 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-30 12:39 [PATCH AUTOSEL 6.12 01/26] ACPICA: fix acpi operand cache leak in dswstate.c Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 02/26] ASoC: amd: yc: Add quirk for Lenovo Yoga Pro 7 14ASP9 Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 03/26] clocksource: Fix the CPUs' choice in the watchdog per CPU verification Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 04/26] tools/nolibc: use intmax definitions from compiler Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 05/26] power: supply: collie: Fix wakeup source leaks on device unbind Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 06/26] mmc: Add quirk to disable DDR50 tuning Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 07/26] ACPICA: Avoid sequence overread in call to strncmp() Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 08/26] mmc: sdhci-esdhc-imx: Save tuning value when card stays powered in suspend Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 09/26] ASoC: tas2770: Power cycle amp on ISENSE/VSENSE change Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 10/26] ASoC: intel/sdw_utils: Assign initial value in asoc_sdw_rt_amp_spk_rtd_init() Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 11/26] ACPI: bus: Bail out if acpi_kobj registration fails Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 12/26] ACPI: Add missing prototype for non CONFIG_SUSPEND/CONFIG_X86 case Sasha Levin
2025-05-30 12:39 ` [PATCH AUTOSEL 6.12 13/26] ACPICA: fix acpi parse and parseext cache leaks Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 14/26] ACPICA: Apply pack(1) to union aml_resource Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 15/26] ALSA: hda: cs35l41: Fix swapped l/r audio channels for Acer Helios laptops Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 16/26] power: supply: bq27xxx: Retrieve again when busy Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 17/26] pmdomain: core: Reset genpd->states to avoid freeing invalid data Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 18/26] ACPICA: utilities: Fix overflow check in vsnprintf() Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 19/26] platform-msi: Add msi_remove_device_irq_domain() in platform_device_msi_free_irqs_all() Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 20/26] ASoC: tegra210_ahub: Add check to of_device_get_match_data() Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 21/26] Make 'cc-option' work correctly for the -Wno-xyzzy pattern Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 22/26] gpiolib: of: Add polarity quirk for s5m8767 Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 23/26] PM: runtime: fix denying of auto suspend in pm_suspend_timer_fn() Sasha Levin
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 24/26] tools/nolibc: use pselect6_time64 if available Sasha Levin
2025-05-30 12:40 ` Sasha Levin [this message]
2025-05-30 12:40 ` [PATCH AUTOSEL 6.12 26/26] ACPI: battery: negate current when discharging Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250530124012.2575409-25-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=clamor95@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=sebastian.reichel@collabora.com \
--cc=sre@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox