From: Grant Peltier <grantpeltier93@gmail.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: robh@kernel.org, linux@roeck-us.net, magnus.damm@gmail.com,
grant.peltier.jg@renesas.com, brandon.howell.jg@renesas.com,
linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
linux-doc@vger.kernel.org
Subject: Re: [PATCH v2 1/2] hwmon: (pmbus/isl68137) add support for voltage divider on Vout
Date: Wed, 23 Oct 2024 11:40:33 -0500 [thread overview]
Message-ID: <ZxknAYim1Dojp13h@raspberrypi> (raw)
In-Reply-To: <CAMuHMdWeqGvUZmTpo18oaOzYz1TEg97OuXyUSy9YJxmrWQWMBw@mail.gmail.com>
Hi Geert,
On Wed, Oct 23, 2024 at 09:34:36AM +0200, Geert Uytterhoeven wrote:
> > [...]
> > + case PMBUS_READ_VOUT:
> > + ret = pmbus_read_word_data(client, page, phase, reg);
> > + if (ret > 0 && data->channel[page].vout_voltage_divider[0]
> > + && data->channel[page].vout_voltage_divider[1]) {
> > + u64 temp = DIV_ROUND_CLOSEST_ULL((u64)ret *
> > + (data->channel[page].vout_voltage_divider[0]
> > + + data->channel[page].vout_voltage_divider[1]),
> > + data->channel[page].vout_voltage_divider[1]);
>
> You are casting "ret" to u64 to force a 64-bit multiplication, as the
> product may not fit in 32 bits. However, DIV_ROUND_CLOSEST_ULL()
> does a 32-bit division on 32-bit platforms. So this should use
> DIV_U64_ROUND_CLOSEST() instead.
> The sum of vout_voltage_divider[0] + vout_voltage_divider[1] might
> not fit in 32 bits, so that should be changed to a 64-bit addition.
> Unfortunately there is no rounding version of mul_u64_u32_div() yet,
> so you have to open-code it.
>
> > + ret = clamp_val(temp, 0, 0xffff);
> > + }
> > + break;
> > default:
> > ret = -ENODATA;
> > [...]
> > + u64 temp = DIV_ROUND_CLOSEST_ULL((u64)word *
> > + data->channel[page].vout_voltage_divider[1],
> > + (data->channel[page].vout_voltage_divider[0] +
> > + data->channel[page].vout_voltage_divider[1]));
>
> Similar comments, but here the sum is the divisor, so you have to use
> a full 64-by-64 division, using DIV64_U64_ROUND_CLOSEST().
>
> > + ret = clamp_val(temp, 0, 0xffff);
> > + } else {
> > + ret = -ENODATA;
> > + }
> > + break;
> > + default:
> > + ret = -ENODATA;
> > + break;
> > + }
> > + return ret;
> > +}
> > [...]
> > +
> > + of_property_read_u32_array(child, "renesas,vout-voltage-divider",
> > + data->channel[channel].vout_voltage_divider,
> > + ARRAY_SIZE(data->channel[channel].vout_voltage_divider));
>
> Shouldn't the return value be checked for errors different from -EINVAL?
>
Thank you for your review! I will make the requested changes and submit a
new version.
Best regards,
Grant
next prev parent reply other threads:[~2024-10-23 16:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 1:56 [PATCH v2 0/2] dt-bindings: hwmon: pmbus: add bindings for isl68137 Grant Peltier
2024-10-23 1:58 ` [PATCH v2 1/2] hwmon: (pmbus/isl68137) add support for voltage divider on Vout Grant Peltier
2024-10-23 7:34 ` Geert Uytterhoeven
2024-10-23 16:40 ` Grant Peltier [this message]
2024-10-24 17:48 ` Guenter Roeck
2024-10-24 19:43 ` Grant Peltier
2024-10-24 20:03 ` Guenter Roeck
2024-10-23 1:58 ` [PATCH v2 2/2] dt-bindings: hwmon: isl68137: add bindings to support voltage dividers Grant Peltier
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=ZxknAYim1Dojp13h@raspberrypi \
--to=grantpeltier93@gmail.com \
--cc=brandon.howell.jg@renesas.com \
--cc=devicetree@vger.kernel.org \
--cc=geert@linux-m68k.org \
--cc=grant.peltier.jg@renesas.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=magnus.damm@gmail.com \
--cc=robh@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).