From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Jonathan Cameron <jic23@kernel.org>,
Qing Wang <wangqing@vivo.com>,
"Jyoti Bhayana" <jbhayana@google.com>,
Lars-Peter Clausen <lars@metafoo.de>, <linux-iio@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio: use div64_u64() instead of do_div()
Date: Mon, 14 Feb 2022 11:01:19 +0000 [thread overview]
Message-ID: <20220214110119.00006347@Huawei.com> (raw)
In-Reply-To: <29e74800-1c3f-e043-97e6-d83f7a53fafb@wanadoo.fr>
On Sun, 13 Feb 2022 19:54:01 +0100
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
> Le 13/02/2022 à 19:50, Christophe JAILLET a écrit :
> > Le 13/02/2022 à 18:59, Jonathan Cameron a écrit :
> >> On Wed, 9 Feb 2022 00:37:53 -0800
> >> Qing Wang <wangqing-DGpbCiVdSXo@public.gmane.org> wrote:
> >>
> >>> From: Wang Qing <wangqing-DGpbCiVdSXo@public.gmane.org>
> >>>
> >>> do_div() does a 64-by-32 division.
> >>> When the divisor is u64, do_div() truncates it to 32 bits, this means it
> >>> can test non-zero and be truncated to zero for division.
> >>>
> >>> fix do_div.cocci warning:
> >>> do_div() does a 64-by-32 division, please consider using div64_u64
> >>> instead.
> >>>
> >>> Signed-off-by: Wang Qing <wangqing-DGpbCiVdSXo@public.gmane.org>
> >> These look correct to me. Jyoti, please could give these a sanity check?
> >>
> >
> > This is wrong.
> >
> > See [1].
> >
> > CJ
> >
> > [1]:
> > https://lore.kernel.org/linux-kernel/20211117112559.jix3hmx7uwqmuryg-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org/
>
> Broken link, sorry:
>
> [1]
> https://lore.kernel.org/linux-kernel/20211117112559.jix3hmx7uwqmuryg@pengutronix.de/
>
oops. Thanks for the heads up. I'd forgotten the slightly odd convention
around do_div
Jonathan
> >
> >
> >> Thanks,
> >>
> >> Jonathan
> >>
> >>> ---
> >>> drivers/iio/common/scmi_sensors/scmi_iio.c | 10 +++++-----
> >>> 1 file changed, 5 insertions(+), 5 deletions(-)
> >>>
> >>> diff --git a/drivers/iio/common/scmi_sensors/scmi_iio.c
> >>> b/drivers/iio/common/scmi_sensors/scmi_iio.c
> >>> index d538bf3..d6df5da
> >>> --- a/drivers/iio/common/scmi_sensors/scmi_iio.c
> >>> +++ b/drivers/iio/common/scmi_sensors/scmi_iio.c
> >>> @@ -160,7 +160,7 @@ static int scmi_iio_set_odr_val(struct iio_dev
> >>> *iio_dev, int val, int val2)
> >>> mult = scnprintf(buf, sizeof(buf), "%llu", sf) - 1;
> >>> sec = int_pow(10, mult) * UHZ_PER_HZ;
> >>> - do_div(sec, uHz);
> >>> + div64_u64(sec, uHz);
> >>> if (sec == 0) {
> >>> dev_err(&iio_dev->dev,
> >>> "Trying to set invalid sensor update value for sensor %s",
> >>> @@ -237,10 +237,10 @@ static void convert_ns_to_freq(u64 interval_ns,
> >>> u64 *hz, u64 *uhz)
> >>> u64 rem, freq;
> >>> freq = NSEC_PER_SEC;
> >>> - rem = do_div(freq, interval_ns);
> >>> + rem = div64_u64(freq, interval_ns);
> >>> *hz = freq;
> >>> *uhz = rem * 1000000UL;
> >>> - do_div(*uhz, interval_ns);
> >>> + div64_u64(*uhz, interval_ns);
> >>> }
> >>> static int scmi_iio_get_odr_val(struct iio_dev *iio_dev, int *val,
> >>> int *val2)
> >>> @@ -266,7 +266,7 @@ static int scmi_iio_get_odr_val(struct iio_dev
> >>> *iio_dev, int *val, int *val2)
> >>> mult = SCMI_SENS_CFG_GET_UPDATE_EXP(sensor_config);
> >>> if (mult < 0) {
> >>> sensor_interval_mult = int_pow(10, abs(mult));
> >>> - do_div(sensor_update_interval, sensor_interval_mult);
> >>> + div64_u64(sensor_update_interval, sensor_interval_mult);
> >>> } else {
> >>> sensor_interval_mult = int_pow(10, mult);
> >>> sensor_update_interval =
> >>> @@ -500,7 +500,7 @@ static u64 scmi_iio_convert_interval_to_ns(u32 val)
> >>> mult = SCMI_SENS_INTVL_GET_EXP(val);
> >>> if (mult < 0) {
> >>> sensor_interval_mult = int_pow(10, abs(mult));
> >>> - do_div(sensor_update_interval, sensor_interval_mult);
> >>> + div64_u64(sensor_update_interval, sensor_interval_mult);
> >>> } else {
> >>> sensor_interval_mult = int_pow(10, mult);
> >>> sensor_update_interval =
> >>
> >>
> >
> >
>
next prev parent reply other threads:[~2022-02-14 11:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 8:37 [PATCH] iio: use div64_u64() instead of do_div() Qing Wang
2022-02-13 17:59 ` Jonathan Cameron
2022-02-13 18:50 ` Christophe JAILLET
2022-02-13 18:54 ` Christophe JAILLET
2022-02-14 11:01 ` Jonathan Cameron [this message]
2022-02-14 17:42 ` Jyoti Bhayana
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=20220214110119.00006347@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=jbhayana@google.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wangqing@vivo.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