ASoC: Use snd_ctl_find_id_mixer() instead of open-coding
v2 cover ASoC: Use snd_ctl_find_id_mixer() instead of open-coding
The first two patches change snd_soc_card_get_kcontrol() to use the core snd_ctl_find_id_mixer() functionality instead of open-coding its own list walk.
The last patch adds a KUnit test for this, which was tested on the original and modified code.
Changes in V2:
Only change is in the KUnit test (patch #3) to make the const strings more consty.
Richard Fitzgerald (3):
ALSA: control: Introduce snd_ctl_find_id_mixer_locked()
ASoC: soc-card: Use snd_ctl_find_id_mixer() instead of open-coding
ASoC: soc-card: Add KUnit test case for snd_soc_card_get_kcontrol
include/sound/control.h | 23 +++++ sound/soc/Kconfig | 8 ++ sound/soc/Makefile | 4 + sound/soc/soc-card-test.c | 184 ++++++++++++++++++++++++++++++++++++++ sound/soc/soc-card.c | 21 +---- 5 files changed, 223 insertions(+), 17 deletions(-) create mode 100644 sound/soc/soc-card-test.c
Signature · 1 line
2.39.2
PATCH v2 1/3 ALSA: control: Introduce snd_ctl_find_id_mixer_locked()
Adds wrapper function snd_ctl_find_id_mixer_locked(). This is identical to snd_ctl_find_id_mixer() except that it can be called from code that is already holding controls_rwsem.
--- include/sound/control.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
include/sound/control.h +23 -0
@@ -167,6 +167,29 @@ snd_ctl_find_id_mixer(struct snd_card *card, const char *name)return snd_ctl_find_id (card, &id); } +/** +* snd_ctl_find_id_mixer_locked - find the control instance with the given name string +* @card: the card instance +* @name: the name string +* +* Finds the control instance with the given name and +* @SNDRV_CTL_ELEM_IFACE_MIXER. Other fields are set to zero. +* +* This is merely a wrapper to snd_ctl_find_id_locked(). +* The caller must down card->controls_rwsem before calling this function. +* +* Return: The pointer of the instance if found, or %NULL if not. +*/ +static inline struct snd_kcontrol * +snd_ctl_find_id_mixer_locked (struct snd_card *card,const char *name) +{ +struct snd_ctl_elem_id id = {}; + + id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; +strscpy (id.name, name,sizeof (id.name)); +return snd_ctl_find_id_locked (card, &id); +} +int snd_ctl_create (struct snd_card *card);int snd_ctl_register_ioctl (snd_kctl_ioctl_func_t fcn);
Signature · 1 line
2.39.2
PATCH v2 2/3 ASoC: soc-card: Use snd_ctl_find_id_mixer() instead of open-coding
In reply to Richard FitzgeraldUse the snd_ctl_find_id_mixer[_locked]() wrapper in snd_soc_card_get_kcontrol[_locked]() instead of open-coding a custom list walk of the card controls list.
--- sound/soc/soc-card.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
sound/soc/soc-card.c +4 -17
@@ -32,33 +32,20 @@ static inline int _soc_card_ret(struct snd_soc_card *card,struct snd_kcontrol *snd_soc_card_get_kcontrol_locked (struct snd_soc_card *soc_card,const char *name) { -struct snd_card *card = soc_card->snd_card; -struct snd_kcontrol *kctl; - -/* must be held read or write */ -lockdep_assert_held (&card->controls_rwsem); -if (unlikely (!name))return NULL ; -list_for_each_entry (kctl, &card->controls, list) -if (!strncmp (kctl->id.name, name,sizeof (kctl->id.name))) -return kctl; -return NULL ; +return snd_ctl_find_id_mixer_locked (soc_card->snd_card, name); }EXPORT_SYMBOL_GPL (snd_soc_card_get_kcontrol_locked);struct snd_kcontrol *snd_soc_card_get_kcontrol (struct snd_soc_card *soc_card,const char *name) { -struct snd_card *card = soc_card->snd_card; -struct snd_kcontrol *kctl; +if (unlikely (!name)) +return NULL ; -down_read (&card->controls_rwsem); - kctl =snd_soc_card_get_kcontrol_locked (soc_card, name); -up_read (&card->controls_rwsem); - -return kctl; +return snd_ctl_find_id_mixer (soc_card->snd_card, name); }EXPORT_SYMBOL_GPL (snd_soc_card_get_kcontrol);
Signature · 1 line
2.39.2
PATCH v2 3/3 ASoC: soc-card: Add KUnit test case for snd_soc_card_get_kcontrol
In reply to Richard FitzgeraldAdd a new snd-soc-card KUnit test with a simple test case for snd_soc_card_get_kcontrol() and snd_soc_card_get_kcontrol_locked().
--- sound/soc/Kconfig | 8 ++ sound/soc/Makefile | 4 + sound/soc/soc-card-test.c | 184 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 sound/soc/soc-card-test.c
sound/soc/Kconfig +8 -0
@@ -66,6 +66,14 @@ config SND_SOC_TOPOLOGY_KUNIT_TEST userspace applications such as pulseaudio, to prevent unnecessary problems. +config SND_SOC_CARD_KUNIT_TEST + tristate "KUnit tests for SoC card" + depends on KUNIT + default KUNIT_ALL_TESTS + help + If you want to perform tests on ALSA SoC card functions say Y here. + If unsure, say N. + config SND_SOC_UTILS_KUNIT_TEST tristate "KUnit tests for SoC utils" depends on KUNIT
sound/soc/Makefile +4 -0
@@ -12,6 +12,10 @@ ifneq ($(CONFIG_SND_SOC_TOPOLOGY_KUNIT_TEST),) obj-$(CONFIG_SND_SOC_TOPOLOGY_KUNIT_TEST) += soc-topology-test.o endif +ifneq ($(CONFIG_SND_SOC_CARD_KUNIT_TEST),) +obj-$(CONFIG_SND_SOC_CARD_KUNIT_TEST) += soc-card-test.o +endif + ifneq ($(CONFIG_SND_SOC_UTILS_KUNIT_TEST),) # snd-soc-test-objs := soc-utils-test.o obj-$(CONFIG_SND_SOC_UTILS_KUNIT_TEST) += soc-utils-test.o
sound/soc/soc-card-test.c new file +184 -0
184 lines not on this page · raw message
Signature · 1 line
2.39.2
Quoted 8 lines · Richard Fitzgerald
The first two patches change
snd_soc_card_get_kcontrol()to use the coresnd_ctl_find_id_mixer()functionality instead of open-coding its own list walk.The last patch adds a KUnit test for this, which was tested on the original and modified code.
Quoted 8 lines
Changes in V2:
Only change is in the KUnit test (patch #3) to make the const strings more consty.Richard Fitzgerald (3):
ALSA: control: Introducesnd_ctl_find_id_mixer_locked()
ASoC: soc-card: Usesnd_ctl_find_id_mixer()instead of open-coding
ASoC: soc-card: Add KUnit test case forsnd_soc_card_get_kcontrol
I suppose this goes via Mark's tree. Feel free to take my ack:
thanks,
Takashi
Mark Brown
maintainerQuoted 8 lines · Richard Fitzgerald
The first two patches change
snd_soc_card_get_kcontrol()to use the coresnd_ctl_find_id_mixer()functionality instead of open-coding its own list walk.The last patch adds a KUnit test for this, which was tested on the original and modified code.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/3] ALSA: control: Introduce snd_ctl_find_id_mixer_locked()
commit: 08ea486a61451189b190c7b89e406b889cf693fa
[2/3] ASoC: soc-card: Use snd_ctl_find_id_mixer() instead of open-coding
commit: 897cc72b08374c1224a9ded03c82dfc8e41f80c2
[3/3] ASoC: soc-card: Add KUnit test case for snd_soc_card_get_kcontrol
commit: ef7784e41db73f3d31ce545227ebba4483479a26All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark