linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] VMCI: Use kmalloc_array() in qp_alloc_ppn_set()
@ 2017-01-08 16:37 SF Markus Elfring
  2017-01-09  9:40 ` Michal Hocko
  0 siblings, 1 reply; 3+ messages in thread
From: SF Markus Elfring @ 2017-01-08 16:37 UTC (permalink / raw)
  To: Andrew Morton, George Zhang, Kirill A. Shutemov, Masahiro Yamada,
	Michal Hocko
  Cc: LKML, kernel-janitors

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

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/misc/vmw_vmci/vmci_queue_pair.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
index 498c0854305f..7b5c8a89cc54 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -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;
-- 
2.11.0

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

* Re: [PATCH] VMCI: Use kmalloc_array() in qp_alloc_ppn_set()
  2017-01-08 16:37 [PATCH] VMCI: Use kmalloc_array() in qp_alloc_ppn_set() SF Markus Elfring
@ 2017-01-09  9:40 ` Michal Hocko
  2017-01-09 11:48   ` SF Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Hocko @ 2017-01-09  9:40 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: Andrew Morton, George Zhang, Kirill A. Shutemov, Masahiro Yamada,
	LKML, kernel-janitors

On Sun 08-01-17 17:37:08, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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.

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.

> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/misc/vmw_vmci/vmci_queue_pair.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
> index 498c0854305f..7b5c8a89cc54 100644
> --- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
> +++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
> @@ -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;
> -- 
> 2.11.0
> 

-- 
Michal Hocko
SUSE Labs

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

* Re: VMCI: Use kmalloc_array() in qp_alloc_ppn_set()
  2017-01-09  9:40 ` Michal Hocko
@ 2017-01-09 11:48   ` SF Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-01-09 11:48 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Andrew Morton, George Zhang, Kirill A. Shutemov, Masahiro Yamada,
	LKML, kernel-janitors

> 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

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

end of thread, other threads:[~2017-01-09 11:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-08 16:37 [PATCH] VMCI: Use kmalloc_array() in qp_alloc_ppn_set() SF Markus Elfring
2017-01-09  9:40 ` Michal Hocko
2017-01-09 11:48   ` 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).