* [PATCH] ASoC: rt274: Variable "buf" in function rt274_jack_detect() could be uninitialized
@ 2019-01-07 20:12 Yizhuo
0 siblings, 0 replies; 3+ messages in thread
From: Yizhuo @ 2019-01-07 20:12 UTC (permalink / raw)
Cc: csong, zhiyunq, Yizhuo, Bard Liao, Oder Chiou, Liam Girdwood,
Mark Brown, Jaroslav Kysela, Takashi Iwai, alsa-devel,
linux-kernel
In function rt274_jack_detect(), local variable "buf" could
be uninitialized if function regmap_read() returns -EINVAL.
However, it will be used to calculate "hp" and "mic" and
make their value unpredictable while those value are used
in the caller. This is potentially unsafe.
Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
sound/soc/codecs/rt274.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/rt274.c b/sound/soc/codecs/rt274.c
index 8f92e5c4dd9d..332a3e955bdb 100644
--- a/sound/soc/codecs/rt274.c
+++ b/sound/soc/codecs/rt274.c
@@ -353,6 +353,7 @@ static void rt274_index_sync(struct snd_soc_codec *codec)
static int rt274_jack_detect(struct rt274_priv *rt274, bool *hp, bool *mic)
{
unsigned int buf;
+ int ret;
*hp = false;
*mic = false;
@@ -360,9 +361,15 @@ static int rt274_jack_detect(struct rt274_priv *rt274, bool *hp, bool *mic)
if (!rt274->codec)
return -EINVAL;
- regmap_read(rt274->regmap, RT274_GET_HP_SENSE, &buf);
+ ret = regmap_read(rt274->regmap, RT274_GET_HP_SENSE, &buf);
+ if (ret)
+ return ret;
+
*hp = buf & 0x80000000;
- regmap_read(rt274->regmap, RT274_GET_MIC_SENSE, &buf);
+ ret = regmap_read(rt274->regmap, RT274_GET_MIC_SENSE, &buf);
+ if (ret)
+ return ret;
+
*mic = buf & 0x80000000;
pr_debug("*hp = %d *mic = %d\n", *hp, *mic);
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ASoC: rt274: Variable "buf" in function rt274_jack_detect() could be uninitialized
2019-01-04 20:27 Yizhuo
@ 2019-01-07 16:58 ` Mark Brown
0 siblings, 0 replies; 3+ messages in thread
From: Mark Brown @ 2019-01-07 16:58 UTC (permalink / raw)
To: Yizhuo
Cc: csong, zhiyunq, Bard Liao, Oder Chiou, Liam Girdwood,
Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 411 bytes --]
On Fri, Jan 04, 2019 at 12:27:08PM -0800, Yizhuo wrote:
> In function rt274_jack_detect(), local variable "buf" could
> be uninitialized if function regmap_read() returns -EINVAL.
> However, it will be used to calculate "hp" and "mic" and
> make their value unpredictable while those value are used
> in the caller. This is potentially unsafe.
This doesn't apply against current code, please check and resend.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] ASoC: rt274: Variable "buf" in function rt274_jack_detect() could be uninitialized
@ 2019-01-04 20:27 Yizhuo
2019-01-07 16:58 ` Mark Brown
0 siblings, 1 reply; 3+ messages in thread
From: Yizhuo @ 2019-01-04 20:27 UTC (permalink / raw)
Cc: csong, zhiyunq, Yizhuo, Bard Liao, Oder Chiou, Liam Girdwood,
Mark Brown, Jaroslav Kysela, Takashi Iwai, alsa-devel,
linux-kernel
In function rt274_jack_detect(), local variable "buf" could
be uninitialized if function regmap_read() returns -EINVAL.
However, it will be used to calculate "hp" and "mic" and
make their value unpredictable while those value are used
in the caller. This is potentially unsafe.
Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
sound/soc/codecs/rt274.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/rt274.c b/sound/soc/codecs/rt274.c
index cd048df76232..a2c1a6df8df6 100644
--- a/sound/soc/codecs/rt274.c
+++ b/sound/soc/codecs/rt274.c
@@ -353,6 +353,7 @@ static void rt274_index_sync(struct snd_soc_codec *codec)
static int rt274_jack_detect(struct rt274_priv *rt274, bool *hp, bool *mic)
{
unsigned int buf;
+ int ret = 0;
*hp = false;
*mic = false;
@@ -360,9 +361,15 @@ static int rt274_jack_detect(struct rt274_priv *rt274, bool *hp, bool *mic)
if (!rt274->codec)
return -EINVAL;
- regmap_read(rt274->regmap, RT274_GET_HP_SENSE, &buf);
+ ret = regmap_read(rt274->regmap, RT274_GET_HP_SENSE, &buf);
+ if (ret)
+ return ret;
+
*hp = buf & 0x80000000;
- regmap_read(rt274->regmap, RT274_GET_MIC_SENSE, &buf);
+ ret = regmap_read(rt274->regmap, RT274_GET_MIC_SENSE, &buf);
+ if (ret)
+ return ret;
+
*mic = buf & 0x80000000;
pr_debug("*hp = %d *mic = %d\n", *hp, *mic);
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-01-07 20:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-07 20:12 [PATCH] ASoC: rt274: Variable "buf" in function rt274_jack_detect() could be uninitialized Yizhuo
-- strict thread matches above, loose matches on Subject: below --
2019-01-04 20:27 Yizhuo
2019-01-07 16:58 ` Mark Brown
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).