All of lore.kernel.org
 help / color / mirror / Atom feed
From: Javier Carrasco <javier.carrasco.cruz@gmail.com>
To: Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	 Dan Carpenter <dan.carpenter@linaro.org>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Javier Carrasco <javier.carrasco.cruz@gmail.com>
Subject: [PATCH 1/2] hwmon: chipcap2: fix uninitialized variable in cc2_get_reg_val()
Date: Wed, 07 Feb 2024 22:17:08 +0100	[thread overview]
Message-ID: <20240207-chipcap2_init_vars-v1-1-08cafe43e20e@gmail.com> (raw)
In-Reply-To: <20240207-chipcap2_init_vars-v1-0-08cafe43e20e@gmail.com>

The reg_val variable in cc2_get_reg_val() might be used without a known
value if cc2_read_reg() fails. That leads to a useless data conversion
because the returned error means the read operation failed and the data is
not relevant.

That makes its initial value irrelevant as well, so skip the data
conversion instead. If no error happens, a value is assigned to reg_val
and the data conversion is required.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-hwmon/294e4634-89d4-415e-a723-b208d8770d7c@gmail.com/T/#t
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/hwmon/chipcap2.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/chipcap2.c b/drivers/hwmon/chipcap2.c
index a62c507b1042..3b604fc5d8ae 100644
--- a/drivers/hwmon/chipcap2.c
+++ b/drivers/hwmon/chipcap2.c
@@ -324,7 +324,9 @@ static int cc2_get_reg_val(struct cc2_data *data, u8 reg, long *val)
 	int ret;
 
 	ret = cc2_read_reg(data, reg, &reg_val);
-	*val = cc2_rh_convert(reg_val);
+	if (!ret)
+		*val = cc2_rh_convert(reg_val);
+
 	cc2_disable(data);
 
 	return ret;

-- 
2.40.1


  reply	other threads:[~2024-02-07 21:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07 21:17 [PATCH 0/2] hwmon: chipcap2: fix uninitialized symbols Javier Carrasco
2024-02-07 21:17 ` Javier Carrasco [this message]
2024-02-07 21:31   ` [PATCH 1/2] hwmon: chipcap2: fix uninitialized variable in cc2_get_reg_val() Guenter Roeck
2024-02-07 21:17 ` [PATCH 2/2] hwmon: chipcap2: fix return path in cc2_request_alarm_irqs() Javier Carrasco
2024-02-07 21:32   ` Guenter Roeck

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=20240207-chipcap2_init_vars-v1-1-08cafe43e20e@gmail.com \
    --to=javier.carrasco.cruz@gmail.com \
    --cc=dan.carpenter@linaro.org \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /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 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.