Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752159AbcCGEUW (ORCPT ); Sun, 6 Mar 2016 23:20:22 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:61527 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751995AbcCGEUQ (ORCPT ); Sun, 6 Mar 2016 23:20:16 -0500 From: Arnd Bergmann To: Mark Brown Cc: Arnd Bergmann , Brian Austin , Paul Handrigan , Liam Girdwood , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: cs35l32: avoid uninitialized variable access Date: Mon, 7 Mar 2016 05:19:06 +0100 Message-Id: <1457324374-3405023-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:AgGSC046EUY8sqmzWRmpp6a6a8Yf7YUYp1ZEL1gnfl5I2EwwYDM 5Wn8+GDNnXKxLSbjJ3jQyAzGLCnOxlq7XErVFzf3NMX24OPcfBjk+s43C3brhsz1MxSxD12 jfjQhs1z2EotzCy32+ABrLnIsXr2Hd3en59KvrvCcwlLpg9BnQdclszYO9gI0wlgoxLRoX4 +s/6OuEQkrnW3oToufLgg== X-UI-Out-Filterresults: notjunk:1;V01:K0:ZirPUilSmQ0=:cZCM9uLrDJSbnpqbew3Gys 6iLhya4T6a4EMVYaAQrT5cbgO1ZOAyhpOeREGluq6cghev5UzWVU5MM5KF+s1EUVv9d+s3ZpX Aln1BzbHz14tAdyNsNzysRA72ta3t5P/Ohg+kV1MnulVes8gyl72bBuRriNXRMU4cZ9IofXTe Ahis1xcTZ2yN8g+V2nUujc1eiWe0EANiKrLfp1hXno08jcJvR9JFTWXun1Ydu08MT3vzxk0Ne Dq+E3C2zeHJwuktEFeJHOrRHfakQSP+rnNG+T7AEtVAZKYbCYUQfPzn3UqoZ4NEFl1FFWf3nX gAS/Omcr9FTAJdnLEjaKksrziocBW0ZK7LwCjPcYTv4lmCEMVPJTN902muuCt6E8AF2lVoiQj IN8uiwfOtpLs6GtPoVoGFdo1zvnd06bVoGRIEJWZHwl6NuNIzkwvg7SMJpBu+laZ7pVfQ/K8g n58EFGktupPfKTR1Hh2MqWWGmTBXhn02KUwUhMnIHGbl6nzLqd7nOgO8BobRXXFUeDnMxyKG1 JZLXra6lWaorcwlPYH6YymYwGgNr6/783OahL3f/0zdVCUjY7GxWA94E3DzSztSZaw/Rc2i14 nIjvtawPF44Qz/Jse0hKFhvqsN5I5guomLQfzEY8mvibtcG1T1wsB3fVcDoHqRq6cHsr/mDfn shGca2eDPAGiG2N+2lD9mtY6hJ82Og8c4o6wM6IFrKxheHcwv6Bx3GDgsq6LujRREDdE= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3154 Lines: 91 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 --- sound/soc/codecs/cs35l32.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sound/soc/codecs/cs35l32.c b/sound/soc/codecs/cs35l32.c index 44c30fe3e315..c490dc74121b 100644 --- a/sound/soc/codecs/cs35l32.c +++ b/sound/soc/codecs/cs35l32.c @@ -274,21 +274,24 @@ 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: case CS35L32_BOOST_MGR_BYPASS: 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 +299,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 +315,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: -- 2.7.0