Re: [PATCH 16/18] iio: adc: ad4170-4: Drop ad4170_iout_pin_tbl
From: Andy Shevchenko
Date: Thu Dec 03 2026 - 12:21:32 EST
On Thu, Dec 03, 2026 at 04:19:56PM +0100, Janani Sunil wrote:
> The valid CURRENT_SOURCEn I_OUT_PIN values are the analog input pins and
> GPIO0 to GPIO3, which are two contiguous ranges. Check them directly
> instead of looking the pin up in a table listing every value, and check
> the pin availability in the same branch that identifies the pin type.
>
> This prepares for devices with a different number of analog input pins,
> for which a fixed table of valid pins would no longer fit.
>
> No functional change intended.
...
> + } else if (in_range(pin, AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(0),
> + AD4170_NUM_GPIO_PINS)) {
While works in this case in_range() doesn't make code read better.
I think traditional two-way comparison is preferred.
...
> unsigned int gpio = pin - AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(0);
>
> if (st->gpio_fn[gpio] != AD4170_GPIO_UNASSIGNED)
> st->gpio_fn[gpio] |= AD4170_GPIO_AC_EXCITATION;
> + return 0;
> }
>
> - return 0;
> + return dev_err_probe(dev, -EINVAL, "Invalid excitation pin: %u\n", pin);
Can you rearrange the code to return an error from inside the branch?
--
With Best Regards,
Andy Shevchenko