tty: wch: Fix C-CERT coverity issues

C-CERT coverity issues fix for wch tty serial driver

CID:679040
CID:678956
CID:678957
CID:679059
CID:678985
CID:679029
CID:679037
CID:679049

Bug 3959323

Change-Id: If34f5490b80d19162df60235fc74f0427a0caf07
Signed-off-by: Ankit patel <anpatel@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2992040
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
Reviewed-by: Bibek Basu <bbasu@nvidia.com>
This commit is contained in:
Ankit patel
2023-10-05 20:55:15 +05:30
committed by mobile promotions
parent 3013b107c1
commit af229f6fbf
3 changed files with 57 additions and 54 deletions

View File

@@ -1,16 +1,16 @@
/*
* Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#ifndef WCH_COMMON
#define WCH_COMMON
@@ -221,7 +221,7 @@ enum {
#define PORTFLAG_CH384_28_PORTS 0x0020
// board info
#define WCH_BOARDS_MAX 0x08
#define WCH_BOARDS_MAX 0x04
#define WCH_PORT_ONBOARD_MAX 0x20
#define WCH_SER_TOTAL_MAX 0x100

View File

@@ -1,3 +1,15 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
/*
* PCI/PCIE to serial driver for ch351/352/353/355/356/357/358/359/382/384, etc.
*
@@ -31,20 +43,6 @@
* V1.24 - fixed ch351/2/3 uart0 setting bug, merged pre-load driver
*/
/*
* Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. 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,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
#include "wch_common.h"
extern struct wch_board wch_board_table[WCH_BOARDS_MAX];
@@ -112,6 +110,9 @@ static irqreturn_t wch_interrupt(int irq, void *dev_id)
int status = 0;
int handled = IRQ_NONE;
if (!dev_id)
return handled;
for (i = 0; i < WCH_BOARDS_MAX; i++) {
if (dev_id == &(wch_board_table[i])) {
sb = dev_id;
@@ -159,7 +160,7 @@ static int wch_pci_board_probe(void)
struct pci_dev *pdev = NULL;
struct pci_dev *pdev_array[4] = {NULL, NULL, NULL, NULL};
int wch_pci_board_id_cnt;
size_t wch_pci_board_id_cnt;
int table_cnt;
int board_cnt;
int i;
@@ -248,7 +249,7 @@ static int wch_pci_board_probe(void)
sb->bus_number = pdev->bus->number;
sb->dev_number = PCI_SLOT(pdev->devfn);
sb->board_enum = (int)wch_pci_board_id[table_cnt].driver_data;
sb->board_enum = (unsigned int)wch_pci_board_id[table_cnt].driver_data;
sb->pb_info = wch_pci_board_conf[sb->board_enum];
sb->board_flag = sb->pb_info.board_flag;
@@ -367,7 +368,7 @@ static int wch_assign_resource(void)
return status;
}
for (j = 0; j < sb->ser_ports; j++, ser_n++, sp++) {
for (j = 0; j < sb->ser_ports && j < WCH_PORT_ONBOARD_MAX ; j++, ser_n++, sp++) {
sp->port.chip_flag = sb->pb_info.port[j].chip_flag;
sp->port.iobase = sb->bar_addr[sb->pb_info.port[j].bar1] + sb->pb_info.port[j].offset1;

View File

@@ -1,14 +1,13 @@
/*
* Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include <nvidia/conftest.h>
@@ -545,7 +544,7 @@ static int ser_startup(struct ser_state *state, int init_hw)
retval = wch_ser_startup(port);
if (retval == 0) {
if (init_hw) {
if (init_hw && info->tty) {
ser_change_speed(state, NULL);
if (info->tty->termios.c_cflag & CBAUD)
{
@@ -555,6 +554,7 @@ static int ser_startup(struct ser_state *state, int init_hw)
info->flags |= WCH_UIF_INITIALIZED;
if (info->tty)
clear_bit(TTY_IO_ERROR, &info->tty->flags);
}
@@ -1106,26 +1106,28 @@ static int ser_wait_modem_status(struct ser_state *state, unsigned long arg)
static int ser_get_count(struct ser_state *state, struct serial_icounter_struct *icnt)
{
struct serial_icounter_struct icount;
struct serial_icounter_struct *icount;
struct ser_icount cnow;
struct ser_port *port = state->port;
spin_lock_irq(&port->lock);
memcpy(&cnow, &port->icount, sizeof(struct ser_icount));
spin_unlock_irq(&port->lock);
icount.cts = cnow.cts;
icount.dsr = cnow.dsr;
icount.rng = cnow.rng;
icount.dcd = cnow.dcd;
icount.rx = cnow.rx;
icount.tx = cnow.tx;
icount.frame = cnow.frame;
icount.overrun = cnow.overrun;
icount.parity = cnow.parity;
icount.brk = cnow.brk;
icount.buf_overrun = cnow.buf_overrun;
icount = kzalloc(sizeof(*icount), GFP_KERNEL);
return copy_to_user(icnt, &icount, sizeof(icount)) ? -EFAULT : 0;
icount->cts = cnow.cts;
icount->dsr = cnow.dsr;
icount->rng = cnow.rng;
icount->dcd = cnow.dcd;
icount->rx = cnow.rx;
icount->tx = cnow.tx;
icount->frame = cnow.frame;
icount->overrun = cnow.overrun;
icount->parity = cnow.parity;
icount->brk = cnow.brk;
icount->buf_overrun = cnow.buf_overrun;
return copy_to_user(icnt, icount, sizeof(*icount)) ? -EFAULT : 0;
}
static void ser_config_rs485(struct ser_state *state, struct serial_rs485 *rs485)