Skip to contentSkip to conversation

md/dm-stats: Use kmalloc_array() in parse_histogram()

PATCH New SF Markus Elfring 1 participant 1 message Oct 1, 2016

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

PATCH 1/1 md/dm-stats: Use kmalloc_array() in parse_histogram()

From: Markus Elfring <[email protected]>
Date: Sat, 1 Oct 2016 05:55:05 +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 "kmalloc_array".

This issue was detected by using the Coccinelle software.

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

---
 drivers/md/dm-stats.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/md/dm-stats.c +3 -1
index 38b05f2..7b79425 100644
@@ -917,7 +917,9 @@ static int parse_histogram(const char *h, unsigned *n_histogram_entries,
 		if (*q == ',')
 			(*n_histogram_entries)++;
 
-	*histogram_boundaries = kmalloc(*n_histogram_entries * sizeof(unsigned long long), GFP_KERNEL);
+	*histogram_boundaries = kmalloc_array(*n_histogram_entries,
+					      sizeof(**histogram_boundaries),
+					      GFP_KERNEL);
 	if (!*histogram_boundaries)
 		return -ENOMEM;
 
Signature · 1 line
2.10.0