From 9b526e03db947b00962bc1acb6adf96b21b3ce75 Mon Sep 17 00:00:00 2001 From: Sharad Gupta Date: Wed, 9 Mar 2022 23:13:51 +0530 Subject: [PATCH] nvadsp: CERT-C Fixes Fixed for L1 issues : Return value check for snprintf NULL pointer check using IS_ERR_OR_NULL Bug 3512545 CID 407176 CID 429671 CID 471352 Signed-off-by: Sharad Gupta Change-Id: Ib03339db8dc669b6eff448941fac62b2feabf7bc Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2679048 Reviewed-by: svcacv Reviewed-by: Akash Kollipara Reviewed-by: Sachin Nikam Reviewed-by: Viswanath L Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: svc_kernel_abi GVS: Gerrit_Virtual_Submit --- drivers/platform/tegra/nvadsp/app.c | 9 +++++++-- drivers/platform/tegra/nvadsp/app_loader_linker.c | 2 +- drivers/platform/tegra/nvadsp/os.c | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/platform/tegra/nvadsp/app.c b/drivers/platform/tegra/nvadsp/app.c index 12634b76..38dac101 100644 --- a/drivers/platform/tegra/nvadsp/app.c +++ b/drivers/platform/tegra/nvadsp/app.c @@ -3,7 +3,7 @@ * * ADSP OS App management * - * Copyright (C) 2014-2021, NVIDIA Corporation. All rights reserved. + * Copyright (C) 2014-2022, NVIDIA Corporation. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -425,8 +425,13 @@ static int create_instance_memory(nvadsp_app_info_t *app, char name[NVADSP_NAME_SZ]; void *aram_handle; dma_addr_t da; + int ret; - snprintf(name, NVADSP_NAME_SZ, "%s:%d", app->name, app->instance_id); + ret = snprintf(name, NVADSP_NAME_SZ, "%s:%d", app->name, app->instance_id); + if (ret < 0 || ret >= NVADSP_NAME_SZ) { + dev_err(dev, "Invalid App name %s\n", app->name); + return -EINVAL; + } if (sz->dram) { mem->dram = nvadsp_alloc_coherent(sz->dram, &da, GFP_KERNEL); diff --git a/drivers/platform/tegra/nvadsp/app_loader_linker.c b/drivers/platform/tegra/nvadsp/app_loader_linker.c index 083a0d4a..cfd8d193 100644 --- a/drivers/platform/tegra/nvadsp/app_loader_linker.c +++ b/drivers/platform/tegra/nvadsp/app_loader_linker.c @@ -893,7 +893,7 @@ struct adsp_module *load_adsp_dynamic_module(const char *appname, /* Figure out module layout, and allocate all the memory. */ mod = layout_and_allocate(&info); - if (IS_ERR(mod)) + if (IS_ERR_OR_NULL(mod)) goto error_free_memory; /* update adsp specific sections */ diff --git a/drivers/platform/tegra/nvadsp/os.c b/drivers/platform/tegra/nvadsp/os.c index 7a472532..7bb55ee4 100644 --- a/drivers/platform/tegra/nvadsp/os.c +++ b/drivers/platform/tegra/nvadsp/os.c @@ -332,7 +332,7 @@ bool is_adsp_dram_addr(u64 addr) int nvadsp_add_load_mappings(phys_addr_t pa, void *mapping, int len) { - if (map_idx >= NM_LOAD_MAPPINGS) + if (map_idx < 0 || map_idx >= NM_LOAD_MAPPINGS) return -EINVAL; adsp_map[map_idx].da = pa; @@ -884,7 +884,7 @@ static int nvadsp_firmware_load(struct platform_device *pdev) } shared_mem = get_mailbox_shared_region(fw); - if (IS_ERR(shared_mem)) { + if (IS_ERR_OR_NULL(shared_mem)) { if (drv_data->chip_data->adsp_shared_mem_hwmbox != 0) { /* * If FW is not explicitly defining a shared memory