From aaecfae53f60715e52a9e29a956d0246f4f0bafa Mon Sep 17 00:00:00 2001 From: Nitin Kumbhar Date: Fri, 15 Feb 2019 15:16:17 +0530 Subject: gpu: nvgpu: add checks for kzalloc() allocations Check kzalloc() allocations for failures and return an error if an allocation fails. Bug 2279948 Change-Id: I8a2c3b84904da897ad6118900c11489c8656c20f Signed-off-by: Nitin Kumbhar Reviewed-on: https://git-master.nvidia.com/r/2020123 (cherry picked from commit fadd0014da39cb9498472494e52590db4b0bd7b9) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2298066 Tested-by: mobile promotions Reviewed-by: mobile promotions --- drivers/gpu/nvgpu/clk/clk_prog.c | 4 +++- drivers/gpu/nvgpu/gk20a/gr_gk20a.c | 2 ++ drivers/gpu/nvgpu/os/linux/scale.c | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'drivers/gpu') diff --git a/drivers/gpu/nvgpu/clk/clk_prog.c b/drivers/gpu/nvgpu/clk/clk_prog.c index e5c2a295..9d44d6d4 100644 --- a/drivers/gpu/nvgpu/clk/clk_prog.c +++ b/drivers/gpu/nvgpu/clk/clk_prog.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2020, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -628,6 +628,8 @@ static int clk_prog_construct_1x_master(struct gk20a *g, pclkprog->p_vf_entries = (struct ctrl_clk_clk_prog_1x_master_vf_entry *) nvgpu_kzalloc(g, vfsize); + if (!pclkprog->p_vf_entries) + return -ENOMEM; memcpy(pclkprog->p_vf_entries, ptmpprog->p_vf_entries, vfsize); diff --git a/drivers/gpu/nvgpu/gk20a/gr_gk20a.c b/drivers/gpu/nvgpu/gk20a/gr_gk20a.c index 4f897b97..d24b8bf7 100644 --- a/drivers/gpu/nvgpu/gk20a/gr_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/gr_gk20a.c @@ -3473,6 +3473,8 @@ static int gr_gk20a_init_gr_config(struct gk20a *g, struct gr_gk20a *gr) gr->sm_to_cluster = nvgpu_kzalloc(g, gr->gpc_count * gr->max_tpc_per_gpc_count * sm_per_tpc * sizeof(struct sm_info)); + if (!gr->sm_to_cluster) + goto clean_up; } else { memset(gr->sm_to_cluster, 0, gr->gpc_count * gr->max_tpc_per_gpc_count * diff --git a/drivers/gpu/nvgpu/os/linux/scale.c b/drivers/gpu/nvgpu/os/linux/scale.c index ef7996e6..388e168d 100644 --- a/drivers/gpu/nvgpu/os/linux/scale.c +++ b/drivers/gpu/nvgpu/os/linux/scale.c @@ -1,7 +1,7 @@ /* * gk20a clock scaling profile * - * Copyright (c) 2013-2018, NVIDIA Corporation. All rights reserved. + * Copyright (c) 2013-2020, NVIDIA Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -339,6 +339,8 @@ void gk20a_scale_init(struct device *dev) return; profile = nvgpu_kzalloc(g, sizeof(*profile)); + if (!profile) + return; profile->dev = dev; profile->dev_stat.busy = false; -- cgit v1.2.2