mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Gabriel Rondon <grondon@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	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: Tue, 24 Mar 2026 13:42:40 +0200	[thread overview]
Message-ID: <acJ4sPoX_UqorDXS@ashevche-desk.local> (raw)
In-Reply-To: <20260323215633.8140-1-grondon@gmail.com>

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,

Do not add trailing comma to a terminator.

>  };

...

> static const struct attribute_group ads8688_attribute_group = {

>  	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW)		\
>  			      | BIT(IIO_CHAN_INFO_SCALE)	\
>  			      | BIT(IIO_CHAN_INFO_OFFSET),	\
> +	.info_mask_shared_by_type_available =			\
> +			      BIT(IIO_CHAN_INFO_SCALE)		\
> +			      | BIT(IIO_CHAN_INFO_OFFSET),	\

This is actually slightly different style to what is put in the above.
Ideally should be unified, but probably matter for another change
(if even needed).

>  	.scan_index = index,					\
>  	.scan_type = {						\
>  		.sign = 'u',					\

>  }

...

> -	int ret;
> +	int ret, i;

Why is 'i' signed?

...


> +	for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) {

	for (unsigned int i = 0; i < ARRAY_SIZE(st->scale_avail); i++) {

should be good.

> +		st->scale_avail[i][0] = 0;

> +		st->scale_avail[i][1] = ads8688_range_def[i].scale *
> +					st->vref_mv;

I would leave this on a single line (it's only 81 characters).

> +	}

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2026-03-24 11:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 21:56 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 [this message]
2026-03-24 12:19   ` Gabriel Rondon
2026-03-25 19:42   ` 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=acJ4sPoX_UqorDXS@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=grondon@gmail.com \
    --cc=jic23@kernel.org \
    --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

all inboxes | Powered by JetHome®