linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: supply: max17042_battery: fix the potential uninitialized use in max17042_write_verify_reg()
@ 2019-10-02 15:44 Yizhuo
  2019-10-14  3:31 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Yizhuo @ 2019-10-02 15:44 UTC (permalink / raw)
  Cc: csong, zhiyunq, Yizhuo, Sebastian Reichel, linux-pm, linux-kernel

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


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

* Re: [PATCH] power: supply: max17042_battery: fix the potential uninitialized use in max17042_write_verify_reg()
  2019-10-02 15:44 [PATCH] power: supply: max17042_battery: fix the potential uninitialized use in max17042_write_verify_reg() Yizhuo
@ 2019-10-14  3:31 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2019-10-14  3:31 UTC (permalink / raw)
  To: Yizhuo; +Cc: csong, zhiyunq, linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1402 bytes --]

Hi,

On Wed, Oct 02, 2019 at 08:44:06AM -0700, Yizhuo wrote:
> 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>
> ---

Instead of directly failing, integrate this into
the retry loop. Also the Signed-off-by and patch
author name looks incomplete.

Thanks,

-- Sebastian

>  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
> 

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

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

end of thread, other threads:[~2019-10-14  3:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-02 15:44 [PATCH] power: supply: max17042_battery: fix the potential uninitialized use in max17042_write_verify_reg() Yizhuo
2019-10-14  3:31 ` Sebastian Reichel

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).