From patchwork Tue Nov 8 08:11:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 9416865 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 09A9260459 for ; Tue, 8 Nov 2016 08:25:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE900289C1 for ; Tue, 8 Nov 2016 08:25:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1BF8289BC; Tue, 8 Nov 2016 08:25:47 +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 A0DA7289BC for ; Tue, 8 Nov 2016 08:25:46 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 1207F266EF1; Tue, 8 Nov 2016 09:25:45 +0100 (CET) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 37D9D266F00; Tue, 8 Nov 2016 09:23:23 +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 288D1266EFF; Tue, 8 Nov 2016 09:13:17 +0100 (CET) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by alsa0.perex.cz (Postfix) with ESMTP id D91C8266ED4 for ; Tue, 8 Nov 2016 09:13:11 +0100 (CET) Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id uA889fa3012406; Tue, 8 Nov 2016 09:13:11 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 26k7q0sa87-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 08 Nov 2016 09:13:11 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5F2E134; Tue, 8 Nov 2016 08:13:10 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 38EF02596; Tue, 8 Nov 2016 08:13:10 +0000 (GMT) Received: from localhost (10.201.23.162) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.294.0; Tue, 8 Nov 2016 09:13:10 +0100 From: Arnaud Pouliquen To: Takashi Sakamoto , , Charles Keepax , Vinod Koul Date: Tue, 8 Nov 2016 09:11:13 +0100 Message-ID: <1478592675-23092-3-git-send-email-arnaud.pouliquen@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1478592675-23092-1-git-send-email-arnaud.pouliquen@st.com> References: <1478592675-23092-1-git-send-email-arnaud.pouliquen@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.162] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-08_03:, , signatures=0 Cc: Takashi Iwai , broonie@kernel.org, lgirdwood@gmail.com Subject: [alsa-devel] [RFC 2/4] Alsa: control: increment index field for duplicated control. 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of returning an error when a control is already present, the index field is incremented and a warning message is printed. This allows drivers to instanciate same control without device and sub device number management ( MIXER type controls). Change-Id: Ifcc60dca9d1cf4c3a424bb9653296678aa7953cb Signed-off-by: Arnaud Pouliquen --- sound/core/control.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/sound/core/control.c b/sound/core/control.c index fb096cb..014e3f4 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -365,6 +365,7 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol) struct snd_ctl_elem_id id; unsigned int idx; unsigned int count; + struct snd_kcontrol *elem_set; int err = -EINVAL; if (! kcontrol) @@ -376,17 +377,24 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol) goto error; down_write(&card->controls_rwsem); - if (snd_ctl_find_id(card, &id)) { - up_write(&card->controls_rwsem); - dev_err(card->dev, "control %i:%i:%i:%s:%i is already present\n", - id.iface, - id.device, - id.subdevice, - id.name, - id.index); - err = -EBUSY; - goto error; + while (elem_set = snd_ctl_find_id(card, &id)) { + id.index++; + if (id.index > UINT_MAX - kcontrol->count) { + up_write(&card->controls_rwsem); + dev_err(card->dev, "no more free index for control %i:%i:%i:%s\n", + id.iface, id.device, id.subdevice, id.name); + err = -ENOSPC; + goto error; + } + } + if (kcontrol->id.index != id.index) { + dev_warn(card->dev, "control %i:%i:%i:%s:%i is already present\n", + id.iface, id.device, id.subdevice, id.name, id.index); + dev_warn(card->dev, "control index updated from %i to %i\n", + kcontrol->id.index, id.index); + kcontrol->id.index = id.index; } + if (snd_ctl_find_hole(card, kcontrol->count) < 0) { up_write(&card->controls_rwsem); err = -ENOMEM;