linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized
@ 2019-09-29 17:09 Yizhuo
  2019-10-01 17:56 ` Applied "regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized" to the regulator tree Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Yizhuo @ 2019-09-29 17:09 UTC (permalink / raw)
  Cc: csong, zhiyunq, Yizhuo, Liam Girdwood, Mark Brown, linux-kernel

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

Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
 drivers/regulator/pfuze100-regulator.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c
index df5df1c495ad..689537927f6f 100644
--- a/drivers/regulator/pfuze100-regulator.c
+++ b/drivers/regulator/pfuze100-regulator.c
@@ -788,7 +788,13 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
 
 		/* SW2~SW4 high bit check and modify the voltage value table */
 		if (i >= sw_check_start && i <= sw_check_end) {
-			regmap_read(pfuze_chip->regmap, desc->vsel_reg, &val);
+			ret = regmap_read(pfuze_chip->regmap,
+						desc->vsel_reg, &val);
+			if (ret) {
+				dev_err(&client->dev, "Fails to read from the register.\n");
+				return ret;
+			}
+
 			if (val & sw_hi) {
 				if (pfuze_chip->chip_id == PFUZE3000 ||
 					pfuze_chip->chip_id == PFUZE3001) {
-- 
2.17.1


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

* Applied "regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized" to the regulator tree
  2019-09-29 17:09 [PATCH] regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized Yizhuo
@ 2019-10-01 17:56 ` Mark Brown
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2019-10-01 17:56 UTC (permalink / raw)
  To: Yizhuo; +Cc: Cc:, Cc:, csong, Liam Girdwood, linux-kernel, Mark Brown, zhiyunq

The patch

   regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized

has been applied to the regulator tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-5.4

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 1252b283141f03c3dffd139292c862cae10e174d Mon Sep 17 00:00:00 2001
From: Yizhuo <yzhai003@ucr.edu>
Date: Sun, 29 Sep 2019 10:09:57 -0700
Subject: [PATCH] regulator: pfuze100-regulator: Variable "val" in
 pfuze100_regulator_probe() could be uninitialized

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

Signed-off-by: Yizhuo <yzhai003@ucr.edu>
Link: https://lore.kernel.org/r/20190929170957.14775-1-yzhai003@ucr.edu
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/regulator/pfuze100-regulator.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c
index df5df1c495ad..689537927f6f 100644
--- a/drivers/regulator/pfuze100-regulator.c
+++ b/drivers/regulator/pfuze100-regulator.c
@@ -788,7 +788,13 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
 
 		/* SW2~SW4 high bit check and modify the voltage value table */
 		if (i >= sw_check_start && i <= sw_check_end) {
-			regmap_read(pfuze_chip->regmap, desc->vsel_reg, &val);
+			ret = regmap_read(pfuze_chip->regmap,
+						desc->vsel_reg, &val);
+			if (ret) {
+				dev_err(&client->dev, "Fails to read from the register.\n");
+				return ret;
+			}
+
 			if (val & sw_hi) {
 				if (pfuze_chip->chip_id == PFUZE3000 ||
 					pfuze_chip->chip_id == PFUZE3001) {
-- 
2.20.1


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

* Re: [PATCH] regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized
  2019-09-03 11:25 ` Mark Brown
@ 2019-09-03 16:21   ` Yizhuo Zhai
  0 siblings, 0 replies; 5+ messages in thread
From: Yizhuo Zhai @ 2019-09-03 16:21 UTC (permalink / raw)
  To: Mark Brown; +Cc: Chengyu Song, Zhiyun Qian, Liam Girdwood, linux-kernel

Thanks Mark, I will send a new patch and check the return value instead.

On Tue, Sep 3, 2019 at 4:26 AM Mark Brown <broonie@kernel.org> wrote:
>
> On Mon, Sep 02, 2019 at 03:10:47PM -0700, Yizhuo wrote:
> > In function pfuze100_regulator_probe(), variable "val" could be
> > initialized if regmap_read() fails. However, "val" is used to
> > decide the control flow later in the if statement, which is
> > potentially unsafe.
>
> >               struct regulator_desc *desc;
> > -             int val;
> > +             int val = 0;
>
> This just unconditionally assings a value to this variable which will
> stop any warnings but there's no analysis explaining why this is a good
> fix - are we actually forgetting to check something we should be
> checking, are we sure that this is the correct value to use?



-- 
Kind Regards,

Yizhuo Zhai

Computer Science, Graduate Student
University of California, Riverside

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

* Re: [PATCH] regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized
  2019-09-02 22:10 [PATCH] regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized Yizhuo
@ 2019-09-03 11:25 ` Mark Brown
  2019-09-03 16:21   ` Yizhuo Zhai
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2019-09-03 11:25 UTC (permalink / raw)
  To: Yizhuo; +Cc: csong, zhiyunq, Liam Girdwood, linux-kernel

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

On Mon, Sep 02, 2019 at 03:10:47PM -0700, Yizhuo wrote:
> In function pfuze100_regulator_probe(), variable "val" could be
> initialized if regmap_read() fails. However, "val" is used to
> decide the control flow later in the if statement, which is
> potentially unsafe.

>  		struct regulator_desc *desc;
> -		int val;
> +		int val = 0;

This just unconditionally assings a value to this variable which will
stop any warnings but there's no analysis explaining why this is a good
fix - are we actually forgetting to check something we should be
checking, are we sure that this is the correct value to use?

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

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

* [PATCH] regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized
@ 2019-09-02 22:10 Yizhuo
  2019-09-03 11:25 ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Yizhuo @ 2019-09-02 22:10 UTC (permalink / raw)
  Cc: csong, zhiyunq, Yizhuo, Liam Girdwood, Mark Brown, linux-kernel

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

Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
 drivers/regulator/pfuze100-regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c
index df5df1c495ad..649e2bfcdffd 100644
--- a/drivers/regulator/pfuze100-regulator.c
+++ b/drivers/regulator/pfuze100-regulator.c
@@ -777,7 +777,7 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
 	for (i = 0; i < regulator_num; i++) {
 		struct regulator_init_data *init_data;
 		struct regulator_desc *desc;
-		int val;
+		int val = 0;
 
 		desc = &pfuze_chip->regulator_descs[i].desc;
 
-- 
2.17.1


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

end of thread, other threads:[~2019-10-01 17:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-29 17:09 [PATCH] regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized Yizhuo
2019-10-01 17:56 ` Applied "regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized" to the regulator tree Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2019-09-02 22:10 [PATCH] regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized Yizhuo
2019-09-03 11:25 ` Mark Brown
2019-09-03 16:21   ` Yizhuo Zhai

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