devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: Alexandru Ardelean <aardelean@baylibre.com>,
	David Lechner <dlechner@baylibre.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	 devicetree@vger.kernel.org, jic23@kernel.org,
	krzk+dt@kernel.org, robh@kernel.org, 	lars@metafoo.de,
	michael.hennerich@analog.com, gstols@baylibre.com, brgl@bgdev.pl
Subject: Re: [PATCH 2/6] iio: adc: ad7606: fix issue/quirk with find_closest() for oversampling
Date: Tue, 22 Oct 2024 10:24:33 +0200	[thread overview]
Message-ID: <41c6f424ed42655a62a7b66aa81604605676a551.camel@gmail.com> (raw)
In-Reply-To: <CA+GgBR-8i-S2gnp39TnOxayfGqLpdhAceOjNDpE+Y7t_5Xeaig@mail.gmail.com>

On Tue, 2024-10-22 at 09:31 +0300, Alexandru Ardelean wrote:
> On Mon, Oct 21, 2024 at 10:31 PM David Lechner <dlechner@baylibre.com> wrote:
> > 
> > On 10/21/24 2:03 PM, David Lechner wrote:
> > > On 10/21/24 8:02 AM, Alexandru Ardelean wrote:
> > > > There's a small issue with setting oversampling-ratio that seems to have
> > > > been there since the driver was in staging.
> > > > Trying to set an oversampling value of '2' will set an oversampling
> > > > value
> > > > of '1'. This is because find_closest() does an average + rounding of 1 +
> > > > 2,
> > > > and we get '1'.
> > > > 
> > > > This is the only issue with find_closest(), at least in this setup. The
> > > > other values (above 2) work reasonably well. Setting 3, rounds to 2, so
> > > > a
> > > > quick fix is to round 'val' to 3 (if userspace provides 2).
> > > 
> > > This sounds like a bug in find_closest() instead of in this driver.
> > > 
> 
> Adding Bart (the original author of find_closest()).
> 
> > > If there is an exact match in the list, it seems reasonable to expect
> > > that the exact match is returned by find_closest().
> > > 
> > 
> > Likely also affected by this bug since they have values 1, 2 in the list:
> > 
> > * rtq6056_adc_set_average()
> > * si1133_scale_to_swgain()
> 
> Yeah.
> I forgot to mention this sooner.
> But this patch is more of an RFC patch about how to handle this
> situation with find_closest().
> 
> For monotonic values with an increment of 1, find_closest() is a bit buggy.
> Will try to fix find_closest()
> 
> > 

FWIW, I'm not a fan of using find_closest() in this situation. We have an
available attr wich outputs the supported values. To me, -EINVAL is the way to
go if some user writes an invalid value.

I feel the usage of find_closest() in these case is likely to make the code
easier. Maybe an helper analogous to match_string() would be seen with good eyes
(like match_value()).

But yeah, I guess that changing the behavior now could break some userspace
users.

- Nuno Sá

  reply	other threads:[~2024-10-22  8:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-21 13:02 [PATCH 0/6] iio: adc: ad7606: add support for AD760{7,8,9} parts Alexandru Ardelean
2024-10-21 13:02 ` [PATCH 1/6] iio: adc: ad7606: fix/persist oversampling_ratio setting Alexandru Ardelean
2024-10-21 13:02 ` [PATCH 2/6] iio: adc: ad7606: fix issue/quirk with find_closest() for oversampling Alexandru Ardelean
2024-10-21 19:03   ` David Lechner
2024-10-21 19:31     ` David Lechner
2024-10-22  6:31       ` Alexandru Ardelean
2024-10-22  8:24         ` Nuno Sá [this message]
2024-10-21 13:02 ` [PATCH 3/6] iio: adc: ad7606: use realbits for sign-extending in scan_direct Alexandru Ardelean
2024-10-21 17:19   ` David Lechner
2024-10-22  6:09     ` Alexandru Ardelean
2024-10-21 13:02 ` [PATCH 4/6] iio: adc: ad7606: rework scale-available to be static Alexandru Ardelean
2024-10-21 18:17   ` David Lechner
2024-10-22  6:59     ` Alexandru Ardelean
2024-10-22  8:28       ` Nuno Sá
2024-10-21 13:02 ` [PATCH 5/6] dt-bindings: iio: adc: adi,ad7606: document AD760{7,8,9} parts Alexandru Ardelean
2024-10-21 16:52   ` Conor Dooley
2024-10-21 13:02 ` [PATCH 6/6] iio: adc: ad7606: add support for " Alexandru Ardelean

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=41c6f424ed42655a62a7b66aa81604605676a551.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=aardelean@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=gstols@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.hennerich@analog.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).