All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store()
@ 2016-09-01  9:38 ` SF Markus Elfring
  0 siblings, 0 replies; 8+ messages in thread
From: SF Markus Elfring @ 2016-09-01  9:38 UTC (permalink / raw)
  To: linux-s390, Heiko Carstens, Martin Schwidefsky, Michael Holzheu
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 1 Sep 2016 11:30: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 "kmalloc_array".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/s390/hypfs/hypfs_diag0c.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/s390/hypfs/hypfs_diag0c.c b/arch/s390/hypfs/hypfs_diag0c.c
index 0f1927c..61418a8 100644
--- a/arch/s390/hypfs/hypfs_diag0c.c
+++ b/arch/s390/hypfs/hypfs_diag0c.c
@@ -48,7 +48,9 @@ static void *diag0c_store(unsigned int *count)
 
 	get_online_cpus();
 	cpu_count = num_online_cpus();
-	cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(), GFP_KERNEL);
+	cpu_vec = kmalloc_array(num_possible_cpus(),
+				sizeof(*cpu_vec),
+				GFP_KERNEL);
 	if (!cpu_vec)
 		goto fail_put_online_cpus;
 	/* Note: Diag 0c needs 8 byte alignment and real storage */
-- 
2.9.3

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

* [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store()
@ 2016-09-01  9:38 ` SF Markus Elfring
  0 siblings, 0 replies; 8+ messages in thread
From: SF Markus Elfring @ 2016-09-01  9:38 UTC (permalink / raw)
  To: linux-s390, Heiko Carstens, Martin Schwidefsky, Michael Holzheu
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 1 Sep 2016 11:30: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 "kmalloc_array".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/s390/hypfs/hypfs_diag0c.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/s390/hypfs/hypfs_diag0c.c b/arch/s390/hypfs/hypfs_diag0c.c
index 0f1927c..61418a8 100644
--- a/arch/s390/hypfs/hypfs_diag0c.c
+++ b/arch/s390/hypfs/hypfs_diag0c.c
@@ -48,7 +48,9 @@ static void *diag0c_store(unsigned int *count)
 
 	get_online_cpus();
 	cpu_count = num_online_cpus();
-	cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(), GFP_KERNEL);
+	cpu_vec = kmalloc_array(num_possible_cpus(),
+				sizeof(*cpu_vec),
+				GFP_KERNEL);
 	if (!cpu_vec)
 		goto fail_put_online_cpus;
 	/* Note: Diag 0c needs 8 byte alignment and real storage */
-- 
2.9.3


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

* Re: [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store()
  2016-09-01  9:38 ` SF Markus Elfring
@ 2016-09-01 10:32   ` Heiko Carstens
  -1 siblings, 0 replies; 8+ messages in thread
From: Heiko Carstens @ 2016-09-01 10:32 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-s390, Martin Schwidefsky, Michael Holzheu, LKML,
	kernel-janitors, Julia Lawall, Paolo Bonzini

On Thu, Sep 01, 2016 at 11:38:15AM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 1 Sep 2016 11:30: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 "kmalloc_array".
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  arch/s390/hypfs/hypfs_diag0c.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/s390/hypfs/hypfs_diag0c.c b/arch/s390/hypfs/hypfs_diag0c.c
> index 0f1927c..61418a8 100644
> --- a/arch/s390/hypfs/hypfs_diag0c.c
> +++ b/arch/s390/hypfs/hypfs_diag0c.c
> @@ -48,7 +48,9 @@ static void *diag0c_store(unsigned int *count)
>  
>  	get_online_cpus();
>  	cpu_count = num_online_cpus();
> -	cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(), GFP_KERNEL);
> +	cpu_vec = kmalloc_array(num_possible_cpus(),
> +				sizeof(*cpu_vec),
> +				GFP_KERNEL);

How does this improve the situation? For any real life scenario this can't
overflow, but it does add an extra (pointless) runtime check, since
num_possible_cpus() is not a compile time constant.

So, why is this an "issue"?

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

* Re: [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store()
@ 2016-09-01 10:32   ` Heiko Carstens
  0 siblings, 0 replies; 8+ messages in thread
From: Heiko Carstens @ 2016-09-01 10:32 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-s390, Martin Schwidefsky, Michael Holzheu, LKML,
	kernel-janitors, Julia Lawall, Paolo Bonzini

On Thu, Sep 01, 2016 at 11:38:15AM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 1 Sep 2016 11:30: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 "kmalloc_array".
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  arch/s390/hypfs/hypfs_diag0c.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/s390/hypfs/hypfs_diag0c.c b/arch/s390/hypfs/hypfs_diag0c.c
> index 0f1927c..61418a8 100644
> --- a/arch/s390/hypfs/hypfs_diag0c.c
> +++ b/arch/s390/hypfs/hypfs_diag0c.c
> @@ -48,7 +48,9 @@ static void *diag0c_store(unsigned int *count)
>  
>  	get_online_cpus();
>  	cpu_count = num_online_cpus();
> -	cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(), GFP_KERNEL);
> +	cpu_vec = kmalloc_array(num_possible_cpus(),
> +				sizeof(*cpu_vec),
> +				GFP_KERNEL);

How does this improve the situation? For any real life scenario this can't
overflow, but it does add an extra (pointless) runtime check, since
num_possible_cpus() is not a compile time constant.

So, why is this an "issue"?


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

* Re: [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store()
  2016-09-01 10:32   ` Heiko Carstens
@ 2016-09-01 15:39     ` Paolo Bonzini
  -1 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2016-09-01 15:39 UTC (permalink / raw)
  To: Heiko Carstens, SF Markus Elfring
  Cc: linux-s390, Martin Schwidefsky, Michael Holzheu, LKML,
	kernel-janitors, Julia Lawall



On 01/09/2016 12:32, Heiko Carstens wrote:
> On Thu, Sep 01, 2016 at 11:38:15AM +0200, SF Markus Elfring wrote:
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Thu, 1 Sep 2016 11:30: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 "kmalloc_array".
>>
>> This issue was detected by using the Coccinelle software.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>> ---
>>  arch/s390/hypfs/hypfs_diag0c.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/s390/hypfs/hypfs_diag0c.c b/arch/s390/hypfs/hypfs_diag0c.c
>> index 0f1927c..61418a8 100644
>> --- a/arch/s390/hypfs/hypfs_diag0c.c
>> +++ b/arch/s390/hypfs/hypfs_diag0c.c
>> @@ -48,7 +48,9 @@ static void *diag0c_store(unsigned int *count)
>>  
>>  	get_online_cpus();
>>  	cpu_count = num_online_cpus();
>> -	cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(), GFP_KERNEL);
>> +	cpu_vec = kmalloc_array(num_possible_cpus(),
>> +				sizeof(*cpu_vec),
>> +				GFP_KERNEL);
> 
> How does this improve the situation? For any real life scenario this can't
> overflow, but it does add an extra (pointless) runtime check, since
> num_possible_cpus() is not a compile time constant.
> 
> So, why is this an "issue"?

It's not an issue but I for one still prefer consistent use of
kmalloc_array and kcalloc.

Paolo

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

* Re: [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store()
@ 2016-09-01 15:39     ` Paolo Bonzini
  0 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2016-09-01 15:39 UTC (permalink / raw)
  To: Heiko Carstens, SF Markus Elfring
  Cc: linux-s390, Martin Schwidefsky, Michael Holzheu, LKML,
	kernel-janitors, Julia Lawall



On 01/09/2016 12:32, Heiko Carstens wrote:
> On Thu, Sep 01, 2016 at 11:38:15AM +0200, SF Markus Elfring wrote:
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Thu, 1 Sep 2016 11:30: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 "kmalloc_array".
>>
>> This issue was detected by using the Coccinelle software.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>> ---
>>  arch/s390/hypfs/hypfs_diag0c.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/s390/hypfs/hypfs_diag0c.c b/arch/s390/hypfs/hypfs_diag0c.c
>> index 0f1927c..61418a8 100644
>> --- a/arch/s390/hypfs/hypfs_diag0c.c
>> +++ b/arch/s390/hypfs/hypfs_diag0c.c
>> @@ -48,7 +48,9 @@ static void *diag0c_store(unsigned int *count)
>>  
>>  	get_online_cpus();
>>  	cpu_count = num_online_cpus();
>> -	cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(), GFP_KERNEL);
>> +	cpu_vec = kmalloc_array(num_possible_cpus(),
>> +				sizeof(*cpu_vec),
>> +				GFP_KERNEL);
> 
> How does this improve the situation? For any real life scenario this can't
> overflow, but it does add an extra (pointless) runtime check, since
> num_possible_cpus() is not a compile time constant.
> 
> So, why is this an "issue"?

It's not an issue but I for one still prefer consistent use of
kmalloc_array and kcalloc.

Paolo

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

* Re: [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store()
  2016-09-01 15:39     ` Paolo Bonzini
@ 2016-09-01 16:53       ` Michael Holzheu
  -1 siblings, 0 replies; 8+ messages in thread
From: Michael Holzheu @ 2016-09-01 16:53 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Heiko Carstens, SF Markus Elfring, linux-s390,
	Martin Schwidefsky, LKML, kernel-janitors, Julia Lawall

Am Thu, 1 Sep 2016 17:39:02 +0200
schrieb Paolo Bonzini <pbonzini@redhat.com>:

> 
> 
> On 01/09/2016 12:32, Heiko Carstens wrote:
> > On Thu, Sep 01, 2016 at 11:38:15AM +0200, SF Markus Elfring wrote:
> >> From: Markus Elfring <elfring@users.sourceforge.net>
> >> Date: Thu, 1 Sep 2016 11:30: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 "kmalloc_array".
> >>
> >> This issue was detected by using the Coccinelle software.
> >>
> >> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> >> ---
> >>  arch/s390/hypfs/hypfs_diag0c.c | 4 +++-
> >>  1 file changed, 3 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/arch/s390/hypfs/hypfs_diag0c.c
> >> b/arch/s390/hypfs/hypfs_diag0c.c index 0f1927c..61418a8 100644
> >> --- a/arch/s390/hypfs/hypfs_diag0c.c
> >> +++ b/arch/s390/hypfs/hypfs_diag0c.c
> >> @@ -48,7 +48,9 @@ static void *diag0c_store(unsigned int *count)
> >>  
> >>  	get_online_cpus();
> >>  	cpu_count = num_online_cpus();
> >> -	cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(),
> >> GFP_KERNEL);
> >> +	cpu_vec = kmalloc_array(num_possible_cpus(),
> >> +				sizeof(*cpu_vec),
> >> +				GFP_KERNEL);
> > 
> > How does this improve the situation? For any real life scenario
> > this can't overflow, but it does add an extra (pointless) runtime
> > check, since num_possible_cpus() is not a compile time constant.
> > 
> > So, why is this an "issue"?
> 
> It's not an issue but I for one still prefer consistent use of
> kmalloc_array and kcalloc.

Hello Paolo,

I will keep this in mind for future code, but would prefer not changing
this now.

Michael

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

* Re: [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store()
@ 2016-09-01 16:53       ` Michael Holzheu
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Holzheu @ 2016-09-01 16:53 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Heiko Carstens, SF Markus Elfring, linux-s390,
	Martin Schwidefsky, LKML, kernel-janitors, Julia Lawall

Am Thu, 1 Sep 2016 17:39:02 +0200
schrieb Paolo Bonzini <pbonzini@redhat.com>:

> 
> 
> On 01/09/2016 12:32, Heiko Carstens wrote:
> > On Thu, Sep 01, 2016 at 11:38:15AM +0200, SF Markus Elfring wrote:
> >> From: Markus Elfring <elfring@users.sourceforge.net>
> >> Date: Thu, 1 Sep 2016 11:30: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 "kmalloc_array".
> >>
> >> This issue was detected by using the Coccinelle software.
> >>
> >> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> >> ---
> >>  arch/s390/hypfs/hypfs_diag0c.c | 4 +++-
> >>  1 file changed, 3 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/arch/s390/hypfs/hypfs_diag0c.c
> >> b/arch/s390/hypfs/hypfs_diag0c.c index 0f1927c..61418a8 100644
> >> --- a/arch/s390/hypfs/hypfs_diag0c.c
> >> +++ b/arch/s390/hypfs/hypfs_diag0c.c
> >> @@ -48,7 +48,9 @@ static void *diag0c_store(unsigned int *count)
> >>  
> >>  	get_online_cpus();
> >>  	cpu_count = num_online_cpus();
> >> -	cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(),
> >> GFP_KERNEL);
> >> +	cpu_vec = kmalloc_array(num_possible_cpus(),
> >> +				sizeof(*cpu_vec),
> >> +				GFP_KERNEL);
> > 
> > How does this improve the situation? For any real life scenario
> > this can't overflow, but it does add an extra (pointless) runtime
> > check, since num_possible_cpus() is not a compile time constant.
> > 
> > So, why is this an "issue"?
> 
> It's not an issue but I for one still prefer consistent use of
> kmalloc_array and kcalloc.

Hello Paolo,

I will keep this in mind for future code, but would prefer not changing
this now.

Michael


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

end of thread, other threads:[~2016-09-01 21:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-01  9:38 [PATCH] s390/hypfs: Use kmalloc_array() in diag0c_store() SF Markus Elfring
2016-09-01  9:38 ` SF Markus Elfring
2016-09-01 10:32 ` Heiko Carstens
2016-09-01 10:32   ` Heiko Carstens
2016-09-01 15:39   ` Paolo Bonzini
2016-09-01 15:39     ` Paolo Bonzini
2016-09-01 16:53     ` Michael Holzheu
2016-09-01 16:53       ` Michael Holzheu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.