diff mbox series

platform: uv: fix missing checks for kcalloc

Message ID 20190324225755.1702-1-kjlu@umn.edu (mailing list archive)
State Superseded, archived
Delegated to: Andy Shevchenko
Headers show
Series platform: uv: fix missing checks for kcalloc | expand

Commit Message

Kangjie Lu March 24, 2019, 10:57 p.m. UTC
In case kcalloc fails, the patch return an error to avoid
potential NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 arch/x86/platform/uv/tlb_uv.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Borislav Petkov March 25, 2019, 12:55 p.m. UTC | #1
On Sun, Mar 24, 2019 at 05:57:53PM -0500, Kangjie Lu wrote:
> In case kcalloc fails, the patch return an error to avoid
> potential NULL pointer dereference.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>  arch/x86/platform/uv/tlb_uv.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
> index 2c53b0f19329..1ac777f14846 100644
> --- a/arch/x86/platform/uv/tlb_uv.c
> +++ b/arch/x86/platform/uv/tlb_uv.c
> @@ -2140,7 +2140,13 @@ static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
>  		timeout_us = calculate_destination_timeout();
>  
>  	uvhub_descs = kcalloc(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL);
> +	if (!uvhub_descs)
> +		return 1;

Here...

>  	uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
> +	if (!uvhub_mask) {
> +		kfree(uvhub_descs);
> +		return 1;
> +	}

... and here you can simply do

		goto fail;

instead. After having initialized uvhub_descs and uvhub_mask to NULL;

Thx.
diff mbox series

Patch

diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
index 2c53b0f19329..1ac777f14846 100644
--- a/arch/x86/platform/uv/tlb_uv.c
+++ b/arch/x86/platform/uv/tlb_uv.c
@@ -2140,7 +2140,13 @@  static int __init init_per_cpu(int nuvhubs, int base_part_pnode)
 		timeout_us = calculate_destination_timeout();
 
 	uvhub_descs = kcalloc(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL);
+	if (!uvhub_descs)
+		return 1;
 	uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
+	if (!uvhub_mask) {
+		kfree(uvhub_descs);
+		return 1;
+	}
 
 	if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask))
 		goto fail;