From ad01764abb00abc291bc06aa33ce08e2122e88bb Mon Sep 17 00:00:00 2001 From: Bhadram Varka Date: Tue, 8 Feb 2022 18:16:06 +0530 Subject: [PATCH] nvethernet: fix coverity defects CID 9871576 Untrusted array index read CID 10112340 Dereference before null check CID 10127838 Unchecked return value CID 10127841 Dead default in switch CID 10127905 Unchecked return value CID 10127961 Unused value Bug 3461002 Change-Id: If041434e57295b282dacf06ed66b1a436b96a165 Signed-off-by: Bhadram Varka Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2665776 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: svcacv Reviewed-by: svc_kernel_abi Reviewed-by: Mohan Thadikamalla Reviewed-by: Rakesh Goyal Reviewed-by: Sachin Nikam GVS: Gerrit_Virtual_Submit --- drivers/net/ethernet/nvidia/nvethernet/ether_linux.c | 4 ++-- drivers/net/ethernet/nvidia/nvethernet/ethtool.c | 8 ++++---- drivers/net/ethernet/nvidia/nvethernet/ioctl.c | 7 ++++++- drivers/net/ethernet/nvidia/nvethernet/osd.c | 9 +++++++-- drivers/net/ethernet/nvidia/nvethernet/selftests.c | 9 +++++++-- drivers/net/ethernet/nvidia/nvethernet/sysfs.c | 5 ++--- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c b/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c index 1725acbc..df37a0fe 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c +++ b/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c @@ -4996,15 +4996,15 @@ static int ether_get_eqos_clks(struct ether_priv_data *pdata) goto err_tx; } + /* This is optional clk */ pdata->rx_m_clk = devm_clk_get(dev, "eqos_rx_m"); if (IS_ERR(pdata->rx_m_clk)) { - ret = PTR_ERR(pdata->rx_m_clk); dev_info(dev, "failed to get eqos_rx_m clk\n"); } + /* This is optional clk */ pdata->rx_input_clk = devm_clk_get(dev, "eqos_rx_input"); if (IS_ERR(pdata->rx_input_clk)) { - ret = PTR_ERR(pdata->rx_input_clk); dev_info(dev, "failed to get eqos_rx_input clk\n"); } diff --git a/drivers/net/ethernet/nvidia/nvethernet/ethtool.c b/drivers/net/ethernet/nvidia/nvethernet/ethtool.c index 17be5f9f..60991756 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/ethtool.c +++ b/drivers/net/ethernet/nvidia/nvethernet/ethtool.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-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, @@ -1396,9 +1396,6 @@ static void ether_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) { struct ether_priv_data *pdata = netdev_priv(ndev); - wol->supported = 0; - wol->wolopts = 0; - if (!wol) return; @@ -1409,6 +1406,9 @@ static void ether_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) return; } + wol->supported = 0; + wol->wolopts = 0; + if (!phy_interrupt_is_valid(pdata->phydev)) return; diff --git a/drivers/net/ethernet/nvidia/nvethernet/ioctl.c b/drivers/net/ethernet/nvidia/nvethernet/ioctl.c index dfd1c9bd..9684413d 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/ioctl.c +++ b/drivers/net/ethernet/nvidia/nvethernet/ioctl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2019-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, @@ -141,6 +141,11 @@ static int ether_set_avb_algo(struct net_device *ndev, return ret; } + if (ioctl_data.avb.qindex >= OSI_MGBE_MAX_NUM_QUEUES) { + dev_err(pdata->dev, "Invalid queue index from user\n"); + return -EINVAL; + } + /* Check AVB mode disable on slot function enable */ tx_ring = osi_dma->tx_ring[ioctl_data.avb.qindex]; if (tx_ring && tx_ring->slot_check == OSI_ENABLE && diff --git a/drivers/net/ethernet/nvidia/nvethernet/osd.c b/drivers/net/ethernet/nvidia/nvethernet/osd.c index de3f4b32..e328d015 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/osd.c +++ b/drivers/net/ethernet/nvidia/nvethernet/osd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-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, @@ -922,7 +922,12 @@ int osd_ivc_send_cmd(void *priv, ivc_msg_common_t *ivc_buf, unsigned int len) dcnt = IVC_READ_TIMEOUT_CNT; while ((!tegra_hv_ivc_can_read(ictxt->ivck))) { - wait_for_completion_timeout(&ictxt->msg_complete, IVC_WAIT_TIMEOUT); + if (!wait_for_completion_timeout(&ictxt->msg_complete, + IVC_WAIT_TIMEOUT)) { + ret = -ETIMEDOUT; + goto fail; + } + dcnt--; if (!dcnt) { dev_err(pdata->dev, "IVC read timeout\n"); diff --git a/drivers/net/ethernet/nvidia/nvethernet/selftests.c b/drivers/net/ethernet/nvidia/nvethernet/selftests.c index 1844566b..d9d88ab8 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/selftests.c +++ b/drivers/net/ethernet/nvidia/nvethernet/selftests.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2021-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, @@ -249,7 +249,12 @@ static int ether_test_loopback(struct ether_priv_data *pdata, if (ret) goto cleanup; - wait_for_completion_timeout(&tpdata->comp, msecs_to_jiffies(200)); + if (!wait_for_completion_timeout(&tpdata->comp, + msecs_to_jiffies(200))) { + ret = -ETIMEDOUT; + goto cleanup; + } + ret = !tpdata->completed; cleanup: dev_remove_pack(&tpdata->pt); diff --git a/drivers/net/ethernet/nvidia/nvethernet/sysfs.c b/drivers/net/ethernet/nvidia/nvethernet/sysfs.c index 5c9c563b..9f014f13 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/sysfs.c +++ b/drivers/net/ethernet/nvidia/nvethernet/sysfs.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2019-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, @@ -684,11 +684,10 @@ static int parse_inputs(const char *buf, case 2: flags |= OSI_LUT_FLAGS_BYTE2_PATTERN_VALID; break; + default: case 3: flags |= OSI_LUT_FLAGS_BYTE3_PATTERN_VALID; break; - default: - break; } lut_in->byte_pattern[i] = byte[i]; lut_in->byte_pattern_offset[i] = byte_offset[i];