Skip to contentSkip to conversation

extcon: fix a missing check of regmap_read

PATCH In review Kangjie Lu 3 participants 5 messages Mar 18, 2019 – Mar 20, 2019

Subsystems (3)
lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 extcon: fix a missing check of regmap_read

When regmap_read fails, it doesn't make sense to use the read value "val" because it can be uninitialized.

The fix returns if regmap_read fails.

---
 drivers/extcon/extcon-axp288.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/extcon/extcon-axp288.c +4 -0
index a983708b77a6..b2ba5f073aa7 100644
@@ -143,6 +143,10 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
 	int ret;
 
 	ret = regmap_read(info->regmap, AXP288_PS_BOOT_REASON_REG, &val);
+	if (ret) {
+		dev_dbg(info->dev, "regmap_read error %d\n", ret);
+		return;
+	}
 	for (i = 0, rsi = axp288_pwr_up_down_info; *rsi; rsi++, i++) {
 		if (val & BIT(i)) {
 			dev_dbg(info->dev, "%s\n", *rsi);
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 15 lines · Kangjie Lu

When regmap_read fails, it doesn't make sense to use the read value "val" because it can be uninitialized.

The fix returns if regmap_read fails.

---
  drivers/extcon/extcon-axp288.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/extcon/extcon-axp288.c +0 -0
index a983708b77a6..b2ba5f073aa7 100644

drivers/extcon/extcon-axp288.c static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) · line 152

Quoted 10 lines
drivers/extcon/extcon-axp288.c +4 -0
@@ -143,6 +143,10 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
  	int ret;
 
  	ret = regmap_read(info->regmap, AXP288_PS_BOOT_REASON_REG, &val);
+	if (ret) {
+		dev_dbg(info->dev, "regmap_read error %d\n", ret);
+		return;
+	}
  	for (i = 0, rsi = axp288_pwr_up_down_info; *rsi; rsi++, i++) {
  		if (val & BIT(i)) {
  			dev_dbg(info->dev, "%s\n", *rsi);

Patch looks good to me:

Regards,

Hans

maintainer
#2 lore raw
In reply to Kangjie Lu

Hi,

Quoted 15 lines · Kangjie Lu

When regmap_read fails, it doesn't make sense to use the read value "val" because it can be uninitialized.

The fix returns if regmap_read fails.

---
 drivers/extcon/extcon-axp288.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/extcon/extcon-axp288.c +0 -0
index a983708b77a6..b2ba5f073aa7 100644

drivers/extcon/extcon-axp288.c static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) · line 147

Quoted 5 lines
drivers/extcon/extcon-axp288.c +2 -0
@@ -143,6 +143,10 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
 	int ret;
 
 	ret = regmap_read(info->regmap, AXP288_PS_BOOT_REASON_REG, &val);
+	if (ret) {
+		dev_dbg(info->dev, "regmap_read error %d\n", ret);

dev_err is correct for handling the error case
instead of dev_dbg. And I recommend that you use following error log because extcon-axp288.c already used the 'failed to ...' log style. If there is no special reason, you better to keep the consistency for the readability.

- dev_err(info->dev, "failed to read BOOT_REASON_REG: %d\n", ret);

Quoted 6 lines
drivers/extcon/extcon-axp288.c +2 -0
+		return;
+	}
 	for (i = 0, rsi = axp288_pwr_up_down_info; *rsi; rsi++, i++) {
 		if (val & BIT(i)) {
 			dev_dbg(info->dev, "%s\n", *rsi);
Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
author
#3 lore raw

PATCH 1/1 extcon: fix a missing check of regmap_read

When regmap_read fails, it doesn't make sense to use the read value "val" because it can be uninitialized.

The fix returns if regmap_read fails.

---
 drivers/extcon/extcon-axp288.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/extcon/extcon-axp288.c +4 -0
index a983708b77a6..b2ba5f073aa7 100644
@@ -143,6 +143,10 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
 	int ret;
 
 	ret = regmap_read(info->regmap, AXP288_PS_BOOT_REASON_REG, &val);
+	if (ret) {
+		dev_err(info->dev, "failed to read BOOT_REASON_REG: %d\n", ret);
+		return;
+	}
 	for (i = 0, rsi = axp288_pwr_up_down_info; *rsi; rsi++, i++) {
 		if (val & BIT(i)) {
 			dev_dbg(info->dev, "%s\n", *rsi);
Signature · 1 line
2.17.1
maintainer
#4 lore raw

Hi,

You better to edit the patch title as following
in order to sustain the title format for extcon:

extcon: fix a missing check of regmap_read
-> extcon: axp288: Fix a missing check of regmap_read

Quoted 15 lines · Kangjie Lu

When regmap_read fails, it doesn't make sense to use the read value "val" because it can be uninitialized.

The fix returns if regmap_read fails.

---
 drivers/extcon/extcon-axp288.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/extcon/extcon-axp288.c +0 -0
index a983708b77a6..b2ba5f073aa7 100644

drivers/extcon/extcon-axp288.c static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) · line 149

Quoted 7 lines
drivers/extcon/extcon-axp288.c +4 -0
@@ -143,6 +143,10 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
 	int ret;
 
 	ret = regmap_read(info->regmap, AXP288_PS_BOOT_REASON_REG, &val);
+	if (ret) {
+		dev_err(info->dev, "failed to read BOOT_REASON_REG: %d\n", ret);
+		return;
+	}

Have to add the blank line. time.

And I think that axp288_extcon_log_rsi() have to return the 'error value' instead of 'void' return type. And then should handle the return value of axp288_extcon_log_rsi() within the axp288_extcon_probe().

For example,

	ret = axp288_extcon_log_rsi(info)
	if (ret < 0)
		return ret;
Quoted 4 lines
drivers/extcon/extcon-axp288.c +0 -0
 	for (i = 0, rsi = axp288_pwr_up_down_info; *rsi; rsi++, i++) {
 		if (val & BIT(i)) {
 			dev_dbg(info->dev, "%s\n", *rsi);
Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics