[PATCH 1/6] staging: vchiq_arm: Use kmalloc_array() in dump_phys_mem()

SF Markus Elfring elfring at users.sourceforge.net
Sat Dec 31 13:58:54 PST 2016


From: Markus Elfring <elfring at users.sourceforge.net>
Date: Sat, 31 Dec 2016 17:50:25 +0100

* 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.

Signed-off-by: Markus Elfring <elfring at users.sourceforge.net>
---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index 610e0d6d93bb..4af77d790ae0 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -1558,8 +1558,7 @@ dump_phys_mem(void *virt_addr, uint32_t num_bytes)
 	end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
 
 	num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
-
-	pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
+	pages = kmalloc_array(num_pages, sizeof(*pages), GFP_KERNEL);
 	if (pages == NULL) {
 		vchiq_log_error(vchiq_arm_log_level,
 			"Unable to allocation memory for %d pages\n",
-- 
2.11.0




More information about the linux-rpi-kernel mailing list