All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/platform/UV: Replace kmalloc and memset with kzalloc and kcalloc
@ 2019-01-15 17:37 Gustavo A. R. Silva
  2019-01-16 12:06 ` Borislav Petkov
  2019-01-16 12:09 ` [tip:x86/cleanups] x86/platform/UV: Replace kmalloc() and memset() with k[cz]alloc() calls tip-bot for Gustavo A. R. Silva
  0 siblings, 2 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2019-01-15 17:37 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin, x86
  Cc: linux-kernel, Gustavo A. R. Silva

Replace kmalloc_node and memset with kzalloc_node, and
kmalloc_array and memset with kcalloc.

Also, remove unnecessary pointer to void vp.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 arch/x86/platform/uv/tlb_uv.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
index a4130b84d1ff..ed7e3a21344b 100644
--- a/arch/x86/platform/uv/tlb_uv.c
+++ b/arch/x86/platform/uv/tlb_uv.c
@@ -2010,8 +2010,7 @@ static void make_per_cpu_thp(struct bau_control *smaster)
 	int cpu;
 	size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
 
-	smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
-	memset(smaster->thp, 0, hpsz);
+	smaster->thp = kzalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
 	for_each_present_cpu(cpu) {
 		smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
 		smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
@@ -2135,15 +2134,12 @@ static int __init summarize_uvhub_sockets(int nuvhubs,
 static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
 {
 	unsigned char *uvhub_mask;
-	void *vp;
 	struct uvhub_desc *uvhub_descs;
 
 	if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub())
 		timeout_us = calculate_destination_timeout();
 
-	vp = kmalloc_array(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL);
-	uvhub_descs = (struct uvhub_desc *)vp;
-	memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
+	uvhub_descs = kcalloc(nuvhubs, sizeof(*uvhub_descs), GFP_KERNEL);
 	uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
 
 	if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask))
-- 
2.20.1


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

* Re: [PATCH] x86/platform/UV: Replace kmalloc and memset with kzalloc and kcalloc
  2019-01-15 17:37 [PATCH] x86/platform/UV: Replace kmalloc and memset with kzalloc and kcalloc Gustavo A. R. Silva
@ 2019-01-16 12:06 ` Borislav Petkov
  2019-01-22 23:08   ` Gustavo A. R. Silva
  2019-01-16 12:09 ` [tip:x86/cleanups] x86/platform/UV: Replace kmalloc() and memset() with k[cz]alloc() calls tip-bot for Gustavo A. R. Silva
  1 sibling, 1 reply; 4+ messages in thread
From: Borislav Petkov @ 2019-01-16 12:06 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, linux-kernel

On Tue, Jan 15, 2019 at 11:37:13AM -0600, Gustavo A. R. Silva wrote:
> Replace kmalloc_node and memset with kzalloc_node, and
> kmalloc_array and memset with kcalloc.
> 
> Also, remove unnecessary pointer to void vp.
> 
> This code was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  arch/x86/platform/uv/tlb_uv.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
> index a4130b84d1ff..ed7e3a21344b 100644
> --- a/arch/x86/platform/uv/tlb_uv.c
> +++ b/arch/x86/platform/uv/tlb_uv.c
> @@ -2010,8 +2010,7 @@ static void make_per_cpu_thp(struct bau_control *smaster)
>  	int cpu;
>  	size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
>  
> -	smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
> -	memset(smaster->thp, 0, hpsz);
> +	smaster->thp = kzalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
>  	for_each_present_cpu(cpu) {
>  		smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
>  		smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
> @@ -2135,15 +2134,12 @@ static int __init summarize_uvhub_sockets(int nuvhubs,
>  static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
>  {
>  	unsigned char *uvhub_mask;
> -	void *vp;
>  	struct uvhub_desc *uvhub_descs;
>  
>  	if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub())
>  		timeout_us = calculate_destination_timeout();
>  
> -	vp = kmalloc_array(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL);
> -	uvhub_descs = (struct uvhub_desc *)vp;
> -	memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
> +	uvhub_descs = kcalloc(nuvhubs, sizeof(*uvhub_descs), GFP_KERNEL);
				       ^^^^^^^^^^^^^^^^^^^^

I'm changing that back to sizeof(struct uvhub_desc) as it is clearer
this way.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

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

* [tip:x86/cleanups] x86/platform/UV: Replace kmalloc() and memset() with k[cz]alloc() calls
  2019-01-15 17:37 [PATCH] x86/platform/UV: Replace kmalloc and memset with kzalloc and kcalloc Gustavo A. R. Silva
  2019-01-16 12:06 ` Borislav Petkov
@ 2019-01-16 12:09 ` tip-bot for Gustavo A. R. Silva
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Gustavo A. R. Silva @ 2019-01-16 12:09 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: nstange, mingo, gustavo, mingo, peterz, colin.king, rvarsha016,
	luto, x86, linux-kernel, tglx, bp, keescook, hpa, abanman

Commit-ID:  2bc217c61685487987c5befd807e10936371643c
Gitweb:     https://git.kernel.org/tip/2bc217c61685487987c5befd807e10936371643c
Author:     Gustavo A. R. Silva <gustavo@embeddedor.com>
AuthorDate: Tue, 15 Jan 2019 11:37:13 -0600
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Wed, 16 Jan 2019 13:01:26 +0100

x86/platform/UV: Replace kmalloc() and memset() with k[cz]alloc() calls

Replace kmalloc_node() and memset() with kzalloc_node(), and
kmalloc_array() and memset() with kcalloc().

This code was detected with the help of Coccinelle.

No functional changes.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Cc: Andrew Banman <abanman@hpe.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Colin Ian King <colin.king@canonical.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Nicolai Stange <nstange@suse.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Varsha Rao <rvarsha016@gmail.com>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190115173713.GA31031@embeddedor
---
 arch/x86/platform/uv/tlb_uv.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
index a4130b84d1ff..2c53b0f19329 100644
--- a/arch/x86/platform/uv/tlb_uv.c
+++ b/arch/x86/platform/uv/tlb_uv.c
@@ -2010,8 +2010,7 @@ static void make_per_cpu_thp(struct bau_control *smaster)
 	int cpu;
 	size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
 
-	smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
-	memset(smaster->thp, 0, hpsz);
+	smaster->thp = kzalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
 	for_each_present_cpu(cpu) {
 		smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
 		smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
@@ -2135,15 +2134,12 @@ static int __init summarize_uvhub_sockets(int nuvhubs,
 static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
 {
 	unsigned char *uvhub_mask;
-	void *vp;
 	struct uvhub_desc *uvhub_descs;
 
 	if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub())
 		timeout_us = calculate_destination_timeout();
 
-	vp = kmalloc_array(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL);
-	uvhub_descs = (struct uvhub_desc *)vp;
-	memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
+	uvhub_descs = kcalloc(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL);
 	uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
 
 	if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask))

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

* Re: [PATCH] x86/platform/UV: Replace kmalloc and memset with kzalloc and kcalloc
  2019-01-16 12:06 ` Borislav Petkov
@ 2019-01-22 23:08   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2019-01-22 23:08 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, linux-kernel



On 1/16/19 6:06 AM, Borislav Petkov wrote:

>> -	vp = kmalloc_array(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL);
>> -	uvhub_descs = (struct uvhub_desc *)vp;
>> -	memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
>> +	uvhub_descs = kcalloc(nuvhubs, sizeof(*uvhub_descs), GFP_KERNEL);
> 				       ^^^^^^^^^^^^^^^^^^^^
> 
> I'm changing that back to sizeof(struct uvhub_desc) as it is clearer
> this way.
> 

Okay.

Thanks, Boris.

--
Gustavo

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

end of thread, other threads:[~2019-01-22 23:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-15 17:37 [PATCH] x86/platform/UV: Replace kmalloc and memset with kzalloc and kcalloc Gustavo A. R. Silva
2019-01-16 12:06 ` Borislav Petkov
2019-01-22 23:08   ` Gustavo A. R. Silva
2019-01-16 12:09 ` [tip:x86/cleanups] x86/platform/UV: Replace kmalloc() and memset() with k[cz]alloc() calls tip-bot for Gustavo A. R. Silva

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.