summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorColin Patrick McCabe <cmccabe@nvidia.com>2011-11-03 16:21:15 -0700
committerDan Willemsen <dwillemsen@nvidia.com>2013-09-14 00:48:46 -0700
commitc8fd554f78a5439b5cf5aeb09fbf789bb7ceae6b (patch)
treec2917cf35a8597d6fe5a94e8ea130a5f16526852 /drivers
parent0373516ae3d6bc04b508d846d2a66bc3c1e6692c (diff)
hwmon: tegra-tsensor: minor cleanup
* when outputting to sysfs, we only have to worry about not overflowing a single page in memory. * don't use strcat * avoid passing data between functions by mutating global strings Change-Id: I8914a9ee282c63a4259c1bcaf9e550328a5664ec Signed-off-by: Colin Patrick McCabe <cmccabe@nvidia.com> Reviewed-on: http://git-master/r/63672 Reviewed-by: Bitan Biswas <bbiswas@nvidia.com> Rebase-Id: Rd3426d0c534a846624a4d55be851a88c67ba6d67
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/tegra-tsensor.c69
1 files changed, 23 insertions, 46 deletions
diff --git a/drivers/hwmon/tegra-tsensor.c b/drivers/hwmon/tegra-tsensor.c
index 2f14ea68a979..2195b7582fa8 100644
--- a/drivers/hwmon/tegra-tsensor.c
+++ b/drivers/hwmon/tegra-tsensor.c
@@ -14,11 +14,6 @@
*
*/
-#if 0
-#define VERBOSE_DEBUG
-#define DEBUG
-#endif
-
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/hwmon.h>
@@ -225,10 +220,6 @@ static struct tegra_tsensor_coeff coeff_table[] = {
/* FIXME: add tsensor coefficients after chip characterization */
};
-static char my_fixed_str[LOCAL_STR_SIZE1] = "YYYYYY";
-static char error_str[LOCAL_STR_SIZE1] = "ERROR:";
-static unsigned int init_flag;
-
static int tsensor_count_2_temp(struct tegra_tsensor_data *data,
unsigned int count, int *p_temperature);
static unsigned int tsensor_get_threshold_counter(
@@ -452,17 +443,13 @@ static ssize_t tsensor_show_counters(struct device *dev,
curr_avg[1], min_max[1], temp1);
if (err < 0)
goto error;
- snprintf(buf, (((LOCAL_STR_SIZE1 << 1) + 3) +
- strlen(fixed_str)),
- "%s "
+ snprintf(buf, PAGE_SIZE, "%s "
"[%d]: current counter=0x%x, %d.%d"
- " deg Celsius ", fixed_str,
- data->tsensor_index,
+ " deg Celsius\n", fixed_str, data->tsensor_index,
((curr_avg[data->tsensor_index] & 0xFFFF0000) >> 16),
get_temperature_int(temp1),
get_temperature_fraction(temp1));
}
- strcat(buf, "\n");
return strlen(buf);
error:
return snprintf(buf, strlen(err_str),
@@ -490,28 +477,29 @@ static bool cclkg_check_hwdiv2_sensor(struct tegra_tsensor_data *data)
*/
static int get_param_values(
struct tegra_tsensor_data *data, unsigned int indx,
- unsigned int *p_reg, unsigned int *p_sft, unsigned int *p_msk)
+ unsigned int *p_reg, unsigned int *p_sft, unsigned int *p_msk,
+ char *info, size_t info_len)
{
switch (indx) {
case TSENSOR_PARAM_TH1:
*p_reg = ((data->tsensor_index << 16) | SENSOR_CFG1);
*p_sft = SENSOR_CFG1_TH1_SHIFT;
*p_msk = SENSOR_CFG_X_TH_X_MASK;
- snprintf(my_fixed_str, LOCAL_STR_SIZE1, "TH1[%d]: ",
+ snprintf(info, info_len, "TH1[%d]: ",
data->tsensor_index);
break;
case TSENSOR_PARAM_TH2:
*p_reg = ((data->tsensor_index << 16) | SENSOR_CFG1);
*p_sft = SENSOR_CFG1_TH2_SHIFT;
*p_msk = SENSOR_CFG_X_TH_X_MASK;
- snprintf(my_fixed_str, LOCAL_STR_SIZE1, "TH2[%d]: ",
+ snprintf(info, info_len, "TH2[%d]: ",
data->tsensor_index);
break;
case TSENSOR_PARAM_TH3:
*p_reg = ((data->tsensor_index << 16) | SENSOR_CFG2);
*p_sft = SENSOR_CFG2_TH3_SHIFT;
*p_msk = SENSOR_CFG_X_TH_X_MASK;
- snprintf(my_fixed_str, LOCAL_STR_SIZE1, "TH3[%d]: ",
+ snprintf(info, info_len, "TH3[%d]: ",
data->tsensor_index);
break;
default:
@@ -533,28 +521,27 @@ static ssize_t show_tsensor_param(struct device *dev,
unsigned int msk;
int err;
int temp;
+ char info[LOCAL_STR_SIZE1];
- err = get_param_values(data, attr->index, &reg, &sft, &msk);
+ err = get_param_values(data, attr->index, &reg, &sft, &msk,
+ info, sizeof(info));
if (err < 0)
goto labelErr;
val = tsensor_get_reg_field(data, reg, sft, msk);
if (val == MAX_THRESHOLD)
- snprintf(buf, LOCAL_STR_SIZE1 + strlen(my_fixed_str),
- "%s un-initialized threshold ",
- my_fixed_str);
+ snprintf(buf, PAGE_SIZE, "%s un-initialized threshold\n", info);
else {
err = tsensor_count_2_temp(data, val, &temp);
if (err != 0)
goto labelErr;
- snprintf(buf, LOCAL_STR_SIZE1 + strlen(my_fixed_str),
- "%s threshold: %d.%d Celsius ",
- my_fixed_str, get_temperature_int(temp),
+ snprintf(buf, PAGE_SIZE, "%s threshold: %d.%d Celsius\n", info,
+ get_temperature_int(temp),
get_temperature_fraction(temp));
}
- strcat(buf, "\n");
return strlen(buf);
+
labelErr:
- snprintf(buf, strlen(error_str), "%s", error_str);
+ snprintf(buf, PAGE_SIZE, "ERROR:");
return strlen(buf);
}
@@ -572,6 +559,7 @@ static ssize_t set_tsensor_param(struct device *dev,
int err;
unsigned int counter;
unsigned int val;
+ char info[LOCAL_STR_SIZE1];
if (strict_strtoul(buf, 0, (long int *)&num)) {
dev_err(dev, "file: %s, line=%d return %s()\n",
@@ -581,7 +569,8 @@ static ssize_t set_tsensor_param(struct device *dev,
counter = tsensor_get_threshold_counter(data, num);
- err = get_param_values(data, attr->index, &reg, &sft, &msk);
+ err = get_param_values(data, attr->index, &reg, &sft, &msk,
+ info, sizeof(info));
if (err < 0)
goto labelErr;
@@ -595,7 +584,7 @@ static ssize_t set_tsensor_param(struct device *dev,
(void)cclkg_check_hwdiv2_sensor(data);
}
val = tsensor_get_reg_field(data, reg, sft, msk);
- dev_dbg(dev, "%s 0x%x\n", my_fixed_str, val);
+ dev_dbg(dev, "%s 0x%x\n", info, val);
return count;
labelErr:
dev_err(dev, "file: %s, line=%d, %s(), error=0x%x\n", __FILE__,
@@ -1800,28 +1789,16 @@ static struct platform_driver tegra_tsensor_driver = {
static int __init tegra_tsensor_init(void)
{
- init_flag = 0;
- if (platform_driver_register(&tegra_tsensor_driver))
- goto exit;
- init_flag = 1;
- return 0;
-
-exit:
- return -ENODEV;
+ return platform_driver_register(&tegra_tsensor_driver);
}
+module_init(tegra_tsensor_init);
static void __exit tegra_tsensor_exit(void)
{
- if (init_flag) {
- platform_driver_unregister(&tegra_tsensor_driver);
- init_flag = 0;
- }
+ platform_driver_unregister(&tegra_tsensor_driver);
}
+module_exit(tegra_tsensor_exit);
MODULE_AUTHOR("nvidia");
MODULE_DESCRIPTION("Nvidia Tegra Temperature Sensor driver");
MODULE_LICENSE("GPL");
-
-module_init(tegra_tsensor_init);
-module_exit(tegra_tsensor_exit);
-