linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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>,
	Sebastian Reichel <sre@kernel.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] power: supply: max17042_battery: fix the potential uninitialized use in max17042_write_verify_reg()
Date: Wed,  2 Oct 2019 08:44:06 -0700	[thread overview]
Message-ID: <20191002154406.8875-1-yzhai003@ucr.edu> (raw)

In function max17042_write_verify_reg(), variable "read_value"
could be uninitialized if regmap_read() fails. However,
"read_value" is used to decide the control flow later in the if
statement, which is potentially unsafe.

Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
 drivers/power/supply/max17042_battery.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index 0dfad2cf13fe..e6a2dacaa730 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -486,12 +486,15 @@ static void max17042_external_power_changed(struct power_supply *psy)
 static int max17042_write_verify_reg(struct regmap *map, u8 reg, u32 value)
 {
 	int retries = 8;
-	int ret;
+	int ret, err;
 	u32 read_value;
 
 	do {
 		ret = regmap_write(map, reg, value);
-		regmap_read(map, reg, &read_value);
+		err = regmap_read(map, reg, &read_value);
+		if (err)
+			return err;
+
 		if (read_value != value) {
 			ret = -EIO;
 			retries--;
-- 
2.17.1


             reply	other threads:[~2019-10-02 15:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-02 15:44 Yizhuo [this message]
2019-10-14  3:31 ` [PATCH] power: supply: max17042_battery: fix the potential uninitialized use in max17042_write_verify_reg() Sebastian Reichel

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=20191002154406.8875-1-yzhai003@ucr.edu \
    --to=yzhai003@ucr.edu \
    --cc=csong@cs.ucr.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    --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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).