Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Gabriel Rondon <grondon@gmail.com>,
	David Lechner <dlechner@baylibre.com>,
	Nuno Sa <nuno.sa@analog.com>, Andy Shevchenko <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: adc: ti-ads8688: use read_avail for available attributes
Date: Wed, 25 Mar 2026 19:42:27 +0000	[thread overview]
Message-ID: <20260325194227.5d112a85@jic23-huawei> (raw)
In-Reply-To: <acJ4sPoX_UqorDXS@ashevche-desk.local>

On Tue, 24 Mar 2026 13:42:40 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Mon, Mar 23, 2026 at 09:56:33PM +0000, Gabriel Rondon wrote:
> > Convert the in_voltage_scale_available and in_voltage_offset_available
> > attributes from legacy IIO_DEVICE_ATTR with custom show functions to the
> > IIO framework's read_avail callback. This uses the framework's built-in
> > support for _available attributes, removing the need for manual sysfs
> > formatting.
> > 
> > Precompute the available scale values at probe time since they depend on
> > the reference voltage which does not change after initialization.  
> 
> ...
> 
> > +static const int ads8688_offset_avail[] = {
> > +	-(1 << (ADS8688_REALBITS - 1)),  
> 
> This is fragile code (however it probably won't be exposed IRL)
> if ADS8688_REALBITS == 32 this is UB in accordance with C standard.
> 
> Also the trick with -BIT(x) is harder to read than simple GENMASK().
> If ADS8688_REALBITS == 1, this becomes -1 (all ones), is it correct?
> 
> > +	0,  

Replying here because the follow up lost too much context.
This is a classic offset for bipolar ADC, which is - half the full
range binary value.  So we won't hit the edge cases, but maybe
expressing it different will be clearer.

-(GENMASK(ADS8688_REALBITS - 1, 0) >> 1) does feel a bit overkill
but -GENMASK(ADS8688_REALBITS - 2, 0) feels under explained (much
like the current).

We 'could' use -(U16MAX >> 1) but that feels very specific to
it being 16 bits.

Maybe just leave this as it already is in the table the value
is copied from. 

      parent reply	other threads:[~2026-03-25 19:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 21:56 [PATCH] iio: adc: ti-ads8688: use read_avail for available attributes Gabriel Rondon
2026-03-24 11:42 ` Nuno Sá
2026-03-24 12:20   ` Gabriel Rondon
2026-03-24 12:24   ` Nuno Sá
2026-03-24 11:42 ` Andy Shevchenko
2026-03-24 12:19   ` Gabriel Rondon
2026-03-25 19:42   ` Jonathan Cameron [this message]

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=20260325194227.5d112a85@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=grondon@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.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