From: Yizhuo <yzhai003@ucr.edu> To: unlisted-recipients:; (no To-header on input) Cc: csong@cs.ucr.edu, zhiyunq@cs.ucr.edu, Yizhuo <yzhai003@ucr.edu>, Bard Liao <bardliao@realtek.com>, Oder Chiou <oder_chiou@realtek.com>, Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: rt298: Variable "val" and "buf" in rt298_jack_detect() could be uninitialized Date: Fri, 4 Jan 2019 13:52:53 -0800 [thread overview] Message-ID: <20190104215253.16278-1-yzhai003@ucr.edu> (raw) In function rt298_jack_detect(), local variable "val" and "buf" are supposed to get initialized by regmap_read(). However, they could be leave uninitialized if regmap_read() returns -EINVAL. Those two variables are used in control flow or update the argument, which could lead to undefined behavior and thus unsafe. Signed-off-by: Yizhuo <yzhai003@ucr.edu> --- sound/soc/codecs/rt298.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/rt298.c b/sound/soc/codecs/rt298.c index ce963768449f..7f74349c17f3 100644 --- a/sound/soc/codecs/rt298.c +++ b/sound/soc/codecs/rt298.c @@ -223,6 +223,7 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) { struct snd_soc_dapm_context *dapm; unsigned int val, buf; + int ret = 0; *hp = false; *mic = false; @@ -233,7 +234,10 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) dapm = snd_soc_codec_get_dapm(rt298->codec); if (rt298->pdata.cbj_en) { - regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + ret = regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + if (ret) + return ret; + *hp = buf & 0x80000000; if (*hp == rt298->is_hp_in) return -1; @@ -260,16 +264,19 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) regmap_update_bits(rt298->regmap, RT298_CBJ_CTRL1, 0xfcc0, 0xd400); msleep(300); - regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val); - + ret = regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val); + if (ret) + return ret; if (0x0070 == (val & 0x0070)) { *mic = true; } else { regmap_update_bits(rt298->regmap, RT298_CBJ_CTRL1, 0xfcc0, 0xe400); msleep(300); - regmap_read(rt298->regmap, + ret = regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val); + if (ret) + return ret; if (0x0070 == (val & 0x0070)) *mic = true; else @@ -285,9 +292,14 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) RT298_CBJ_CTRL1, 0x0400, 0x0000); } } else { - regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + ret = regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + if (ret) + return ret; + *hp = buf & 0x80000000; - regmap_read(rt298->regmap, RT298_GET_MIC1_SENSE, &buf); + ret = regmap_read(rt298->regmap, RT298_GET_MIC1_SENSE, &buf); + if (ret) + return ret; *mic = buf & 0x80000000; } -- 2.17.1
WARNING: multiple messages have this Message-ID (diff)
From: Yizhuo <yzhai003@ucr.edu> Cc: csong@cs.ucr.edu, zhiyunq@cs.ucr.edu, Yizhuo <yzhai003@ucr.edu>, Bard Liao <bardliao@realtek.com>, Oder Chiou <oder_chiou@realtek.com>, Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: rt298: Variable "val" and "buf" in rt298_jack_detect() could be uninitialized Date: Fri, 4 Jan 2019 13:52:53 -0800 [thread overview] Message-ID: <20190104215253.16278-1-yzhai003@ucr.edu> (raw) In function rt298_jack_detect(), local variable "val" and "buf" are supposed to get initialized by regmap_read(). However, they could be leave uninitialized if regmap_read() returns -EINVAL. Those two variables are used in control flow or update the argument, which could lead to undefined behavior and thus unsafe. Signed-off-by: Yizhuo <yzhai003@ucr.edu> --- sound/soc/codecs/rt298.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/rt298.c b/sound/soc/codecs/rt298.c index ce963768449f..7f74349c17f3 100644 --- a/sound/soc/codecs/rt298.c +++ b/sound/soc/codecs/rt298.c @@ -223,6 +223,7 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) { struct snd_soc_dapm_context *dapm; unsigned int val, buf; + int ret = 0; *hp = false; *mic = false; @@ -233,7 +234,10 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) dapm = snd_soc_codec_get_dapm(rt298->codec); if (rt298->pdata.cbj_en) { - regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + ret = regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + if (ret) + return ret; + *hp = buf & 0x80000000; if (*hp == rt298->is_hp_in) return -1; @@ -260,16 +264,19 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) regmap_update_bits(rt298->regmap, RT298_CBJ_CTRL1, 0xfcc0, 0xd400); msleep(300); - regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val); - + ret = regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val); + if (ret) + return ret; if (0x0070 == (val & 0x0070)) { *mic = true; } else { regmap_update_bits(rt298->regmap, RT298_CBJ_CTRL1, 0xfcc0, 0xe400); msleep(300); - regmap_read(rt298->regmap, + ret = regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val); + if (ret) + return ret; if (0x0070 == (val & 0x0070)) *mic = true; else @@ -285,9 +292,14 @@ static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic) RT298_CBJ_CTRL1, 0x0400, 0x0000); } } else { - regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + ret = regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf); + if (ret) + return ret; + *hp = buf & 0x80000000; - regmap_read(rt298->regmap, RT298_GET_MIC1_SENSE, &buf); + ret = regmap_read(rt298->regmap, RT298_GET_MIC1_SENSE, &buf); + if (ret) + return ret; *mic = buf & 0x80000000; } -- 2.17.1
next reply other threads:[~2019-01-04 21:53 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-01-04 21:52 Yizhuo [this message] 2019-01-04 21:52 ` [PATCH] ASoC: rt298: Variable "val" and "buf" in rt298_jack_detect() could be uninitialized Yizhuo 2019-01-07 16:28 ` Mark Brown 2019-01-07 16:28 ` 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=20190104215253.16278-1-yzhai003@ucr.edu \ --to=yzhai003@ucr.edu \ --cc=alsa-devel@alsa-project.org \ --cc=bardliao@realtek.com \ --cc=broonie@kernel.org \ --cc=csong@cs.ucr.edu \ --cc=lgirdwood@gmail.com \ --cc=linux-kernel@vger.kernel.org \ --cc=oder_chiou@realtek.com \ --cc=perex@perex.cz \ --cc=tiwai@suse.com \ --cc=zhiyunq@cs.ucr.edu \ /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.