Browse Source

thermal: core: treat correctly the return value of *scanf calls

This patch checks the return value of all calls to *scanf.
The check is to simply match the number of expect inputs.

The current code does not do any recovery in case the
number of treated inputs are different than the expected.
Therefore, keeping the same behavior.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Eduardo Valentin 8 years ago
parent
commit
09544da9e8
1 changed files with 7 additions and 7 deletions
  1. 7 7
      drivers/thermal/thermal_core.c

+ 7 - 7
drivers/thermal/thermal_core.c

@@ -874,7 +874,7 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,
 	if (!tz->ops->get_trip_type)
 	if (!tz->ops->get_trip_type)
 		return -EPERM;
 		return -EPERM;
 
 
-	if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip))
+	if (sscanf(attr->attr.name, "trip_point_%d_type", &trip) != 1)
 		return -EINVAL;
 		return -EINVAL;
 
 
 	result = tz->ops->get_trip_type(tz, trip, &type);
 	result = tz->ops->get_trip_type(tz, trip, &type);
@@ -906,7 +906,7 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
 	if (!tz->ops->set_trip_temp)
 	if (!tz->ops->set_trip_temp)
 		return -EPERM;
 		return -EPERM;
 
 
-	if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
+	if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip) != 1)
 		return -EINVAL;
 		return -EINVAL;
 
 
 	if (kstrtoint(buf, 10, &temperature))
 	if (kstrtoint(buf, 10, &temperature))
@@ -932,7 +932,7 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
 	if (!tz->ops->get_trip_temp)
 	if (!tz->ops->get_trip_temp)
 		return -EPERM;
 		return -EPERM;
 
 
-	if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
+	if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip) != 1)
 		return -EINVAL;
 		return -EINVAL;
 
 
 	ret = tz->ops->get_trip_temp(tz, trip, &temperature);
 	ret = tz->ops->get_trip_temp(tz, trip, &temperature);
@@ -954,7 +954,7 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
 	if (!tz->ops->set_trip_hyst)
 	if (!tz->ops->set_trip_hyst)
 		return -EPERM;
 		return -EPERM;
 
 
-	if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
+	if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip) != 1)
 		return -EINVAL;
 		return -EINVAL;
 
 
 	if (kstrtoint(buf, 10, &temperature))
 	if (kstrtoint(buf, 10, &temperature))
@@ -984,7 +984,7 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
 	if (!tz->ops->get_trip_hyst)
 	if (!tz->ops->get_trip_hyst)
 		return -EPERM;
 		return -EPERM;
 
 
-	if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
+	if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip) != 1)
 		return -EINVAL;
 		return -EINVAL;
 
 
 	ret = tz->ops->get_trip_hyst(tz, trip, &temperature);
 	ret = tz->ops->get_trip_hyst(tz, trip, &temperature);
@@ -999,7 +999,7 @@ passive_store(struct device *dev, struct device_attribute *attr,
 	struct thermal_zone_device *tz = to_thermal_zone(dev);
 	struct thermal_zone_device *tz = to_thermal_zone(dev);
 	int state;
 	int state;
 
 
-	if (!sscanf(buf, "%d\n", &state))
+	if (sscanf(buf, "%d\n", &state) != 1)
 		return -EINVAL;
 		return -EINVAL;
 
 
 	/* sanity check: values below 1000 millicelcius don't make sense
 	/* sanity check: values below 1000 millicelcius don't make sense
@@ -1457,7 +1457,7 @@ thermal_cooling_device_cur_state_store(struct device *dev,
 	unsigned long state;
 	unsigned long state;
 	int result;
 	int result;
 
 
-	if (!sscanf(buf, "%ld\n", &state))
+	if (sscanf(buf, "%ld\n", &state) != 1)
 		return -EINVAL;
 		return -EINVAL;
 
 
 	if ((long)state < 0)
 	if ((long)state < 0)