Patchwork [U-Boot] power:pmic: prevent data abort for pmic bat command

login
register
mail settings
Submitter Piotr Wilczek
Date Sept. 26, 2013, 12:43 p.m.
Message ID <1380199415-2139-1-git-send-email-p.wilczek@samsung.com>
Download mbox | patch
Permalink /patch/278189/
State Accepted
Delegated to: Tom Rini
Headers show

Comments

Piotr Wilczek - Sept. 26, 2013, 12:43 p.m.
This patch prevents data abort when pmic bat command is called
on non-batery pmic device.

Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
CC: Lukasz Majewski <l.majewski@samsung.com>
CC: Minkyu Kang <mk7.kang@samsung.com>
---
 drivers/power/power_core.c |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
Tom Rini - Oct. 7, 2013, 8:04 p.m.
On Thu, Sep 26, 2013 at 02:43:35PM +0200, Piotr Wilczek wrote:

> This patch prevents data abort when pmic bat command is called
> on non-batery pmic device.
> 
> Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> CC: Lukasz Majewski <l.majewski@samsung.com>
> CC: Minkyu Kang <mk7.kang@samsung.com>

Applied to u-boot/master, thanks!

Patch

diff --git a/drivers/power/power_core.c b/drivers/power/power_core.c
index 583e56b..d9bc05f 100644
--- a/drivers/power/power_core.c
+++ b/drivers/power/power_core.c
@@ -188,18 +188,21 @@  int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (argc < 4)
 			return CMD_RET_USAGE;
 
+		if (!p->pbat) {
+			printf("%s is not a battery\n", p->name);
+			return CMD_RET_FAILURE;
+		}
+
 		if (strcmp(argv[3], "state") == 0)
 			p->fg->fg_battery_check(p->pbat->fg, p);
 
 		if (strcmp(argv[3], "charge") == 0) {
-			if (p->pbat) {
-				printf("BAT: %s charging (ctrl+c to break)\n",
-				       p->name);
-				if (p->low_power_mode)
-					p->low_power_mode();
-				if (p->pbat->battery_charge)
-					p->pbat->battery_charge(p);
-			}
+			printf("BAT: %s charging (ctrl+c to break)\n",
+			       p->name);
+			if (p->low_power_mode)
+				p->low_power_mode();
+			if (p->pbat->battery_charge)
+				p->pbat->battery_charge(p);
 		}
 
 		return CMD_RET_SUCCESS;