OSDN Git Service

ALSA: control: Add input validation
authorTakashi Iwai <tiwai@suse.de>
Thu, 9 Jun 2022 12:02:19 +0000 (14:02 +0200)
committerTakashi Iwai <tiwai@suse.de>
Wed, 15 Jun 2022 05:45:28 +0000 (07:45 +0200)
commitf5e829f92a494a0b66d309497bab4e9d10d4ce3e
tree291439188b9d68267c060514dd02f86d924a4499
parent4e54316ad2485dedf8570fc2afa6fa6ce32db207
ALSA: control: Add input validation

This patch adds a new feature to enable the validation of input data
to control elements in the ALSA core side.  When
CONFIG_SND_CTL_INPUT_VALIDATION is set, ALSA core verifies whether the
each input value via control API is in the defined ranges, also checks
whether it's aligned to the defined steps.  If an invalid value is
detected, ALSA core returns -EINVAL error immediately without passing
further to the driver's callback.  So this is a kind of hardening for
(badly written) drivers that have no proper error checks, at the cost
of a slight performance overhead.

Technically seen, this reuses a part of the existing validation code
for CONFIG_SND_CTL_DEBUG case with a slight modification to suppress
error prints for the input validation.

Link: https://lore.kernel.org/r/20220609120219.3937-5-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/Kconfig
sound/core/control.c