From patchwork Sun Jul 10 15:12:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 9222689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C8432604DB for ; Sun, 10 Jul 2016 15:13:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEFAA23861 for ; Sun, 10 Jul 2016 15:13:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2A2F264F4; Sun, 10 Jul 2016 15:13:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67E6723861 for ; Sun, 10 Jul 2016 15:13:05 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 527AC265312; Sun, 10 Jul 2016 17:12:58 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 4BA7A261490; Sun, 10 Jul 2016 17:12:51 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 136752614E3; Sun, 10 Jul 2016 17:12:48 +0200 (CEST) Received: from smtp-proxy003.phy.lolipop.jp (smtp-proxy003.phy.lolipop.jp [157.7.104.44]) by alsa0.perex.cz (Postfix) with ESMTP id C6DB3260617 for ; Sun, 10 Jul 2016 17:12:42 +0200 (CEST) Received: from smtp-proxy003.phy.lolipop.lan (HELO smtp-proxy003.phy.lolipop.jp) (172.19.44.44) (smtp-auth username m12129643-o-takashi, mechanism plain) by smtp-proxy003.phy.lolipop.jp (qpsmtpd/0.82) with ESMTPA; Mon, 11 Jul 2016 00:12:39 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp-proxy003.phy.lolipop.jp (LOLIPOP-Fsecure); Mon, 11 Jul 2016 00:12:35 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: tiwai@suse.de Date: Mon, 11 Jul 2016 00:12:34 +0900 Message-Id: <1468163554-22826-1-git-send-email-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.7.4 Cc: alsa-devel@alsa-project.org, pulseaudio-discuss@lists.freedesktop.org Subject: [alsa-devel] [alsa-lib][PATCH] hctl: remove assertion from element event handler because removal event overwrites all of queued events X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP In ALSA control core, when several events occurs for an element, they're represented bit mask (struct snd_ctl_event.data.elem.mask). Thus userspace applications can handles these events separately in one I/O operation. There's an exception; removal event. This is represented by all of bits in the mask. Therefore, when a removal event occurs for an element, all of queued events for the element are overwritten. This works worse for a combination of applications which add/remove control elements and applications which keep a cache of elements. For example, let's assume a case that: 1.some elements are added by ioctl(SNDRV_CTL_IOCTL_ELEM_ADD). 2.ALSA control core handles the request and queues 'add' event. 3.applications don't read the event yet. 4.the elements are removed by ioctl(SNDRV_CTL_IOCTL_ELEM_REMOVE) 5.ALSA control core handles the request and queues 'removal' event by overwriting queued events. 6.applications read the event at last. 7.the applications cannot find removed elements in their cache data. Especially, when applications use hctl interface of ALSA userspace library, this situation occurs because the interface is designed to keep element cache implicitly inner the library. PulseAudio is such an application. When executing a test program of ALSA library (test/user-ctl-element-set.c), pulseaudio process aborts due to assertion at calls of snd_hctl_handle_events(). The rule to represent events is in ALSA kernel/userspace interfaces (UAPI header) and it's difficult to improve the rule. Therefore, developers should pay enough attention to the fact that userspace applications can receive removal events for elements which are not notified with 'add' event. For this reason, this commit removes assertion from event handler of ALSA hctl API. CC: pulseaudio-discuss@lists.freedesktop.org Signed-off-by: Takashi Sakamoto --- src/control/hcontrol.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/control/hcontrol.c b/src/control/hcontrol.c index 7645c57..c40a807 100644 --- a/src/control/hcontrol.c +++ b/src/control/hcontrol.c @@ -742,7 +742,6 @@ static int snd_hctl_handle_event(snd_hctl_t *hctl, snd_ctl_event_t *event) if (event->data.elem.mask == SNDRV_CTL_EVENT_MASK_REMOVE) { int dir; res = _snd_hctl_find_elem(hctl, &event->data.elem.id, &dir); - assert(res >= 0 && dir == 0); if (res < 0 || dir != 0) return -ENOENT; snd_hctl_elem_remove(hctl, (unsigned int) res);