public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matteo Martelli <matteomartelli3@gmail.com>
To: Victor.Duicu@microchip.com, andy.shevchenko@gmail.com,
	jic23@kernel.org, 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 14:43:11 +0100	[thread overview]
Message-ID: <c67cd8be57b54b792430fd56a57a3ee1@gmail.com> (raw)
In-Reply-To: <faed3b586e1af2d946d3f9b185a94b6ebf0f6f32.camel@microchip.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3521 bytes --]

On Thu, 14 Nov 2024 12:52:12 +0000, <Victor.Duicu@microchip.com> wrote:
> 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?

Yes, something like this would be clearer to me.

Anyway, I think you also need to check for val > INT_MAX / MICRO when
val_fract is < INT_MAX % MICRO, right?

Also, I think you can remove a couple of parenthesis.

So something like the following maybe (but please double check it):

	if ((!val && !val_fract) || val > INT_MAX / MICRO ||
	   (val == INT_MAX / MICRO && val_fract > INT_MAX % MICRO))

I think that usually it would be better to use pre-computed constants
instead of run-time divisions for efficiency but since the shunt
resistor is likely going to be set rarely, I would go for this code for
better clarity.


> Also, the use of mixed case was suggested by Andy to increase
> readability.

Ah, sorry for missing Andy's comment. I am fine with it if you also find
it more readable.

> 
> ...
> 
> > 
> > 
> > Best regards,
> > Matteo Martelli
> 
> With Best Regards,
> Duicu Victor

Thanks,
Matteo Martelli

  reply	other threads:[~2024-11-14 13:43 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
2024-11-14 13:43     ` Matteo Martelli [this message]
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=c67cd8be57b54b792430fd56a57a3ee1@gmail.com \
    --to=matteomartelli3@gmail.com \
    --cc=Marius.Cristea@microchip.com \
    --cc=Victor.Duicu@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 \
    /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