From patchwork Fri Apr 14 16:40:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 9681439 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 2510660386 for ; Fri, 14 Apr 2017 16:51:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CCB7286CF for ; Fri, 14 Apr 2017 16:51:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F21B2286C7; Fri, 14 Apr 2017 16:51:22 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=no 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 5A040286C7 for ; Fri, 14 Apr 2017 16:51:22 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 9C284267202; Fri, 14 Apr 2017 18:41:08 +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 855532671F2; Fri, 14 Apr 2017 18:41:06 +0200 (CEST) Received: from mail-pf0-f176.google.com (mail-pf0-f176.google.com [209.85.192.176]) by alsa0.perex.cz (Postfix) with ESMTP id 0973026696B for ; Fri, 14 Apr 2017 18:41:02 +0200 (CEST) Received: by mail-pf0-f176.google.com with SMTP id 194so3293553pfv.3 for ; Fri, 14 Apr 2017 09:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fTzJ/vcDJatqgNP1JKDfOwDNlZiPKoluF/2DZPEOjh0=; b=mc2p9yOwSl5RVYnVg6JrWnmKMIerIeWXiwSCvjsiD2YfXckHM7Tmp5scnzkEPoWmwm qacKQGdwJ6mH8K95hVb2V3lbJgSMbMZiNXuNSKuxDXLptyPZ533fBQSacHkPCgVZtIGF IMi7yL1zIqL4a2xaaL1ZSLaB2Ofs+xhywqaJI= 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:in-reply-to :references; bh=fTzJ/vcDJatqgNP1JKDfOwDNlZiPKoluF/2DZPEOjh0=; b=MIm1mv8JnRxq6QcPAatotrYEKTSya5YzYHSngNthmAn/mtfnKFBPzl5OxIKYm3ODH4 h0tRWzzZVI01kMRO89EBpg3Y2G76xZEDryFdd1PfJ/1sAzm6/YXMRlMKltW6XBn8gs+t d+gVDpT17oJiFTWWdXQNBqmyo7C9YvlYegayrhkQF6KLZf4Trix89UxpFf7vprIWVzw7 tK1REvFjY+NCH9nXX1pcwOaCZoiRBxaypXmWgwCcTI7tNu5qEIrIkhNKv6eNDJQ0YzrG IUPqmd0c/+gdVR9sasq5zEonh0gso/+ZvKwrHsF/jpymmXouYItu01zJpDaohdpE9346 EtHg== X-Gm-Message-State: AN3rC/7Wi0w5imO5aveS+X77K07HpND/ckqjrq9XONQ2swzz63LhekSE nAUg16MWTxmyvepJ X-Received: by 10.98.3.135 with SMTP id 129mr7735270pfd.174.1492188061730; Fri, 14 Apr 2017 09:41:01 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by smtp.gmail.com with ESMTPSA id h25sm4206166pfk.119.2017.04.14.09.41.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Apr 2017 09:41:00 -0700 (PDT) From: Douglas Anderson To: bardliao@realtek.com, oder_chiou@realtek.com Date: Fri, 14 Apr 2017 09:40:31 -0700 Message-Id: <20170414164033.11681-2-dianders@chromium.org> X-Mailer: git-send-email 2.12.2.762.g0e3151a226-goog In-Reply-To: <20170414164033.11681-1-dianders@chromium.org> References: <20170414164033.11681-1-dianders@chromium.org> Cc: alsa-devel@alsa-project.org, Douglas Anderson , lgirdwood@gmail.com, linux-kernel@vger.kernel.org, tiwai@suse.com, broonie@kernel.org Subject: [alsa-devel] [PATCH 2/3] ASoC: rt5514: Avoid relying on uninitialized "val" value 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 rt5514_i2c_probe() if the regmap_read(RT5514_VENDOR_ID2) fails then "val" may be left as uninitialized. Current code relies on "val" not being RT5514_DEVICE_ID, but that's potentially unsafe. Let's check for errors from regmap_read() and also explicitly init the value do we're not passing a possibly uninitialized int to printk. Signed-off-by: Douglas Anderson --- sound/soc/codecs/rt5514.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index 481e77763fe4..969a05620e04 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -1090,7 +1090,7 @@ static int rt5514_i2c_probe(struct i2c_client *i2c, struct rt5514_platform_data *pdata = dev_get_platdata(&i2c->dev); struct rt5514_priv *rt5514; int ret; - unsigned int val; + unsigned int val = ~0; rt5514 = devm_kzalloc(&i2c->dev, sizeof(struct rt5514_priv), GFP_KERNEL); @@ -1120,8 +1120,8 @@ static int rt5514_i2c_probe(struct i2c_client *i2c, return ret; } - regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); - if (val != RT5514_DEVICE_ID) { + ret = regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); + if (ret || val != RT5514_DEVICE_ID) { dev_err(&i2c->dev, "Device with ID register %x is not rt5514\n", val); return -ENODEV;