Skip to contentSkip to conversation

s3c-adc-battery: Fix possible NULL pointer dereference

PATCH Applied Syam Sidhardhan 2 participants 2 messages Feb 24, 2013 – Mar 19, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s3c-adc-battery: Fix possible NULL pointer dereference

Check for (bat == NULL) has to be done before accessing bat

---
 drivers/power/s3c_adc_battery.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/power/s3c_adc_battery.c +5 -2
index d2ca989..5948ce0 100644
@@ -145,14 +145,17 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
 
 	int new_level;
 	int full_volt;
-	const struct s3c_adc_bat_thresh *lut = bat->pdata->lut_noac;
-	unsigned int lut_size = bat->pdata->lut_noac_cnt;
+	const struct s3c_adc_bat_thresh *lut;
+	unsigned int lut_size;
 
 	if (!bat) {
 		dev_err(psy->dev, "no battery infos ?!\n");
 		return -EINVAL;
 	}
 
+	lut = bat->pdata->lut_noac;
+	lut_size = bat->pdata->lut_noac_cnt;
+
 	if (bat->volt_value < 0 || bat->cur_value < 0 ||
 		jiffies_to_msecs(jiffies - bat->timestamp) >
 			BAT_POLL_INTERVAL) {
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 4 lines · Syam Sidhardhan

Check for (bat == NULL) has to be done before accessing bat

---

Applied, thanks!

Quoted 29 lines
 drivers/power/s3c_adc_battery.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/power/s3c_adc_battery.c +5 -2
index d2ca989..5948ce0 100644
@@ -145,14 +145,17 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
 
 	int new_level;
 	int full_volt;
-	const struct s3c_adc_bat_thresh *lut = bat->pdata->lut_noac;
-	unsigned int lut_size = bat->pdata->lut_noac_cnt;
+	const struct s3c_adc_bat_thresh *lut;
+	unsigned int lut_size;
 
 	if (!bat) {
 		dev_err(psy->dev, "no battery infos ?!\n");
 		return -EINVAL;
 	}
 
+	lut = bat->pdata->lut_noac;
+	lut_size = bat->pdata->lut_noac_cnt;
+
 	if (bat->volt_value < 0 || bat->cur_value < 0 ||
 		jiffies_to_msecs(jiffies - bat->timestamp) >
 			BAT_POLL_INTERVAL) {
Signature · 1 line
1.7.9.5