From a972eca4b64e207b948be4bc00b2b1c864b461c3 Mon Sep 17 00:00:00 2001 From: yangxu Date: Fri, 10 Jan 2025 07:37:18 +0000 Subject: [PATCH] kernel: nvidia-oot: Fix KMD coverity defects Fix coverity defects ARR38-C STR07-C INT30-C INT08-C ARR30-C Jira CAMERASW-30853 Change-Id: I2e98db911238dca46f142f108f6563321e25b588 Signed-off-by: yangxu Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3281801 Reviewed-by: Sudhir Vyas GVS: buildbot_gerritrpt Reviewed-by: svcacv Reviewed-by: Xiaoming Xiang Reviewed-by: Ankur Pawar Reviewed-by: Praveen AC --- drivers/media/platform/tegra/cdi/cdi_mgr.c | 11 ++++++++++- include/trace/events/tegra_rtcpu.h | 8 +++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/tegra/cdi/cdi_mgr.c b/drivers/media/platform/tegra/cdi/cdi_mgr.c index 5f42c403..e4b25fbf 100644 --- a/drivers/media/platform/tegra/cdi/cdi_mgr.c +++ b/drivers/media/platform/tegra/cdi/cdi_mgr.c @@ -660,7 +660,8 @@ static int cdi_mgr_get_pwr_info(struct cdi_mgr_priv *cdi_mgr, goto pwr_info_end; } - if (pinfo.pwr_gpio >= pd->num_pwr_gpios || pinfo.pwr_gpio < 0) { + if (pinfo.pwr_gpio >= pd->num_pwr_gpios || pinfo.pwr_gpio < 0 + || pinfo.pwr_gpio >= MAX_CDI_GPIOS) { dev_err(cdi_mgr->pdev, "%s: invalid power gpio provided\n", __func__); pinfo.pwr_status = -1; @@ -670,6 +671,14 @@ static int cdi_mgr_get_pwr_info(struct cdi_mgr_priv *cdi_mgr, pinfo.pwr_gpio = array_index_nospec(pinfo.pwr_gpio, pd->num_pwr_gpios); + if (pinfo.pwr_gpio < 0 || pinfo.pwr_gpio >= ARRAY_SIZE(pd->pwr_gpios)) { + dev_err(cdi_mgr->pdev, + "%s: set power status failed due to invalid power gpio value\n", __func__); + pinfo.pwr_status = -1; + err = -EINVAL; + goto pwr_info_end; + } + pinfo.pwr_status = gpio_get_value(pd->pwr_gpios[pinfo.pwr_gpio]); err = 0; diff --git a/include/trace/events/tegra_rtcpu.h b/include/trace/events/tegra_rtcpu.h index b1b4cb5d..279575ff 100644 --- a/include/trace/events/tegra_rtcpu.h +++ b/include/trace/events/tegra_rtcpu.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ #undef TRACE_SYSTEM @@ -10,6 +10,7 @@ #define _TRACE_TEGRA_RTCPU_H #include +#include #include /* @@ -119,7 +120,7 @@ TRACE_EVENT(rtcpu_string, __entry->tstamp = tstamp; __entry->id = id; __entry->len = len; - strncpy(__entry->data, data, sizeof(__entry->data)); + strscpy(__entry->data, data, sizeof(__entry->data)); ), TP_printk("tstamp:%llu id:0x%08x str:\"%.*s\"", __entry->tstamp, __entry->id, @@ -282,7 +283,8 @@ TRACE_EVENT(rtcpu_vinotify_event, __entry->tstamp, __entry->channel_id, __entry->unit, - ((__entry->tag_tag >> 1) < g_trace_vinotify_tag_str_count) ? + (((__entry->tag_tag >> 1) < g_trace_vinotify_tag_str_count) && + ((__entry->tag_tag >> 1) >= 0)) ? g_trace_vinotify_tag_strs[__entry->tag_tag >> 1] : __print_hex(&__entry->tag_tag, 1), __entry->tag_channel, __entry->tag_frame,