From patchwork Fri Aug 8 15:29:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 4697111 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A23249F377 for ; Fri, 8 Aug 2014 15:53:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D6AB120160 for ; Fri, 8 Aug 2014 15:53:53 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 971C820109 for ; Fri, 8 Aug 2014 15:53:52 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0F6DA2652C1; Fri, 8 Aug 2014 17:53:48 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: 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 BB55B265056; Fri, 8 Aug 2014 17:53:38 +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 B157426514B; Fri, 8 Aug 2014 17:29:49 +0200 (CEST) Received: from michel.telenet-ops.be (michel.telenet-ops.be [195.130.137.88]) by alsa0.perex.cz (Postfix) with ESMTP id A6C2E2650E1 for ; Fri, 8 Aug 2014 17:29:41 +0200 (CEST) Received: from ayla.of.borg ([84.193.84.167]) by michel.telenet-ops.be with bizsmtp id cFVe1o00D3cczKo06FVeCh; Fri, 08 Aug 2014 17:29:41 +0200 Received: from geert by ayla.of.borg with local (Exim 4.76) (envelope-from ) id 1XFm6q-0006tj-M9; Fri, 08 Aug 2014 17:29:36 +0200 From: Geert Uytterhoeven To: Lars-Peter Clausen , Liam Girdwood , Mark Brown Date: Fri, 8 Aug 2014 17:29:35 +0200 Message-Id: <1407511775-26479-1-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.7.9.5 X-Mailman-Approved-At: Fri, 08 Aug 2014 17:53:37 +0200 Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [alsa-devel] [PATCH] ASoC: dapm: Fix uninitialized variable in snd_soc_dapm_get_enum_double() 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 If soc_dapm_read() fails, reg_val will be uninitialized, and bogus values will be written later: sound/soc/soc-dapm.c: In function 'snd_soc_dapm_get_enum_double': sound/soc/soc-dapm.c:2862:15: warning: 'reg_val' may be used uninitialized in this function [-Wmaybe-uninitialized] unsigned int reg_val, val; ^ Return early on error to fix this. Introduced by commit ce0fc93ae56e2ba50ff8c220d69e4e860e889320 ("ASoC: Add DAPM support at the component level"). Acked-by: Lars-Peter Clausen --- Is this correct? Please review. Signed-off-by: Geert Uytterhoeven --- sound/soc/soc-dapm.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 8348352dc2c6..177bd8639ef9 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -2860,12 +2860,14 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; unsigned int reg_val, val; - int ret = 0; - if (e->reg != SND_SOC_NOPM) - ret = soc_dapm_read(dapm, e->reg, ®_val); - else + if (e->reg != SND_SOC_NOPM) { + int ret = soc_dapm_read(dapm, e->reg, ®_val); + if (ret) + return ret; + } else { reg_val = dapm_kcontrol_get_value(kcontrol); + } val = (reg_val >> e->shift_l) & e->mask; ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val); @@ -2875,7 +2877,7 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, ucontrol->value.enumerated.item[1] = val; } - return ret; + return 0; } EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);