* [PATCH] power: supply: use ktime_divns() to avoid 64-bit division
@ 2025-10-15 7:56 Michal Kubecek
2025-10-15 10:04 ` Hans de Goede
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Michal Kubecek @ 2025-10-15 7:56 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm; +Cc: Hans de Goede, Linus Walleij, linux-kernel
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1639 bytes --]
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>
---
drivers/power/supply/intel_dc_ti_battery.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/power/supply/intel_dc_ti_battery.c b/drivers/power/supply/intel_dc_ti_battery.c
index 56b0c92e9d28..c26209ef9577 100644
--- a/drivers/power/supply/intel_dc_ti_battery.c
+++ b/drivers/power/supply/intel_dc_ti_battery.c
@@ -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);
--
2.51.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] power: supply: use ktime_divns() to avoid 64-bit division
2025-10-15 7:56 [PATCH] power: supply: use ktime_divns() to avoid 64-bit division Michal Kubecek
@ 2025-10-15 10:04 ` Hans de Goede
2025-10-15 11:57 ` Dhruva Gole
2025-11-03 0:48 ` Sebastian Reichel
2 siblings, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2025-10-15 10:04 UTC (permalink / raw)
To: Michal Kubecek, Sebastian Reichel, linux-pm; +Cc: Linus Walleij, linux-kernel
Hi Michal,
On 15-Oct-25 9:56 AM, Michal Kubecek wrote:
> 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>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hansg@kernel.org>
Regards,
Hans
> ---
> drivers/power/supply/intel_dc_ti_battery.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/power/supply/intel_dc_ti_battery.c b/drivers/power/supply/intel_dc_ti_battery.c
> index 56b0c92e9d28..c26209ef9577 100644
> --- a/drivers/power/supply/intel_dc_ti_battery.c
> +++ b/drivers/power/supply/intel_dc_ti_battery.c
> @@ -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);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] power: supply: use ktime_divns() to avoid 64-bit division
2025-10-15 7:56 [PATCH] power: supply: use ktime_divns() to avoid 64-bit division Michal Kubecek
2025-10-15 10:04 ` Hans de Goede
@ 2025-10-15 11:57 ` Dhruva Gole
2025-11-03 0:48 ` Sebastian Reichel
2 siblings, 0 replies; 4+ messages in thread
From: Dhruva Gole @ 2025-10-15 11:57 UTC (permalink / raw)
To: Michal Kubecek
Cc: Sebastian Reichel, linux-pm, Hans de Goede, Linus Walleij, linux-kernel
On Oct 15, 2025 at 09:56:31 +0200, Michal Kubecek wrote:
> 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>
> ---
Good catch!
Reviewed-by: Dhruva Gole <d-gole@ti.com>
--
Best regards,
Dhruva Gole
Texas Instruments Incorporated
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] power: supply: use ktime_divns() to avoid 64-bit division
2025-10-15 7:56 [PATCH] power: supply: use ktime_divns() to avoid 64-bit division Michal Kubecek
2025-10-15 10:04 ` Hans de Goede
2025-10-15 11:57 ` Dhruva Gole
@ 2025-11-03 0:48 ` Sebastian Reichel
2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2025-11-03 0:48 UTC (permalink / raw)
To: Sebastian Reichel, linux-pm, Michal Kubecek
Cc: Hans de Goede, Linus Walleij, linux-kernel
On Wed, 15 Oct 2025 09:56:31 +0200, Michal Kubecek wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] power: supply: use ktime_divns() to avoid 64-bit division
commit: 3fd1695f5da0538ef72e1268baa00528b589347a
Best regards,
--
Sebastian Reichel <sebastian.reichel@collabora.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-03 0:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-15 7:56 [PATCH] power: supply: use ktime_divns() to avoid 64-bit division Michal Kubecek
2025-10-15 10:04 ` Hans de Goede
2025-10-15 11:57 ` Dhruva Gole
2025-11-03 0:48 ` Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®