linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Thermal/int340x: Fine-tuning for five function implementations
@ 2017-04-10 20:15 SF Markus Elfring
  2017-04-10 20:18 ` [PATCH 1/3] ACPI/int340x_thermal: Use kcalloc() in two functions SF Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-04-10 20:15 UTC (permalink / raw)
  To: linux-pm, Eduardo Valentin, Srinivas Pandruvada, Zhang Rui
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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(-)

-- 
2.12.2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] ACPI/int340x_thermal: Use kcalloc() in two functions
  2017-04-10 20:15 [PATCH 0/3] Thermal/int340x: Fine-tuning for five function implementations SF Markus Elfring
@ 2017-04-10 20:18 ` SF Markus Elfring
  2017-04-10 20:19 ` [PATCH 2/3] ACPI/int340x_thermal: Improve size determinations " SF Markus Elfring
  2017-04-10 20:20 ` [PATCH 3/3] thermal: int340x: Use kcalloc() in int340x_thermal_zone_add() SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-04-10 20:18 UTC (permalink / raw)
  To: linux-pm, Eduardo Valentin, Srinivas Pandruvada, Zhang Rui
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/int340x_thermal/acpi_thermal_rel.c b/drivers/thermal/int340x_thermal/acpi_thermal_rel.c
index 2c2ec7666eb1..52a5fe0f81e8 100644
--- a/drivers/thermal/int340x_thermal/acpi_thermal_rel.c
+++ b/drivers/thermal/int340x_thermal/acpi_thermal_rel.c
@@ -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;
-- 
2.12.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] ACPI/int340x_thermal: Improve size determinations in two functions
  2017-04-10 20:15 [PATCH 0/3] Thermal/int340x: Fine-tuning for five function implementations SF Markus Elfring
  2017-04-10 20:18 ` [PATCH 1/3] ACPI/int340x_thermal: Use kcalloc() in two functions SF Markus Elfring
@ 2017-04-10 20:19 ` SF Markus Elfring
  2017-04-10 20:20 ` [PATCH 3/3] thermal: int340x: Use kcalloc() in int340x_thermal_zone_add() SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-04-10 20:19 UTC (permalink / raw)
  To: linux-pm, Eduardo Valentin, Srinivas Pandruvada, Zhang Rui
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/thermal/int340x_thermal/acpi_thermal_rel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/int340x_thermal/acpi_thermal_rel.c b/drivers/thermal/int340x_thermal/acpi_thermal_rel.c
index 52a5fe0f81e8..d7791b1fec33 100644
--- a/drivers/thermal/int340x_thermal/acpi_thermal_rel.c
+++ b/drivers/thermal/int340x_thermal/acpi_thermal_rel.c
@@ -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;
-- 
2.12.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] thermal: int340x: Use kcalloc() in int340x_thermal_zone_add()
  2017-04-10 20:15 [PATCH 0/3] Thermal/int340x: Fine-tuning for five function implementations SF Markus Elfring
  2017-04-10 20:18 ` [PATCH 1/3] ACPI/int340x_thermal: Use kcalloc() in two functions SF Markus Elfring
  2017-04-10 20:19 ` [PATCH 2/3] ACPI/int340x_thermal: Improve size determinations " SF Markus Elfring
@ 2017-04-10 20:20 ` SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-04-10 20:20 UTC (permalink / raw)
  To: linux-pm, Eduardo Valentin, Srinivas Pandruvada, Zhang Rui
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/thermal/int340x_thermal/int340x_thermal_zone.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/int340x_thermal/int340x_thermal_zone.c
index 145a5c53ff5c..a611f3367168 100644
--- a/drivers/thermal/int340x_thermal/int340x_thermal_zone.c
+++ b/drivers/thermal/int340x_thermal/int340x_thermal_zone.c
@@ -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;
-- 
2.12.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-10 20:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-10 20:15 [PATCH 0/3] Thermal/int340x: Fine-tuning for five function implementations SF Markus Elfring
2017-04-10 20:18 ` [PATCH 1/3] ACPI/int340x_thermal: Use kcalloc() in two functions SF Markus Elfring
2017-04-10 20:19 ` [PATCH 2/3] ACPI/int340x_thermal: Improve size determinations " SF Markus Elfring
2017-04-10 20:20 ` [PATCH 3/3] thermal: int340x: Use kcalloc() in int340x_thermal_zone_add() SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).