From patchwork Sun May 14 08:57:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 9725601 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 AABF6603F8 for ; Sun, 14 May 2017 09:12:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A733C27F95 for ; Sun, 14 May 2017 09:12:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93AEA2867D; Sun, 14 May 2017 09:12:28 +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 EAE18281E1 for ; Sun, 14 May 2017 09:12:27 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 85FBC267254; Sun, 14 May 2017 10:58:30 +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 7A2E726720A; Sun, 14 May 2017 10:58:24 +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 63A0A2668AC for ; Sun, 14 May 2017 10:58:06 +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; Sun, 14 May 2017 17:58:00 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp-proxy003.phy.lolipop.jp (LOLIPOP-Fsecure); Sun, 14 May 2017 17:57:56 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: clemens@ladisch.de, tiwai@suse.de, lars@metafoo.de Date: Sun, 14 May 2017 17:57:52 +0900 Message-Id: <20170514085756.22382-18-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170514085756.22382-1-o-takashi@sakamocchi.jp> References: <20170514085756.22382-1-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH RFC 17/21] ALSA: pcm: check type of parameter in added rule 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 Drivers can register rule of PCM parameters by a call of snd_pcm_hw_rule_add(). The rule includes a target parameter and dependent parameters. Basically, these parameters are the ones classified as mask or interval type. Although the helper function should check the variables, it actually doesn't. This brings extra check in rule application. This commit adds argument checker to the helper function. Unfortunately, snd_pcm_hw_constraint_msbits() pass -1 as its parameter type. This is because it's for non-mask/non-interval parameter. However, similar helper functions, i.e. snd_pcm_hw_constraint_ratdens(), uses the same value for target/dependent parameter. We can use SNDRV_PCM_HW_PARAM_SAMPLE_BITS for the parameter. Signed-off-by: Takashi Sakamoto --- sound/core/pcm_lib.c | 13 +++++++++---- sound/core/pcm_native.c | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 9659fa6..f699245 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -1146,6 +1146,10 @@ int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond, struct snd_pcm_hw_rule *c; unsigned int k; va_list args; + + if (!hw_is_mask(var) && !hw_is_interval(var)) + return -EINVAL; + va_start(args, dep); if (constrs->rules_num >= constrs->rules_all) { struct snd_pcm_hw_rule *new; @@ -1448,10 +1452,11 @@ int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime, unsigned int msbits) { unsigned long l = (msbits << 16) | width; - return snd_pcm_hw_rule_add(runtime, cond, -1, - snd_pcm_hw_rule_msbits, - (void*) l, - SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); + return snd_pcm_hw_rule_add(runtime, cond, + SNDRV_PCM_HW_PARAM_SAMPLE_BITS, + snd_pcm_hw_rule_msbits, + (void *) l, + SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); } EXPORT_SYMBOL(snd_pcm_hw_constraint_msbits); diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index ad71eb2..00d5aff 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -438,7 +438,7 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream, * in user space by returned bits, then preparing for next * iteration. */ - if (changed && r->var >= 0) { + if (changed) { params->cmask |= (1 << r->var); vstamps[r->var] = stamp; again = true;