Linux IIO development
 help / color / mirror / Atom feed
From: <Victor.Duicu@microchip.com>
To: <andy.shevchenko@gmail.com>, <jic23@kernel.org>,
	<matteomartelli3@gmail.com>, <lars@metafoo.de>
Cc: <Marius.Cristea@microchip.com>, <linux-kernel@vger.kernel.org>,
	<linux-iio@vger.kernel.org>
Subject: Re: [PATCH v11] iio: adc: pac1921: Add ACPI support to Microchip pac1921
Date: Thu, 14 Nov 2024 12:52:12 +0000	[thread overview]
Message-ID: <faed3b586e1af2d946d3f9b185a94b6ebf0f6f32.camel@microchip.com> (raw)
In-Reply-To: <c1b30741bec25e25c6e57389bf45d04f@gmail.com>

On Thu, 2024-11-14 at 12:00 +0100, Matteo Martelli wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 

Hi Matteo,

> On Thu, 14 Nov 2024 10:47:02 +0200, <victor.duicu@microchip.com>
> wrote:
> > From: Victor Duicu <victor.duicu@microchip.com>
> > 
> > This patch implements ACPI support to Microchip pac1921.
> > The driver can read the shunt resistor value and label from the
> > ACPI table.
> > 
> > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> > Signed-off-by: Victor Duicu <victor.duicu@microchip.com>
> > ---
> > 

....

> > 
> > 
> > +#define PAC1921_ACPI_GET_uOHMS_VALS             0
> > +#define PAC1921_ACPI_GET_LABEL                       1
> > +/*
> > + * The maximum acceptable shunt value is 2146.999999 OHM.
> > + * This value, which is below INT_MAX, was chosen in order to
> > + * allow the readings from dt and ACPI to share the same range
> > + * and to simplify the checks.
> > + * With this value the maximum current that can be read is
> > + * 0.1V / 2146.999999OHM = 46.576 uA
> > + * If we use INT_MAX the maximum current that can be read is
> > + * 0.1V / 2147.483647OHM = 46.566 uA
> > + * The relative error between the two values is
> > + * |(46.566 - 46.576) / 46.566| * 100 = 0.0214
> > + */
> > +#define PAC1921_MAX_SHUNT_VALUE_uOHMS                2146999999UL
> > +
> 
> Just a minor point about this: if I understand correctly that value
> comes from (INT_MAX / MICRO - 1) * MICRO + MAX_MICRO. This was to
> simplify the check in a single statement in
> pac1921_write_shunt_resistor()
> which is called when the shunt resistor is set from *sysfs* (neither
> from DT nor ACPI). I'm fine with this value and the new check but I
> find
> the explanation comment a bit confusing. If you could come up with a
> bit
> more clear explanation about the reason of such value I think it
> would be
> better otherwise I am fine with it as it is. Also, maybe use the full
> room
> for 80 characters per line and UOHMS instead of uOHMS to avoid mixed
> case if
> you are going with a new version.

We could completely remove the need to use a constant below INT_MAX
with this check in pac1921_write_shunt_resistor:

if ((!val && !val_fract) || 
((val >= INT_MAX / MICRO) && (val_fract > INT_MAX % MICRO)))
	return -EINVAL;

Do you agree with this approach?
Also, the use of mixed case was suggested by Andy to increase
readability.

...

> 
> 
> Best regards,
> Matteo Martelli

With Best Regards,
Duicu Victor

  reply	other threads:[~2024-11-14 12:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-14  8:47 [PATCH v11] iio: adc: pac1921: Add ACPI support to Microchip pac1921 victor.duicu
2024-11-14 11:00 ` Matteo Martelli
2024-11-14 12:52   ` Victor.Duicu [this message]
2024-11-14 13:43     ` Matteo Martelli
2024-11-23 16:25       ` Jonathan Cameron

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=faed3b586e1af2d946d3f9b185a94b6ebf0f6f32.camel@microchip.com \
    --to=victor.duicu@microchip.com \
    --cc=Marius.Cristea@microchip.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matteomartelli3@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