From 4636d2781ea7ba39d7fe377fa31c791f74bb155f Mon Sep 17 00:00:00 2001 From: Manish Bhardwaj Date: Wed, 2 Mar 2022 08:12:04 +0000 Subject: [PATCH] kernel: nvidia: fix cert warnings Using this patch we are fixing below cert warnings :- 1. cert_err33_c_violation: The error status of function call snprintf(name, 20UL, "ivc-queue%d", i) is not checked. 2. cert_err33_c_violation: The error status of function call snprintf(name, 30UL, "gr-virt-comm-%d", i) is not checked. 3. cert_err33_c_violation: The error status of function call snprintf(name, 20UL, "mempool%d", i) is not checked. Below changes has been done to fix above cert warnings:- 1. check the return value to snprintf function and handle return error gracefully. Bug 3512545 Signed-off-by: Manish Bhardwaj Change-Id: Ia41ab89e3759387b36489dca5f57652f7389f328 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2676650 Tested-by: mobile promotions Reviewed-by: mobile promotions --- drivers/video/tegra/virt/tegra_gr_comm.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/video/tegra/virt/tegra_gr_comm.c b/drivers/video/tegra/virt/tegra_gr_comm.c index 95435c56..9e931dac 100644 --- a/drivers/video/tegra/virt/tegra_gr_comm.c +++ b/drivers/video/tegra/virt/tegra_gr_comm.c @@ -1,7 +1,7 @@ /* * Tegra Graphics Virtualization Communication Framework * - * Copyright (c) 2013-2021, NVIDIA Corporation. All rights reserved. + * Copyright (c) 2013-2022, 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, @@ -219,7 +219,11 @@ static int setup_mempool(struct platform_device *pdev, char name[20]; u32 inst; - snprintf(name, sizeof(name), "mempool%d", i); + if (snprintf(name, sizeof(name), "mempool%d", i) < 0) { + ret = -ENOMEM; + goto fail; + } + if (of_property_read_u32_index(dev->of_node, name, PROP_MEMPOOL_INST, &inst) == 0) { struct gr_comm_mempool_context *ctx; @@ -268,7 +272,11 @@ static int setup_ivc(struct platform_device *pdev, char name[20]; u32 inst; - snprintf(name, sizeof(name), "ivc-queue%d", i); + if (snprintf(name, sizeof(name), "ivc-queue%d", i) < 0) { + ret = -ENOMEM; + goto fail; + } + if (of_property_read_u32_index(dev->of_node, name, PROP_IVC_INST, &inst) == 0) { struct device_node *hv_dn; @@ -359,7 +367,11 @@ int tegra_gr_comm_init(struct platform_device *pdev, u32 elems, if (queue->valid) return -EEXIST; - snprintf(name, sizeof(name), "gr-virt-comm-%d", i); + if (snprintf(name, sizeof(name), "gr-virt-comm-%d", i) < 0) { + ret = -ENOMEM; + goto fail; + } + queue->element_cache = kmem_cache_create(name, sizeof(struct gr_comm_element) + size, 0,