aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2016-03-14 10:49:54 -0400
committerMark Brown <broonie@kernel.org>2016-03-15 05:23:35 -0400
commitdd5dc001581a7cf6f563e188c302caae1be998c2 (patch)
treea2352a4b9c8a047336eaa3280ab9a4a56bae4285
parentd4a6360f19c1c551afcba42be98df04651fab31b (diff)
ASoC: cs35l32: avoid uninitialized variable access
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 <arnd@arndb.de> Acked-by: Brian Austin <brian.austin@cirrus.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/codecs/cs35l32.c17
1 files 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,
274 if (of_property_read_u32(np, "cirrus,sdout-share", &val) >= 0) 274 if (of_property_read_u32(np, "cirrus,sdout-share", &val) >= 0)
275 pdata->sdout_share = val; 275 pdata->sdout_share = val;
276 276
277 of_property_read_u32(np, "cirrus,boost-manager", &val); 277 if (of_property_read_u32(np, "cirrus,boost-manager", &val))
278 val = -1u;
279
278 switch (val) { 280 switch (val) {
279 case CS35L32_BOOST_MGR_AUTO: 281 case CS35L32_BOOST_MGR_AUTO:
280 case CS35L32_BOOST_MGR_AUTO_AUDIO: 282 case CS35L32_BOOST_MGR_AUTO_AUDIO:
@@ -282,13 +284,15 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client,
282 case CS35L32_BOOST_MGR_FIXED: 284 case CS35L32_BOOST_MGR_FIXED:
283 pdata->boost_mng = val; 285 pdata->boost_mng = val;
284 break; 286 break;
287 case -1u:
285 default: 288 default:
286 dev_err(&i2c_client->dev, 289 dev_err(&i2c_client->dev,
287 "Wrong cirrus,boost-manager DT value %d\n", val); 290 "Wrong cirrus,boost-manager DT value %d\n", val);
288 pdata->boost_mng = CS35L32_BOOST_MGR_BYPASS; 291 pdata->boost_mng = CS35L32_BOOST_MGR_BYPASS;
289 } 292 }
290 293
291 of_property_read_u32(np, "cirrus,sdout-datacfg", &val); 294 if (of_property_read_u32(np, "cirrus,sdout-datacfg", &val))
295 val = -1u;
292 switch (val) { 296 switch (val) {
293 case CS35L32_DATA_CFG_LR_VP: 297 case CS35L32_DATA_CFG_LR_VP:
294 case CS35L32_DATA_CFG_LR_STAT: 298 case CS35L32_DATA_CFG_LR_STAT:
@@ -296,13 +300,15 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client,
296 case CS35L32_DATA_CFG_LR_VPSTAT: 300 case CS35L32_DATA_CFG_LR_VPSTAT:
297 pdata->sdout_datacfg = val; 301 pdata->sdout_datacfg = val;
298 break; 302 break;
303 case -1u:
299 default: 304 default:
300 dev_err(&i2c_client->dev, 305 dev_err(&i2c_client->dev,
301 "Wrong cirrus,sdout-datacfg DT value %d\n", val); 306 "Wrong cirrus,sdout-datacfg DT value %d\n", val);
302 pdata->sdout_datacfg = CS35L32_DATA_CFG_LR; 307 pdata->sdout_datacfg = CS35L32_DATA_CFG_LR;
303 } 308 }
304 309
305 of_property_read_u32(np, "cirrus,battery-threshold", &val); 310 if (of_property_read_u32(np, "cirrus,battery-threshold", &val))
311 val = -1u;
306 switch (val) { 312 switch (val) {
307 case CS35L32_BATT_THRESH_3_1V: 313 case CS35L32_BATT_THRESH_3_1V:
308 case CS35L32_BATT_THRESH_3_2V: 314 case CS35L32_BATT_THRESH_3_2V:
@@ -310,13 +316,15 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client,
310 case CS35L32_BATT_THRESH_3_4V: 316 case CS35L32_BATT_THRESH_3_4V:
311 pdata->batt_thresh = val; 317 pdata->batt_thresh = val;
312 break; 318 break;
319 case -1u:
313 default: 320 default:
314 dev_err(&i2c_client->dev, 321 dev_err(&i2c_client->dev,
315 "Wrong cirrus,battery-threshold DT value %d\n", val); 322 "Wrong cirrus,battery-threshold DT value %d\n", val);
316 pdata->batt_thresh = CS35L32_BATT_THRESH_3_3V; 323 pdata->batt_thresh = CS35L32_BATT_THRESH_3_3V;
317 } 324 }
318 325
319 of_property_read_u32(np, "cirrus,battery-recovery", &val); 326 if (of_property_read_u32(np, "cirrus,battery-recovery", &val))
327 val = -1u;
320 switch (val) { 328 switch (val) {
321 case CS35L32_BATT_RECOV_3_1V: 329 case CS35L32_BATT_RECOV_3_1V:
322 case CS35L32_BATT_RECOV_3_2V: 330 case CS35L32_BATT_RECOV_3_2V:
@@ -326,6 +334,7 @@ static int cs35l32_handle_of_data(struct i2c_client *i2c_client,
326 case CS35L32_BATT_RECOV_3_6V: 334 case CS35L32_BATT_RECOV_3_6V:
327 pdata->batt_recov = val; 335 pdata->batt_recov = val;
328 break; 336 break;
337 case -1u:
329 default: 338 default:
330 dev_err(&i2c_client->dev, 339 dev_err(&i2c_client->dev,
331 "Wrong cirrus,battery-recovery DT value %d\n", val); 340 "Wrong cirrus,battery-recovery DT value %d\n", val);