linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Austin, Brian" <Brian.Austin@cirrus.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Mark Brown <broonie@kernel.org>,
	"Austin, Brian" <Brian.Austin@cirrus.com>,
	"Handrigan, Paul" <Paul.Handrigan@cirrus.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ASoC: cs35l32: avoid uninitialized variable access
Date: Mon, 7 Mar 2016 12:22:18 +0000	[thread overview]
Message-ID: <E771F005-D3E6-48A9-A0B1-1C11F1439E55@cirrus.com> (raw)
In-Reply-To: <1457324374-3405023-1-git-send-email-arnd@arndb.de>


> On Mar 6, 2016, at 10:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> 
> 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>
> ---
> 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;
With this one line removed won’t that keep from assigning the value for later?
The other ones don’t seem to do this but just check for bad value.
> 		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;
> 	}
> 
Regards,
Brian

  reply	other threads:[~2016-03-07 12:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07  4:19 [PATCH] ASoC: cs35l32: avoid uninitialized variable access Arnd Bergmann
2016-03-07 12:22 ` Austin, Brian [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-01-01 23:19 Arnd Bergmann
2016-01-02 14:17 ` Mark Brown
2016-01-04 15:17   ` Arnd Bergmann
2016-01-04 15:20     ` Russell King - ARM Linux
2016-01-04 16:41       ` Arnd Bergmann
2016-01-04 16:52         ` Russell King - ARM Linux
2016-01-04 15:45     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E771F005-D3E6-48A9-A0B1-1C11F1439E55@cirrus.com \
    --to=brian.austin@cirrus.com \
    --cc=Paul.Handrigan@cirrus.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).