From f744c86c590ca01b9373fa411d744bc870334f62 Mon Sep 17 00:00:00 2001 From: Jeff Ohlstein Date: Wed, 1 Feb 2012 17:52:44 -0800 Subject: [PATCH] thermal: msm8960_tsens: nullify tmdev when early_init fails The initialization code uses the tmdev variable as an indicator as to whether or not early initialization succeeded. However, when early init fails, it only kfrees the pointer, it doesn't set it to NULL. This causes us to dereference the now-freed pointer. Additionally, squash the message that prints each time we fail to read the temperature sensor, and print a warning to the kernel log when tsens calibration data is not present. Change-Id: Iab400cac687cdbc36d8c69541675c29a0b82c704 Signed-off-by: Jeff Ohlstein --- drivers/thermal/msm8960_tsens.c | 7 +++++-- drivers/thermal/msm_thermal.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/msm8960_tsens.c b/drivers/thermal/msm8960_tsens.c index f2be9dc982f..2a2166a0398 100644 --- a/drivers/thermal/msm8960_tsens.c +++ b/drivers/thermal/msm8960_tsens.c @@ -176,7 +176,6 @@ static void tsens8960_get_temp(int sensor_num, unsigned long *temp) TSENS_TRDY_RDY_MAX_TIME); tmdev->prev_reading_avail = true; } - code = readl_relaxed(TSENS_S0_STATUS_ADDR + (sensor_num << TSENS_STATUS_ADDR_OFFSET)); *temp = tsens_tz_code_to_degC(code, sensor_num); @@ -726,7 +725,7 @@ static int tsens_calib_sensors8960(void) tmdev->sensor[i].calib_data_backup; if (!tmdev->sensor[i].calib_data) { - pr_err("%s: No temperature sensor:%d data for" + WARN(1, "%s: No temperature sensor:%d data for" " calibration in QFPROM!\n", __func__, i); return -ENODEV; } @@ -789,12 +788,14 @@ int msm_tsens_early_init(struct tsens_platform_data *pdata) rc = tsens_check_version_support(); if (rc < 0) { kfree(tmdev); + tmdev = NULL; return rc; } rc = tsens_calib_sensors(); if (rc < 0) { kfree(tmdev); + tmdev = NULL; return rc; } @@ -846,6 +847,7 @@ static int __init tsens_tm_init(void) fail: tsens_disable_mode(); kfree(tmdev); + tmdev = NULL; mb(); return rc; } @@ -860,6 +862,7 @@ static void __exit tsens_tm_remove(void) for (i = 0; i < tmdev->tsens_num_sensor; i++) thermal_zone_device_unregister(tmdev->sensor[i].tz_dev); kfree(tmdev); + tmdev = NULL; } module_init(tsens_tm_init); diff --git a/drivers/thermal/msm_thermal.c b/drivers/thermal/msm_thermal.c index 25290ba44ec..ed80b1b32b4 100644 --- a/drivers/thermal/msm_thermal.c +++ b/drivers/thermal/msm_thermal.c @@ -75,7 +75,7 @@ static void check_temp(struct work_struct *work) tsens_dev.sensor_num = DEF_TEMP_SENSOR; ret = tsens_get_temp(&tsens_dev, &temp); if (ret) { - pr_err("msm_thermal: Unable to read TSENS sensor %d\n", + pr_debug("msm_thermal: Unable to read TSENS sensor %d\n", tsens_dev.sensor_num); goto reschedule; }