* [PATCH] hwmon:fam15h_power Use div64_u64() for 64-bit divisor
@ 2025-12-30 12:09 SeungJu Cheon
2025-12-30 23:23 ` David Laight
0 siblings, 1 reply; 3+ messages in thread
From: SeungJu Cheon @ 2025-12-30 12:09 UTC (permalink / raw)
To: ray.huang, linux; +Cc: linux-hwmon, linux-kernel, SeungJu Cheon
tdelta is u64, but do_div() truncates the divisor to 32 bits.
Use div64_u64() to handle the full 64-bit divisor correctly.
Signed-off-by: SeungJu Cheon <suunj1331@gmail.com>
---
drivers/hwmon/fam15h_power.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index 8ecebea53651..5e3692606516 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -241,7 +241,7 @@ static ssize_t power1_average_show(struct device *dev,
}
tdelta = data->cpu_sw_pwr_ptsc[cu] - prev_ptsc[cu];
jdelta[cu] *= data->cpu_pwr_sample_ratio * 1000;
- do_div(jdelta[cu], tdelta);
+ jdelta[cu] = div64_u64(jdelta[cu], tdelta);
/* the unit is microWatt */
avg_acc += jdelta[cu];
--
2.52.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon:fam15h_power Use div64_u64() for 64-bit divisor
2025-12-30 12:09 [PATCH] hwmon:fam15h_power Use div64_u64() for 64-bit divisor SeungJu Cheon
@ 2025-12-30 23:23 ` David Laight
2025-12-31 14:18 ` Guenter Roeck
0 siblings, 1 reply; 3+ messages in thread
From: David Laight @ 2025-12-30 23:23 UTC (permalink / raw)
To: SeungJu Cheon; +Cc: ray.huang, linux, linux-hwmon, linux-kernel
On Tue, 30 Dec 2025 21:09:59 +0900
SeungJu Cheon <suunj1331@gmail.com> wrote:
> tdelta is u64, but do_div() truncates the divisor to 32 bits.
> Use div64_u64() to handle the full 64-bit divisor correctly.
Looking at the code I think that tdelta is a time interval and will
always fit in 32bits - so the code is probably fine.
Also I can't see anything that requires jdelta[] be an array.
Neither can I see the justification for MAX_CUS being 8.
>
> Signed-off-by: SeungJu Cheon <suunj1331@gmail.com>
> ---
> drivers/hwmon/fam15h_power.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
> index 8ecebea53651..5e3692606516 100644
> --- a/drivers/hwmon/fam15h_power.c
> +++ b/drivers/hwmon/fam15h_power.c
> @@ -241,7 +241,7 @@ static ssize_t power1_average_show(struct device *dev,
> }
> tdelta = data->cpu_sw_pwr_ptsc[cu] - prev_ptsc[cu];
> jdelta[cu] *= data->cpu_pwr_sample_ratio * 1000;
> - do_div(jdelta[cu], tdelta);
> + jdelta[cu] = div64_u64(jdelta[cu], tdelta);
>
> /* the unit is microWatt */
> avg_acc += jdelta[cu];
That could be:
jdelta *= data->cpu_pwr_sample_ratio * 1000;
avg_acc += div64_u64(jdelta, tdelta);
(or even 1 line...)
David
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon:fam15h_power Use div64_u64() for 64-bit divisor
2025-12-30 23:23 ` David Laight
@ 2025-12-31 14:18 ` Guenter Roeck
0 siblings, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2025-12-31 14:18 UTC (permalink / raw)
To: David Laight; +Cc: SeungJu Cheon, ray.huang, linux-hwmon, linux-kernel
On Tue, Dec 30, 2025 at 11:23:57PM +0000, David Laight wrote:
> On Tue, 30 Dec 2025 21:09:59 +0900
> SeungJu Cheon <suunj1331@gmail.com> wrote:
>
> > tdelta is u64, but do_div() truncates the divisor to 32 bits.
> > Use div64_u64() to handle the full 64-bit divisor correctly.
>
> Looking at the code I think that tdelta is a time interval and will
> always fit in 32bits - so the code is probably fine.
>
Agreed.
> Also I can't see anything that requires jdelta[] be an array.
> Neither can I see the justification for MAX_CUS being 8.
>
Also agree.
Guenter
> >
> > Signed-off-by: SeungJu Cheon <suunj1331@gmail.com>
> > ---
> > drivers/hwmon/fam15h_power.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
> > index 8ecebea53651..5e3692606516 100644
> > --- a/drivers/hwmon/fam15h_power.c
> > +++ b/drivers/hwmon/fam15h_power.c
> > @@ -241,7 +241,7 @@ static ssize_t power1_average_show(struct device *dev,
> > }
> > tdelta = data->cpu_sw_pwr_ptsc[cu] - prev_ptsc[cu];
> > jdelta[cu] *= data->cpu_pwr_sample_ratio * 1000;
> > - do_div(jdelta[cu], tdelta);
> > + jdelta[cu] = div64_u64(jdelta[cu], tdelta);
> >
> > /* the unit is microWatt */
> > avg_acc += jdelta[cu];
>
> That could be:
> jdelta *= data->cpu_pwr_sample_ratio * 1000;
> avg_acc += div64_u64(jdelta, tdelta);
> (or even 1 line...)
>
> David
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-31 14:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-30 12:09 [PATCH] hwmon:fam15h_power Use div64_u64() for 64-bit divisor SeungJu Cheon
2025-12-30 23:23 ` David Laight
2025-12-31 14:18 ` Guenter Roeck
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®