diff mbox

charger-manager: Fix a bug in checking battery temperature.

Message ID 1390297732-2708-1-git-send-email-jonghwa3.lee@samsung.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Jonghwa Lee Jan. 21, 2014, 9:48 a.m. UTC
Removing faulty typecast which converts 'int *' to 'unsigned long *'.
It would make unintended result for 64bit machine especially using Big-endian.

Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
---
 drivers/power/charger-manager.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index ec5c140..8f73790 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -560,15 +560,20 @@  static int cm_get_battery_temperature(struct charger_manager *cm,
 		return -ENODEV;
 
 #ifdef CONFIG_THERMAL
-	ret = thermal_zone_get_temp(cm->tzd_batt, (unsigned long *)temp);
-	if (!ret)
-		/* Calibrate temperature unit */
-		*temp /= 100;
-#else
+	if (cm->tzd_batt && !IS_ERR(cm->tzd_batt)) {
+		unsigned long _temp;
+		ret = thermal_zone_get_temp(cm->tzd_batt, &_temp);
+		if (!ret) {
+			/* Calibrate temperature unit */
+			_temp /= 100;
+			*temp = _temp;
+			return 0;
+		}
+	}
+#endif
 	ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
 				POWER_SUPPLY_PROP_TEMP,
 				(union power_supply_propval *)temp);
-#endif
 	return ret;
 }