[PATCH v3 3/3] iio: adc: xilinx-ams: refactor alarm mapping to table-driven approach
Guilherme Ivo Bozi
guilherme.bozi at usp.br
Tue May 12 08:46:20 PDT 2026
Hi Salih,
On Tue, May 12, 2026 at 11:34 AM Salih Erim <salih.erim at amd.com> wrote:
>
> Hi,
>
> On 4/14/2026 11:40 PM, Guilherme Ivo Bozi wrote:
> > Replace multiple open-coded switch statements that map between
> > scan_index, alarm bits, and register offsets with a centralized
> > table-driven approach.
> >
> > Introduce a struct-based alarm_map to describe the relationship
> > between scan indices and alarm offsets, and add a helper to
> > translate scan_index to event IDs. This removes duplicated logic
> > across ams_get_alarm_offset(), ams_event_to_channel(), and
> > ams_get_alarm_mask().
> >
> > The new approach improves maintainability, reduces code size,
> > and makes it easier to extend or modify alarm mappings in the
> > future, while preserving existing behavior.
> >
> > Signed-off-by: Guilherme Ivo Bozi <guilherme.bozi at usp.br>
> > ---
> > drivers/iio/adc/xilinx-ams.c | 161 +++++++++++++----------------------
> > 1 file changed, 58 insertions(+), 103 deletions(-)
>
> Two issues:
>
> 1) Same tabs-vs-spaces indentation problem as patches 1 and 2.
>
> 2) In ams_event_to_channel():
>
> > + if (event < 0 || event >= ARRAY_SIZE(alarm_map))
> > + return NULL;
>
> The 'event' parameter is u32, so 'event < 0' is always false.
> Either drop the < 0 check or change the parameter type to int
> if you intend to handle negative values.
You are correct regarding the u32 type -- the event < 0 check is
unnecessary. I will remove it in the next revision.
>
> Salih
--
Guilherme Ivo
More information about the linux-arm-kernel
mailing list