[PATCH v3 3/3] iio: adc: xilinx-ams: refactor alarm mapping to table-driven approach
Salih Erim
salih.erim at amd.com
Tue May 12 07:34:13 PDT 2026
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.
Salih
More information about the linux-arm-kernel
mailing list