Эх сурвалжийг харах

thermal: sysfs: use kcalloc() instead of kzalloc()

Simplify size computation by using kcalloc() for
allocating memory for arrays.

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 9 жил өмнө
parent
commit
b819dc9ef0

+ 8 - 5
drivers/thermal/thermal_sysfs.c

@@ -511,7 +511,6 @@ static const struct attribute_group *thermal_zone_attribute_groups[] = {
  */
  */
 static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 {
 {
-	int size = sizeof(struct thermal_attr) * tz->trips;
 	struct attribute **attrs;
 	struct attribute **attrs;
 	int indx;
 	int indx;
 
 
@@ -519,18 +518,22 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 	if (tz->trips <= 0)
 	if (tz->trips <= 0)
 		return -EINVAL;
 		return -EINVAL;
 
 
-	tz->trip_type_attrs = kzalloc(size, GFP_KERNEL);
+	tz->trip_type_attrs = kcalloc(tz->trips, sizeof(*tz->trip_type_attrs),
+				      GFP_KERNEL);
 	if (!tz->trip_type_attrs)
 	if (!tz->trip_type_attrs)
 		return -ENOMEM;
 		return -ENOMEM;
 
 
-	tz->trip_temp_attrs = kzalloc(size, GFP_KERNEL);
+	tz->trip_temp_attrs = kcalloc(tz->trips, sizeof(*tz->trip_temp_attrs),
+				      GFP_KERNEL);
 	if (!tz->trip_temp_attrs) {
 	if (!tz->trip_temp_attrs) {
 		kfree(tz->trip_type_attrs);
 		kfree(tz->trip_type_attrs);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 
 
 	if (tz->ops->get_trip_hyst) {
 	if (tz->ops->get_trip_hyst) {
-		tz->trip_hyst_attrs = kzalloc(size, GFP_KERNEL);
+		tz->trip_hyst_attrs = kcalloc(tz->trips,
+					      sizeof(*tz->trip_hyst_attrs),
+					      GFP_KERNEL);
 		if (!tz->trip_hyst_attrs) {
 		if (!tz->trip_hyst_attrs) {
 			kfree(tz->trip_type_attrs);
 			kfree(tz->trip_type_attrs);
 			kfree(tz->trip_temp_attrs);
 			kfree(tz->trip_temp_attrs);
@@ -538,7 +541,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 		}
 		}
 	}
 	}
 
 
-	attrs = kzalloc(sizeof(*attrs) * tz->trips * 3 + 1, GFP_KERNEL);
+	attrs = kcalloc(tz->trips * 3 + 1, sizeof(*attrs), GFP_KERNEL);
 	if (!attrs) {
 	if (!attrs) {
 		kfree(tz->trip_type_attrs);
 		kfree(tz->trip_type_attrs);
 		kfree(tz->trip_temp_attrs);
 		kfree(tz->trip_temp_attrs);