From patchwork Fri Jan 4 21:52:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yizhuo Zhai X-Patchwork-Id: 10750047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB26C14DE for ; Mon, 7 Jan 2019 07:07:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8EBF28712 for ; Mon, 7 Jan 2019 07:07:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD04C28882; Mon, 7 Jan 2019 07:07:48 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 1097428712 for ; Mon, 7 Jan 2019 07:07:48 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 1EFC0267B2D; Mon, 7 Jan 2019 08:07:10 +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 9CA35267C4B; Fri, 4 Jan 2019 22:53:48 +0100 (CET) Received: from mx2.ucr.edu (mx2.ucr.edu [138.23.62.3]) by alsa0.perex.cz (Postfix) with ESMTP id 27177267C4B for ; Fri, 4 Jan 2019 22:53:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=ucr.edu; i=@ucr.edu;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; d="scan'208";a="1053079735" Received: from mail-pl1-f199.google.com ([209.85.214.199]) by smtp2.ucr.edu with ESMTP/TLS/AES128-GCM-SHA256; 04 Jan 2019 13:53:15 -0800 Received: by mail-pl1-f199.google.com with SMTP id m13so27951392pls.15 for ; Fri, 04 Jan 2019 13:53:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bcRpBh4xAw+MYqTUT9pUoObzqTgSOzqrk5i6PSdJQ1U=; b=SqJOSZ6L2ust7ymkXwdm0SuiKVQaCucueDxDspBZIOaLIGsKVcYsQP/jQoPN09J8nz lKvnlPsFZ9302Eobk28TTA3ah2+iRYCm7INoVdO4tZgpQUXEJsm1Pkexnj7oZe+TNBBy JZQhvjZJm9GpPNDCe78E+XisVS05k2m8DPauJ9v4wBnV6Wi9TMjNwSW2+dXKVpSff+0n 3/rYudXSBBBCrHSuXKNXhkIn4dY6lOuqjmzaiEungjEHaY0kd4do9TKTkdW371ZJMNyx eGADr9WtUaQwsKouiSBFfEtXPIE6Gu8c4iYM5NGJXS3RGCZg7RYm6uL4cfqikWmu+Z0n 6Rjw== X-Gm-Message-State: AJcUukdTdNyMDQ0c1B4AfJRlXNo9FoZa+iZq0N90jbNJ8/b+W4i/XHqK 7oLDMxm38fLCpyEJk69ObsxOJMPnHq1rDmWIz/zRb8Bz+TONiSKhHCoCBFhczPDQs0/iZplUfLv D9IWac/UaKctJMOV+/IjljAWi X-Received: by 2002:a63:d846:: with SMTP id k6mr3080467pgj.251.1546638795416; Fri, 04 Jan 2019 13:53:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN5swTgGXISJ+vGT9ltDwNeGss8juMTdHAkURLQsR7b8FeKi18ieZS3LPwnvrVWgKQf6CKQfQQ== X-Received: by 2002:a63:d846:: with SMTP id k6mr3080448pgj.251.1546638794871; Fri, 04 Jan 2019 13:53:14 -0800 (PST) Received: from Yizhuo.cs.ucr.edu (yizhuo.cs.ucr.edu. [169.235.26.74]) by smtp.googlemail.com with ESMTPSA id h79sm118115071pfj.186.2019.01.04.13.53.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jan 2019 13:53:13 -0800 (PST) From: Yizhuo To: Date: Fri, 4 Jan 2019 13:52:53 -0800 Message-Id: <20190104215253.16278-1-yzhai003@ucr.edu> X-Mailer: git-send-email 2.17.1 X-Mailman-Approved-At: Mon, 07 Jan 2019 08:06:57 +0100 Cc: csong@cs.ucr.edu, Oder Chiou , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Takashi Iwai , zhiyunq@cs.ucr.edu, Liam Girdwood , Yizhuo , Mark Brown , Bard Liao Subject: [alsa-devel] [PATCH] ASoC: rt298: Variable "val" and "buf" in rt298_jack_detect() could be uninitialized 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 function rt298_jack_detect(), local variable "val" and "buf" are supposed to get initialized by regmap_read(). However, they could be leave uninitialized if regmap_read() returns -EINVAL. Those two variables are used in control flow or update the argument, which could lead to undefined behavior and thus unsafe. Signed-off-by: Yizhuo --- sound/soc/codecs/rt298.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/rt298.c b/sound/soc/codecs/rt298.c index ce963768449f..7f74349c17f3 100644 --- a/sound/soc/codecs/rt298.c +++ b/sound/soc/codecs/rt298.c @@ -223,6 +223,7 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) { struct snd_soc_dapm_context *dapm; unsigned int val, buf; + int ret = 0; *hp = false; *mic = false; @@ -233,7 +234,10 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) dapm = snd_soc_codec_get_dapm(rt298->codec); if (rt298->pdata.cbj_en) { - regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + ret = regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + if (ret) + return ret; + *hp = buf & 0x80000000; if (*hp == rt298->is_hp_in) return -1; @@ -260,16 +264,19 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) regmap_update_bits(rt298->regmap, RT298_CBJ_CTRL1, 0xfcc0, 0xd400); msleep(300); - regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val); - + ret = regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val); + if (ret) + return ret; if (0x0070 == (val & 0x0070)) { *mic = true; } else { regmap_update_bits(rt298->regmap, RT298_CBJ_CTRL1, 0xfcc0, 0xe400); msleep(300); - regmap_read(rt298->regmap, + ret = regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val); + if (ret) + return ret; if (0x0070 == (val & 0x0070)) *mic = true; else @@ -285,9 +292,14 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) RT298_CBJ_CTRL1, 0x0400, 0x0000); } } else { - regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + ret = regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + if (ret) + return ret; + *hp = buf & 0x80000000; - regmap_read(rt298->regmap, RT298_GET_MIC1_SENSE, &buf); + ret = regmap_read(rt298->regmap, RT298_GET_MIC1_SENSE, &buf); + if (ret) + return ret; *mic = buf & 0x80000000; }