diff --git a/drivers/tty/serial/wch_35x/wch_common.h b/drivers/tty/serial/wch_35x/wch_common.h index 9c1fc103..62a182c6 100644 --- a/drivers/tty/serial/wch_35x/wch_common.h +++ b/drivers/tty/serial/wch_35x/wch_common.h @@ -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 diff --git a/drivers/tty/serial/wch_35x/wch_main.c b/drivers/tty/serial/wch_35x/wch_main.c index 294311a7..8832709e 100644 --- a/drivers/tty/serial/wch_35x/wch_main.c +++ b/drivers/tty/serial/wch_35x/wch_main.c @@ -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; @@ -234,7 +235,7 @@ static int wch_pci_board_probe(void) } board_cnt++; - if (board_cnt > WCH_BOARDS_MAX) { + if (board_cnt > WCH_BOARDS_MAX) { printk("\n"); printk("WCH Error: WCH Driver Module Support Four Boards In Maximum !\n\n"); status = -ENOSPC; @@ -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,9 +368,9 @@ static int wch_assign_resource(void) return status; } - for (j = 0; j < sb->ser_ports; 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; + 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; /* use scr reg to test io space */ outb(0x55, sp->port.iobase + UART_SCR); diff --git a/drivers/tty/serial/wch_35x/wch_serial.c b/drivers/tty/serial/wch_35x/wch_serial.c index 1f824b5d..67d4e23b 100644 --- a/drivers/tty/serial/wch_35x/wch_serial.c +++ b/drivers/tty/serial/wch_35x/wch_serial.c @@ -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 @@ -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,7 +554,8 @@ static int ser_startup(struct ser_state *state, int init_hw) info->flags |= WCH_UIF_INITIALIZED; - clear_bit(TTY_IO_ERROR, &info->tty->flags); + if (info->tty) + clear_bit(TTY_IO_ERROR, &info->tty->flags); } if (retval && capable(CAP_SYS_ADMIN)) { @@ -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)