From: David Laight <david.laight.linux@gmail.com>
To: SeungJu Cheon <suunj1331@gmail.com>
Cc: ray.huang@amd.com, linux@roeck-us.net,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwmon:fam15h_power Use div64_u64() for 64-bit divisor
Date: Tue, 30 Dec 2025 23:23:57 +0000 [thread overview]
Message-ID: <20251230232357.00222b64@pumpkin> (raw)
In-Reply-To: <20251230120959.199139-1-suunj1331@gmail.com>
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
next prev parent reply other threads:[~2025-12-30 23:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-30 12:09 SeungJu Cheon
2025-12-30 23:23 ` David Laight [this message]
2025-12-31 14:18 ` Guenter Roeck
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=20251230232357.00222b64@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=ray.huang@amd.com \
--cc=suunj1331@gmail.com \
/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
all inboxes | Powered by JetHome®