From patchwork Wed Feb 11 10:40:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 5812031 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B4F679F30C for ; Wed, 11 Feb 2015 10:47:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EF77520109 for ; Wed, 11 Feb 2015 10:47:16 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id A1FBB20254 for ; Wed, 11 Feb 2015 10:47:15 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0ABF5264F33; Wed, 11 Feb 2015 11:47:14 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 2D277261ACE; Wed, 11 Feb 2015 11:43:55 +0100 (CET) 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 55909261A28; Wed, 11 Feb 2015 11:43:51 +0100 (CET) Received: from smtp311.phy.lolipop.jp (smtp311.phy.lolipop.jp [210.157.22.79]) by alsa0.perex.cz (Postfix) with ESMTP id D8728264FF9 for ; Wed, 11 Feb 2015 11:40:21 +0100 (CET) Received: from smtp311.phy.lolipop.lan (HELO smtp311.phy.lolipop.jp) (172.17.1.11) (smtp-auth username m12129643-o-takashi, mechanism plain) by smtp311.phy.lolipop.jp (qpsmtpd/0.82) with ESMTPA; Wed, 11 Feb 2015 19:40:19 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp311.phy.lolipop.jp (LOLIPOP-Fsecure); Wed, 11 Feb 2015 19:40:13 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: clemens@ladisch.de, tiwai@suse.de Date: Wed, 11 Feb 2015 19:40:11 +0900 Message-Id: <1423651213-19829-4-git-send-email-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1423651213-19829-1-git-send-email-o-takashi@sakamocchi.jp> References: <1423651213-19829-1-git-send-email-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH 3/5] ALSA: control: fix logic error about control count in a device 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 It's assumed that the number of userspace controls is just 1 in several parts, while this assumptions is not always true because the value of 'owner' member can be assigned to. This commit fixes this issue. Signed-off-by: Takashi Sakamoto --- sound/core/control.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sound/core/control.c b/sound/core/control.c index 1edd6c5..bce4730 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -514,6 +514,7 @@ static int snd_ctl_remove_user_ctl(struct snd_ctl_file * file, { struct snd_card *card = file->card; struct snd_kcontrol *kctl; + unsigned int count; int i, ret; down_write(&card->controls_rwsem); @@ -531,10 +532,11 @@ static int snd_ctl_remove_user_ctl(struct snd_ctl_file * file, ret = -EBUSY; goto error; } + count = kctl->count; ret = snd_ctl_remove(card, kctl); if (ret < 0) goto error; - card->user_ctl_count--; + card->user_ctl_count -= count; error: up_write(&card->controls_rwsem); return ret; @@ -1202,10 +1204,15 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file, return err; } - if (card->user_ctl_count >= MAX_USER_CONTROLS) - return -ENOMEM; + /* + * The number of controls with the same feature, distinguished by index. + */ + kctl.count = info->owner; + if (kctl.count == 0) + kctl.count = 1; + if (card->user_ctl_count + kctl.count > MAX_USER_CONTROLS) + return -ENOSPC; - kctl.count = info->owner ? info->owner : 1; if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) kctl.info = snd_ctl_elem_user_enum_info; else @@ -1259,7 +1266,7 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file, return err; down_write(&card->controls_rwsem); - card->user_ctl_count++; + card->user_ctl_count += _kctl->count; up_write(&card->controls_rwsem); return 0;