From: Douglas Anderson <dianders@chromium.org> To: bardliao@realtek.com, oder_chiou@realtek.com Cc: Douglas Anderson <dianders@chromium.org>, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] ASoC: rt5514: Avoid relying on uninitialized "val" value Date: Fri, 14 Apr 2017 09:40:31 -0700 [thread overview] Message-ID: <20170414164033.11681-2-dianders@chromium.org> (raw) In-Reply-To: <20170414164033.11681-1-dianders@chromium.org> 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 <dianders@chromium.org> --- 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; -- 2.12.2.762.g0e3151a226-goog
WARNING: multiple messages have this Message-ID (diff)
From: Douglas Anderson <dianders@chromium.org> To: bardliao@realtek.com, oder_chiou@realtek.com Cc: alsa-devel@alsa-project.org, Douglas Anderson <dianders@chromium.org>, lgirdwood@gmail.com, linux-kernel@vger.kernel.org, tiwai@suse.com, broonie@kernel.org Subject: [PATCH 2/3] ASoC: rt5514: Avoid relying on uninitialized "val" value Date: Fri, 14 Apr 2017 09:40:31 -0700 [thread overview] Message-ID: <20170414164033.11681-2-dianders@chromium.org> (raw) In-Reply-To: <20170414164033.11681-1-dianders@chromium.org> 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 <dianders@chromium.org> --- 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; -- 2.12.2.762.g0e3151a226-goog
next prev parent reply other threads:[~2017-04-14 16:41 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-04-14 16:40 [PATCH 1/3] ASoC: rt5514: Mark rt5514_i2c_driver as static Douglas Anderson 2017-04-14 16:40 ` Douglas Anderson 2017-04-14 16:40 ` Douglas Anderson [this message] 2017-04-14 16:40 ` [PATCH 2/3] ASoC: rt5514: Avoid relying on uninitialized "val" value Douglas Anderson 2017-04-14 17:11 ` Applied "ASoC: rt5514: Avoid relying on uninitialized "val" value" to the asoc tree Mark Brown 2017-04-14 17:11 ` Mark Brown 2017-04-14 16:40 ` [PATCH 3/3] ASoC: rt5514: Unconfuse the rt5514 at probe / resume time Douglas Anderson 2017-04-14 17:11 ` Applied "ASoC: rt5514: Unconfuse the rt5514 at probe / resume time" to the asoc tree Mark Brown 2017-04-14 17:11 ` Mark Brown 2017-04-14 17:12 ` Applied "ASoC: rt5514: Mark rt5514_i2c_driver as static" " Mark Brown 2017-04-14 17:12 ` 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=20170414164033.11681-2-dianders@chromium.org \ --to=dianders@chromium.org \ --cc=alsa-devel@alsa-project.org \ --cc=bardliao@realtek.com \ --cc=broonie@kernel.org \ --cc=lgirdwood@gmail.com \ --cc=linux-kernel@vger.kernel.org \ --cc=oder_chiou@realtek.com \ --cc=perex@perex.cz \ --cc=tiwai@suse.com \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.