Re: [PATCH] ALSA: core: Validate card indices in lookup helpers
From: Takashi Iwai
Date: Tue Nov 17 2026 - 10:03:14 EST
On Tue, 17 Nov 2026 11:41:54 +0100,
Sreeraj S Kurup wrote:
>
> Ensure card indices are within the valid range before accessing
> the card array or lock bitmap in snd_card_ref() and
> snd_card_locked().
>
> This prevents out-of-range indices from causing invalid memory
> accesses in these lookup helpers. It also protects against
> invalid indices passed by existing or future callers.
>
> Return NULL from snd_card_ref() and 0 from snd_card_locked()
> when an invalid card index is supplied.
>
> Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@xxxxxxxxx>
If the value is out of range, it must be a bug in the driver, so this
is worth for putting either WARN_ON() or snd_BUG_ON().
thanks,
Takashi