1
0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2026-01-11 17:10:13 +00:00

power: supply: use ktime_divns() to avoid 64-bit division

The build of intel_dc_ti_battery module on i386 (32-bit) fails with

ERROR: modpost: "__udivdi3" [drivers/power/supply/intel_dc_ti_battery.ko]

This is caused by 64-bit division of ktime values by NSEC_PER_USEC. Use
ktime_divns() helper which handles the division correctly on 32-bit
architectures.

Fixes: 8c5795fe5527 ("power: supply: Add new Intel Dollar Cove TI battery driver")
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
Reviewed-by: Dhruva Gole <d-gole@ti.com>
Reviewed-by: Hans de Goede <hansg@kernel.org>
Link: https://patch.msgid.link/20251015075957.8F40620057@lion.mk-sys.cz
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
Michal Kubecek 2025-10-15 09:56:31 +02:00 committed by Sebastian Reichel
parent 06b54f2d74
commit 3fd1695f5d

View File

@ -141,7 +141,7 @@ static int dc_ti_battery_get_voltage_and_current_now(struct power_supply *psy, i
if (ret)
goto out_err;
cnt_start_usec = ktime_get_ns() / NSEC_PER_USEC;
cnt_start_usec = ktime_divns(ktime_get_ns(), NSEC_PER_USEC);
/* Read Vbat, convert IIO mV to power-supply ųV */
ret = iio_read_channel_processed_scale(chip->vbat_channel, volt, 1000);
@ -149,7 +149,7 @@ static int dc_ti_battery_get_voltage_and_current_now(struct power_supply *psy, i
goto out_err;
/* Sleep at least 3 sample-times + slack to get 3+ CC samples */
now_usec = ktime_get_ns() / NSEC_PER_USEC;
now_usec = ktime_divns(ktime_get_ns(), NSEC_PER_USEC);
sleep_usec = 3 * SMPL_INTVL_US + SLEEP_SLACK_US - (now_usec - cnt_start_usec);
if (sleep_usec > 0 && sleep_usec < 1000000)
usleep_range(sleep_usec, sleep_usec + SLEEP_SLACK_US);