Skip to contentSkip to conversation

Thermal/int340x: Fine-tuning for five function implementations

PATCH New SF Markus Elfring 1 participant 4 messages Apr 10, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Thermal/int340x: Fine-tuning for five function implementations

From: Markus Elfring <[email protected]>
Date: Mon, 10 Apr 2017 22:08:11 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Use kcalloc() in two functions
Improve size determinations in two functions
Use kcalloc() in int340x_thermal_zone_add()

 drivers/thermal/int340x_thermal/acpi_thermal_rel.c     | 8 ++++----
 drivers/thermal/int340x_thermal/int340x_thermal_zone.c | 7 ++++---
 2 files changed, 8 insertions(+), 7 deletions(-)
Signature · 1 line
2.12.2
#1 lore raw

PATCH 1/3 ACPI/int340x_thermal: Use kcalloc() in two functions

From: Markus Elfring <[email protected]>
Date: Mon, 10 Apr 2017 21:30:47 +0200

* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of data structures by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thermal/int340x_thermal/acpi_thermal_rel.c +2 -2
index 2c2ec7666eb1..52a5fe0f81e8 100644
@@ -96,7 +96,7 @@ int acpi_parse_trt(acpi_handle handle, int *trt_count, struct trt **trtp,
 	}
 
 	*trt_count = p->package.count;
-	trts = kzalloc(*trt_count * sizeof(struct trt), GFP_KERNEL);
+	trts = kcalloc(*trt_count, sizeof(*trts), GFP_KERNEL);
 	if (!trts) {
 		result = -ENOMEM;
 		goto end;
@@ -178,7 +178,7 @@ int acpi_parse_art(acpi_handle handle, int *art_count, struct art **artp,
 
 	/* ignore p->package.elements[0], as this is _ART Revision field */
 	*art_count = p->package.count - 1;
-	arts = kzalloc(*art_count * sizeof(struct art), GFP_KERNEL);
+	arts = kcalloc(*art_count, sizeof(*arts), GFP_KERNEL);
 	if (!arts) {
 		result = -ENOMEM;
 		goto end;
Signature · 1 line
2.12.2
#2 lore raw

PATCH 2/3 ACPI/int340x_thermal: Improve size determinations in two functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 10 Apr 2017 21:42:44 +0200

Replace the specification of two data types by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determinations a bit safer according to the Linux coding style convention.

---
 drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thermal/int340x_thermal/acpi_thermal_rel.c +2 -2
index 52a5fe0f81e8..d7791b1fec33 100644
@@ -247,7 +247,7 @@ static int fill_art(char __user *ubuf)
 	ret = acpi_parse_art(acpi_thermal_rel_handle, &count, &arts, false);
 	if (ret)
 		goto free_art;
-	art_len = count * sizeof(union art_object);
+	art_len = count * sizeof(*art_user);
 	art_user = kzalloc(art_len, GFP_KERNEL);
 	if (!art_user) {
 		ret = -ENOMEM;
@@ -283,7 +283,7 @@ static int fill_trt(char __user *ubuf)
 	ret = acpi_parse_trt(acpi_thermal_rel_handle, &count, &trts, false);
 	if (ret)
 		goto free_trt;
-	trt_len = count * sizeof(union trt_object);
+	trt_len = count * sizeof(*trt_user);
 	trt_user = kzalloc(trt_len, GFP_KERNEL);
 	if (!trt_user) {
 		ret = -ENOMEM;
Signature · 1 line
2.12.2
#3 lore raw

PATCH 3/3 thermal: int340x: Use kcalloc() in int340x_thermal_zone_add()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 10 Apr 2017 21:56:58 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

---
 drivers/thermal/int340x_thermal/int340x_thermal_zone.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/thermal/int340x_thermal/int340x_thermal_zone.c +4 -3
index 145a5c53ff5c..a611f3367168 100644
@@ -239,9 +239,10 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
 	if (ACPI_FAILURE(status))
 		trip_cnt = 0;
 	else {
-		int34x_thermal_zone->aux_trips = kzalloc(
-				sizeof(*int34x_thermal_zone->aux_trips) *
-				trip_cnt, GFP_KERNEL);
+		int34x_thermal_zone->aux_trips
+			= kcalloc(trip_cnt,
+				  sizeof(*int34x_thermal_zone->aux_trips),
+				  GFP_KERNEL);
 		if (!int34x_thermal_zone->aux_trips) {
 			ret = -ENOMEM;
 			goto err_trip_alloc;
Signature · 1 line
2.12.2