VMCI: Use kmalloc_array() in qp_alloc_ppn_set()
Subsystems (3)
PATCH 1/1 VMCI: Use kmalloc_array() in qp_alloc_ppn_set()
From: Markus Elfring <[email protected]>
Date: Sun, 8 Jan 2017 14:04:10 +0100
Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/misc/vmw_vmci/vmci_queue_pair.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/misc/vmw_vmci/vmci_queue_pair.c +6 -2
@@ -486,13 +486,15 @@ static int qp_alloc_ppn_set(void *prod_q,if (ppn_set->initialized)return VMCI_ERROR_ALREADY_EXISTS ; - produce_ppns -kmalloc (num_produce_pages *sizeof (*produce_ppns),GFP_KERNEL ); + produce_ppns =kmalloc_array (num_produce_pages, +sizeof (*produce_ppns), +GFP_KERNEL );if (!produce_ppns)return VMCI_ERROR_NO_MEM ; - consume_ppns -kmalloc (num_consume_pages *sizeof (*consume_ppns),GFP_KERNEL ); + consume_ppns =kmalloc_array (num_consume_pages, +sizeof (*consume_ppns), +GFP_KERNEL );if (!consume_ppns) {kfree (produce_ppns);return VMCI_ERROR_NO_MEM ;
Signature · 1 line
2.11.0
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 8 Jan 2017 14:04:10 +0100Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "
kmalloc_array".This issue was detected by using the Coccinelle software.
I am surprised that Coccinelle found a single instance of this pattern. If there are more then I would suggest changing all of them at once along with the coccinelle program which has been used.
Quoted 30 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/misc/vmw_vmci/vmci_queue_pair.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/misc/vmw_vmci/vmci_queue_pair.c +6
-2@@ -486,13 +486,15 @@ static int qp_alloc_ppn_set(void *prod_q,if (ppn_set->initialized)return VMCI_ERROR_ALREADY_EXISTS ; - produce_ppns > -kmalloc (num_produce_pages *sizeof (*produce_ppns),GFP_KERNEL ); + produce_ppns =kmalloc_array (num_produce_pages, +sizeof (*produce_ppns), +GFP_KERNEL );if (!produce_ppns)return VMCI_ERROR_NO_MEM ; - consume_ppns > -kmalloc (num_consume_pages *sizeof (*consume_ppns),GFP_KERNEL ); + consume_ppns =kmalloc_array (num_consume_pages, +sizeof (*consume_ppns), +GFP_KERNEL );if (!consume_ppns) {kfree (produce_ppns);return VMCI_ERROR_NO_MEM ;Signature · 1 line
2.11.0
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 2 lines
If there are more then I would suggest changing all of them at once along with the coccinelle program which has been used.
There are still hundreds of similar update candidates left over for other software modules. The acceptance is varying for the proposed refactoring by the involved developers and source code reviewers.
Regards,
Markus