From patchwork Mon Mar 14 14:49:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 8581181 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 69B5BC0553 for ; Mon, 14 Mar 2016 16:00:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C97B8203B4 for ; Mon, 14 Mar 2016 16:00:31 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 9C185203A4 for ; Mon, 14 Mar 2016 16:00:29 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 785A1265906; Mon, 14 Mar 2016 17:00:28 +0100 (CET) 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, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id DFF372652CE; Mon, 14 Mar 2016 16:26:37 +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 4C2572652CE; Mon, 14 Mar 2016 16:26:36 +0100 (CET) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.134]) by alsa0.perex.cz (Postfix) with ESMTP id F067C265A28 for ; Mon, 14 Mar 2016 15:50:38 +0100 (CET) Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue005) with ESMTPA (Nemesis) id 0LyPw2-1ZiTLB09eY-015ucq; Mon, 14 Mar 2016 15:50:27 +0100 From: Arnd Bergmann To: Mark Brown Date: Mon, 14 Mar 2016 15:49:54 +0100 Message-Id: <1457967019-3901380-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:AKb959CEoabO/7mFhYvSiEduUt0A/Dxu3Py4XXs1usWnW239b4r XRkW/Md5T66QgaYGlFLrBAE7Xja7d554BmYihfAM5d//Hq7JFa4o3Dnaql/d5sZchWBCJ5I i+GEPCShYLZ7jVN7y/x76X7Xuwk/8N/ScELLNikxSRh1VElvsI4kRaVd80t5y0PDDHBarBG /24eOQ1FSyr2q6VQ5stmw== X-UI-Out-Filterresults: notjunk:1; V01:K0:fE1pW0+X05k=:sRmX9riy6MzvbrokZYJUbh hnVqEpE8NJVSDop9WCHP289RCfmyJV7k9cvGmByUsjxrvuBa1SSCgd1tRYHQkZO+a2FgJk57L r4PgyKQnJkH668kEJxewL2ODegQJBUjDMCaqkc4JdZsOPy82brieKK5CzXXMZ6jIKb9F8P9T7 YjjJ1LXhaA4LUKuOq8EZApHQr6q6DigErwoqbltdjyDZkS+IqMShXi+yBf7TxCo+3x/FQ/ArW sqO7dhcJbvhJW09y8K3cLiLe1HkNZt+2Gz9lSgjE4No6M73SNartNJKtG4K68Cl52n3qAhXOW o+71xouMPSwt8aohPdEzYz8RbWtQ3dA0wNrM4F3I/4nWo2OCySKdwUzeWn2Pfae4m4EyjSeDU b3l2vGoDfGt0fIt3NWO8NC+GoksPcNS+psu72II8NS5lkKRCdYDgLkzvZ8MHO2QRWW9k3dPLa cvjcIebV/qMaDJgc9e5ScYDSRp14dVaYTmrV5B8VxCPfBsHK6IpR/dLywZHvyU0c0qhW0Z0Mo 8cpvA6vJcuK8DCZiA+pET31X1baq1OtLuimjFbwj9ogQAEuSLxT2QaGQUueuqxCN9huooQDx/ lLXeGN52zmjuza7NZN1PO+s6lARTAlkFgQuLJEfWUjKDONWrgIsnhU1VQMydKJl5HvY7nnSNe u8phiZOkXuVMHknx0Kjot+t08UGOKEVO+pBZpGwLlfP5jl9xt6XjLostIBktnqzh2TMo= Cc: Brian Austin , Axel Lin , Arnd Bergmann , Liam Girdwood , linux-kernel@vger.kernel.org, Takashi Iwai , Paul Handrigan , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH v3] ASoC: cs35l32: avoid uninitialized variable access 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 gcc warns about the possibilty of accessing a property read from devicetree in cs35l32_i2c_probe() when it has not been initialized because CONFIG_OF is disabled: sound/soc/codecs/cs35l32.c: In function 'cs35l32_i2c_probe': sound/soc/codecs/cs35l32.c:278:2: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized] The code is actually correct because it checks the dev->of_node variable first and we know this is NULL here when CONFIG_OF is disabled, but Russell King noticed that it's broken when we probe the device using DT, and the properties are absent. The code already has some checking for incorrect values, and I keep that checking unchanged here, but add an additional check for an error returned by the property accessor functions that now gets handled the same way as incorrect data in the properties. Signed-off-by: Arnd Bergmann Acked-by: Brian Austin --- v3: Restore a line that was accidentally removed, as pointed out by Brian Austin. v2: fix bug in case of CONFIG_OF and missing properties v1: only address warning for the !CONFIG_OF case sound/soc/codecs/cs35l32.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/cs35l32.c b/sound/soc/codecs/cs35l32.c index 44c30fe3e315..287d13740be4 100644 --- a/sound/soc/codecs/cs35l32.c +++ b/sound/soc/codecs/cs35l32.c @@ -274,7 +274,9 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client, if (of_property_read_u32(np, "cirrus,sdout-share", &val) >= 0) pdata->sdout_share = val; - of_property_read_u32(np, "cirrus,boost-manager", &val); + if (of_property_read_u32(np, "cirrus,boost-manager", &val)) + val = -1u; + switch (val) { case CS35L32_BOOST_MGR_AUTO: case CS35L32_BOOST_MGR_AUTO_AUDIO: @@ -282,13 +284,15 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client, case CS35L32_BOOST_MGR_FIXED: pdata->boost_mng = val; break; + case -1u: default: dev_err(&i2c_client->dev, "Wrong cirrus,boost-manager DT value %d\n", val); pdata->boost_mng = CS35L32_BOOST_MGR_BYPASS; } - of_property_read_u32(np, "cirrus,sdout-datacfg", &val); + if (of_property_read_u32(np, "cirrus,sdout-datacfg", &val)) + val = -1u; switch (val) { case CS35L32_DATA_CFG_LR_VP: case CS35L32_DATA_CFG_LR_STAT: @@ -296,13 +300,15 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client, case CS35L32_DATA_CFG_LR_VPSTAT: pdata->sdout_datacfg = val; break; + case -1u: default: dev_err(&i2c_client->dev, "Wrong cirrus,sdout-datacfg DT value %d\n", val); pdata->sdout_datacfg = CS35L32_DATA_CFG_LR; } - of_property_read_u32(np, "cirrus,battery-threshold", &val); + if (of_property_read_u32(np, "cirrus,battery-threshold", &val)) + val = -1u; switch (val) { case CS35L32_BATT_THRESH_3_1V: case CS35L32_BATT_THRESH_3_2V: @@ -310,13 +316,15 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client, case CS35L32_BATT_THRESH_3_4V: pdata->batt_thresh = val; break; + case -1u: default: dev_err(&i2c_client->dev, "Wrong cirrus,battery-threshold DT value %d\n", val); pdata->batt_thresh = CS35L32_BATT_THRESH_3_3V; } - of_property_read_u32(np, "cirrus,battery-recovery", &val); + if (of_property_read_u32(np, "cirrus,battery-recovery", &val)) + val = -1u; switch (val) { case CS35L32_BATT_RECOV_3_1V: case CS35L32_BATT_RECOV_3_2V: @@ -326,6 +334,7 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client, case CS35L32_BATT_RECOV_3_6V: pdata->batt_recov = val; break; + case -1u: default: dev_err(&i2c_client->dev, "Wrong cirrus,battery-recovery DT value %d\n", val);