Skip to contentSkip to conversation

extcon: axp288: Add missed error check

PATCH Superseded Andy Shevchenko 2 participants 4 messages Jul 25, 2019 – Jul 26, 2019 1 message not in the archive

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 extcon: axp288: Add missed error check

It seems from the very beginning the error check has been missed in axp288_extcon_log_rsi(). Add it here.

Cc Ramakrishna Pallala <[email protected]>
---
 drivers/extcon/extcon-axp288.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/extcon/extcon-axp288.c +3 -0
index 7254852e6ec0..4cbcc3b1aa6b 100644
@@ -135,6 +135,9 @@ 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 < 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 · 1 line
2.20.1
#1 lore raw

PATCH 2/2 extcon: axp288: Use for_each_set_bit() in axp288_extcon_log_rsi()

This simplifies and standardizes axp288_extcon_log_rsi() by using for_each_set_bit() library function.

---
 drivers/extcon/extcon-axp288.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/extcon/extcon-axp288.c +5 -8
index 4cbcc3b1aa6b..670334c362ac 100644
@@ -121,7 +121,6 @@ static const char * const axp288_pwr_up_down_info[] = {
 	"Last shutdown caused by PMIC UVLO threshold",
 	"Last shutdown caused by SOC initiated cold off",
 	"Last shutdown caused by user pressing the power button",
-	NULL,
 };
 
 /*
@@ -130,20 +129,18 @@ static const char * const axp288_pwr_up_down_info[] = {
  */
 static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
 {
-	const char * const *rsi;
 	unsigned int val, i, clear_mask = 0;
+	unsigned long bits;
 	int ret;
 
 	ret = regmap_read(info->regmap, AXP288_PS_BOOT_REASON_REG, &val);
 	if (ret < 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);
-			clear_mask |= BIT(i);
-		}
-	}
+	bits = val & GENMASK(ARRAY_SIZE(axp288_pwr_up_down_info) - 1, 0);
+	for_each_set_bit(i, &bits, ARRAY_SIZE(axp288_pwr_up_down_info))
+		dev_dbg(info->dev, "%s\n", axp288_pwr_up_down_info[i]);
+	clear_mask = bits;
 
 	/* Clear the register value for next reboot (write 1 to clear bit) */
 	regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
Signature · 1 line
2.20.1
maintainer Acked-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] extcon: axp288: Use for_each_set_bit() in axp288_extcon_log_rsi()

Quoted 37 lines · Andy Shevchenko

This simplifies and standardizes axp288_extcon_log_rsi() by using for_each_set_bit() library function.

---
 drivers/extcon/extcon-axp288.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/extcon/extcon-axp288.c +1 -5
index 4cbcc3b1aa6b..670334c362ac 100644
@@ -121,7 +121,6 @@ static const char * const axp288_pwr_up_down_info[] = {
 	"Last shutdown caused by PMIC UVLO threshold",
 	"Last shutdown caused by SOC initiated cold off",
 	"Last shutdown caused by user pressing the power button",
-	NULL,
 };
 
 /*
@@ -130,20 +129,18 @@ static const char * const axp288_pwr_up_down_info[] = {
  */
 static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
 {
-	const char * const *rsi;
 	unsigned int val, i, clear_mask = 0;
+	unsigned long bits;
 	int ret;
 
 	ret = regmap_read(info->regmap, AXP288_PS_BOOT_REASON_REG, &val);
 	if (ret < 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);

drivers/extcon/extcon-axp288.c static const char * const axp288_pwr_up_down_info[] = { · line 146

Quoted 10 lines
drivers/extcon/extcon-axp288.c +4 -3
-			clear_mask |= BIT(i);
-		}
-	}
+	bits = val & GENMASK(ARRAY_SIZE(axp288_pwr_up_down_info) - 1, 0);
+	for_each_set_bit(i, &bits, ARRAY_SIZE(axp288_pwr_up_down_info))
+		dev_dbg(info->dev, "%s\n", axp288_pwr_up_down_info[i]);
+	clear_mask = bits;
 
 	/* Clear the register value for next reboot (write 1 to clear bit) */
 	regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 11 lines · Chanwoo Choi

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

Quoted 6 lines · Andy Shevchenko

It seems from the very beginning the error check has been missed in axp288_extcon_log_rsi(). Add it here.

drivers/extcon/extcon-axp288.c +2 -0
 	ret = regmap_read(info->regmap, AXP288_PS_BOOT_REASON_REG, &val);
+	if (ret < 0)
+		return;

It need to print error log because axp288_extcon_log_rsi() has the void' return type if there is no any error log, it is not possible to check the error status.

Makes sense.
Will add in v2.

P.S. You answered privately, I had returned Cc list back.

Signature · 2 lines
With Best Regards,
Andy Shevchenko