mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] In function rt274_i2c_probe(), if the regmap_read fails. The variable "val" could leave uninitialized but used in if statement.
@ 2019-01-03  2:38 Yizhuo
  2019-01-03 13:10 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Yizhuo @ 2019-01-03  2:38 UTC (permalink / raw)
  Cc: csong, zhiyunq, Yizhuo, Bard Liao, Oder Chiou, Liam Girdwood,
	Mark Brown, Jaroslav Kysela, Takashi Iwai, alsa-devel,
	linux-kernel

Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
 sound/soc/codecs/rt274.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/rt274.c b/sound/soc/codecs/rt274.c
index 8f92e5c4dd9d..940658cac063 100644
--- a/sound/soc/codecs/rt274.c
+++ b/sound/soc/codecs/rt274.c
@@ -1113,7 +1113,7 @@ static int rt274_i2c_probe(struct i2c_client *i2c,
 	struct rt274_priv *rt274;
 
 	int ret;
-	unsigned int val;
+	unsigned int val = ~0;
 
 	rt274 = devm_kzalloc(&i2c->dev,	sizeof(*rt274),
 				GFP_KERNEL);
@@ -1128,9 +1128,9 @@ static int rt274_i2c_probe(struct i2c_client *i2c,
 		return ret;
 	}
 
-	regmap_read(rt274->regmap,
+	ret = regmap_read(rt274->regmap,
 		RT274_GET_PARAM(AC_NODE_ROOT, AC_PAR_VENDOR_ID), &val);
-	if (val != RT274_VENDOR_ID) {
+	if (ret || val != RT274_VENDOR_ID) {
 		dev_err(&i2c->dev,
 			"Device with ID register %#x is not rt274\n", val);
 		return -ENODEV;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] In function rt274_i2c_probe(), if the regmap_read fails. The variable "val" could leave uninitialized but used in if statement.
  2019-01-03  2:38 [PATCH] In function rt274_i2c_probe(), if the regmap_read fails. The variable "val" could leave uninitialized but used in if statement Yizhuo
@ 2019-01-03 13:10 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2019-01-03 13:10 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: 793 bytes --]

On Wed, Jan 02, 2019 at 06:38:39PM -0800, Yizhuo wrote:

>  	int ret;
> -	unsigned int val;
> +	unsigned int val = ~0;
>  

This just shuts warnings up which may mask further problem, it is better
to just leave it and fix the users.

> -	regmap_read(rt274->regmap,
> +	ret = regmap_read(rt274->regmap,
>  		RT274_GET_PARAM(AC_NODE_ROOT, AC_PAR_VENDOR_ID), &val);
> -	if (val != RT274_VENDOR_ID) {
> +	if (ret || val != RT274_VENDOR_ID) {
>  		dev_err(&i2c->dev,
>  			"Device with ID register %#x is not rt274\n", val);
>  		return -ENODEV;

If the read returned an error we should pass back the error code we got
from it, not mask it with another error code.  This is especially true
here where the error message would be very misleading if there's a
problem with I/O.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-03 13:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-03  2:38 [PATCH] In function rt274_i2c_probe(), if the regmap_read fails. The variable "val" could leave uninitialized but used in if statement Yizhuo
2019-01-03 13:10 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®