From 18236ec9a48f180933ad07a10944d4a1acf60277 Mon Sep 17 00:00:00 2001 From: buque Date: Mon, 12 Dec 2022 12:39:27 +0800 Subject: [PATCH] alsa-mixer: avoid assertion at alsa-lib mixer API when element removal PulseAudio v5.99 or later hits assertion at alsa-lib mixer API due to wrong handling of removal event for mixer element. pulseaudio: mixer.c:149: hctl_elem_event_handler: Assertion `bag_empty(bag)' failed. The removal event is defined as '~0U', thus it's not distinguished from the other type of event just by bitwise operator. At the removal event, class implementator for mixer API should detach mixer element from hcontrol element in callback handler since alsa-lib has assertion to check the list of mixer elements for a hcontrol element is empty or not after calling all of handlers. In detail, please refer to MR to alsa-lib: * https://github.com/alsa-project/alsa-lib/pull/244 This commit fixes the above two issues. The issue can be regenerated by `samples/ctl` Python 3 script of alsa-gobject. * https://github.com/alsa-project/alsa-gobject/ It adds some user-defined elements into sound card 0. When terminated by SIGINT signal, it removes the elements. Then PulseAudio dies due to the assertion. Fixes: 1fd8848e64cf ("alsa-util: Add functions for accessing mixer elements through mixer class") Part-of: --- ...-assertion-at-alsa-lib-mixer-API-whe.patch | 59 +++++++++++++++++++ pulseaudio.spec | 4 ++ 2 files changed, 63 insertions(+) create mode 100644 0001-alsa-mixer-avoid-assertion-at-alsa-lib-mixer-API-whe.patch diff --git a/0001-alsa-mixer-avoid-assertion-at-alsa-lib-mixer-API-whe.patch b/0001-alsa-mixer-avoid-assertion-at-alsa-lib-mixer-API-whe.patch new file mode 100644 index 0000000..29a8de2 --- /dev/null +++ b/0001-alsa-mixer-avoid-assertion-at-alsa-lib-mixer-API-whe.patch @@ -0,0 +1,59 @@ +From 4bdf4c99662f3da0e58d6c04bafff95d84362922 Mon Sep 17 00:00:00 2001 +From: Takashi Sakamoto +Date: Mon, 27 Jun 2022 10:09:52 +0900 +Subject: [PATCH] alsa-mixer: avoid assertion at alsa-lib mixer API when + element removal + +PulseAudio v5.99 or later hits assertion at alsa-lib mixer API due to +wrong handling of removal event for mixer element. + +pulseaudio: mixer.c:149: hctl_elem_event_handler: Assertion `bag_empty(bag)' failed. + +The removal event is defined as '~0U', thus it's not distinguished from +the other type of event just by bitwise operator. + +At the removal event, class implementator for mixer API should detach +mixer element from hcontrol element in callback handler since alsa-lib +has assertion to check the list of mixer elements for a hcontrol element +is empty or not after calling all of handlers. In detail, please refer to +MR to alsa-lib: + + * https://github.com/alsa-project/alsa-lib/pull/244 + +This commit fixes the above two issues. The issue can be regenerated by +`samples/ctl` Python 3 script of alsa-gobject. + + * https://github.com/alsa-project/alsa-gobject/ + +It adds some user-defined elements into sound card 0. When terminated by +SIGINT signal, it removes the elements. Then PulseAudio dies due to the +assertion. + +Fixes: 1fd8848e64cf ("alsa-util: Add functions for accessing mixer elements through mixer class") +Part-of: +--- + src/modules/alsa/alsa-util.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c +index 7dc373fa0..f4e838d37 100644 +--- a/src/modules/alsa/alsa-util.c ++++ b/src/modules/alsa/alsa-util.c +@@ -1654,7 +1654,13 @@ static int mixer_class_event(snd_mixer_class_t *class, unsigned int mask, + { + int err; + const char *name = snd_hctl_elem_get_name(helem); +- if (mask & SND_CTL_EVENT_MASK_ADD) { ++ /* NOTE: The remove event is defined as '~0U`. */ ++ if (mask == SND_CTL_EVENT_MASK_REMOVE) { ++ /* NOTE: Unless we remove the pointer to melem from the linked-list at ++ * private_data of helem, an assertion will be hit in alsa-lib since ++ * the list is not empty. */ ++ snd_mixer_elem_detach(melem, helem); ++ } else if (mask & SND_CTL_EVENT_MASK_ADD) { + snd_ctl_elem_iface_t iface = snd_hctl_elem_get_interface(helem); + if (iface == SND_CTL_ELEM_IFACE_CARD || iface == SND_CTL_ELEM_IFACE_PCM) { + snd_mixer_elem_t *new_melem; +-- +2.33.0 + diff --git a/pulseaudio.spec b/pulseaudio.spec index 9ccf0c5..bda7578 100644 --- a/pulseaudio.spec +++ b/pulseaudio.spec @@ -15,6 +15,7 @@ Source5: default.pa-for-gdm Patch201: pulseaudio-autostart.patch Patch1001: 0001-Fix-the-problem-that-the-description-field-of-pa_als.patch +Patch1002: 0001-alsa-mixer-avoid-assertion-at-alsa-lib-mixer-API-whe.patch BuildRequires: meson BuildRequires: automake libtool gcc-c++ bash-completion @@ -242,6 +243,9 @@ exit 0 %{_mandir}/man*/* %changelog +* Mon Dec 12 2022 wuxu - 16.1-4 +- alsa-mixer: avoid assertion at alsa-lib mixer API when element removal + * Tue Oct 18 2022 Liu Zixian - 16.1-4 - delete unused BuildRequires -- Gitee