Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

serial: 8250: invert serial8250_register_8250_port() CIR condition

There is no point in a long 'if' in serial8250_register_8250_port() to
just return ENOSPC for PORT_8250_CIR ports. Invert the condition and
return immediately.

'gpios' variable was moved to its set location.

And return ENODEV instead of ENOSPC. The latter is a leftover from the
previous find-uart 'if'. The former makes a lot more sense in this case.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20250611100319.186924-31-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
05b537a1 15c9dc73

+127 -126
+127 -126
drivers/tty/serial/8250/8250_core.c
··· 725 725 nr_uarts++; 726 726 } 727 727 728 + if (uart->port.type == PORT_8250_CIR) { 729 + ret = -ENODEV; 730 + goto unlock; 731 + } 732 + 733 + if (uart->port.dev) 734 + uart_remove_one_port(&serial8250_reg, &uart->port); 735 + 736 + uart->port.ctrl_id = up->port.ctrl_id; 737 + uart->port.port_id = up->port.port_id; 738 + uart->port.iobase = up->port.iobase; 739 + uart->port.membase = up->port.membase; 740 + uart->port.irq = up->port.irq; 741 + uart->port.irqflags = up->port.irqflags; 742 + uart->port.uartclk = up->port.uartclk; 743 + uart->port.fifosize = up->port.fifosize; 744 + uart->port.regshift = up->port.regshift; 745 + uart->port.iotype = up->port.iotype; 746 + uart->port.flags = up->port.flags | UPF_BOOT_AUTOCONF; 747 + uart->bugs = up->bugs; 748 + uart->port.mapbase = up->port.mapbase; 749 + uart->port.mapsize = up->port.mapsize; 750 + uart->port.private_data = up->port.private_data; 751 + uart->tx_loadsz = up->tx_loadsz; 752 + uart->capabilities = up->capabilities; 753 + uart->port.throttle = up->port.throttle; 754 + uart->port.unthrottle = up->port.unthrottle; 755 + uart->port.rs485_config = up->port.rs485_config; 756 + uart->port.rs485_supported = up->port.rs485_supported; 757 + uart->port.rs485 = up->port.rs485; 758 + uart->rs485_start_tx = up->rs485_start_tx; 759 + uart->rs485_stop_tx = up->rs485_stop_tx; 760 + uart->lsr_save_mask = up->lsr_save_mask; 761 + uart->dma = up->dma; 762 + 763 + /* Take tx_loadsz from fifosize if it wasn't set separately */ 764 + if (uart->port.fifosize && !uart->tx_loadsz) 765 + uart->tx_loadsz = uart->port.fifosize; 766 + 767 + if (up->port.dev) { 768 + uart->port.dev = up->port.dev; 769 + ret = uart_get_rs485_mode(&uart->port); 770 + if (ret) 771 + goto err; 772 + } 773 + 774 + if (up->port.flags & UPF_FIXED_TYPE) 775 + uart->port.type = up->port.type; 776 + 777 + /* 778 + * Only call mctrl_gpio_init(), if the device has no ACPI 779 + * companion device 780 + */ 781 + if (!has_acpi_companion(uart->port.dev)) { 782 + struct mctrl_gpios *gpios = mctrl_gpio_init(&uart->port, 0); 783 + if (IS_ERR(gpios)) { 784 + ret = PTR_ERR(gpios); 785 + goto err; 786 + } else { 787 + uart->gpios = gpios; 788 + } 789 + } 790 + 791 + serial8250_set_defaults(uart); 792 + 793 + /* Possibly override default I/O functions. */ 794 + if (up->port.serial_in) 795 + uart->port.serial_in = up->port.serial_in; 796 + if (up->port.serial_out) 797 + uart->port.serial_out = up->port.serial_out; 798 + if (up->port.handle_irq) 799 + uart->port.handle_irq = up->port.handle_irq; 800 + /* Possibly override set_termios call */ 801 + if (up->port.set_termios) 802 + uart->port.set_termios = up->port.set_termios; 803 + if (up->port.set_ldisc) 804 + uart->port.set_ldisc = up->port.set_ldisc; 805 + if (up->port.get_mctrl) 806 + uart->port.get_mctrl = up->port.get_mctrl; 807 + if (up->port.set_mctrl) 808 + uart->port.set_mctrl = up->port.set_mctrl; 809 + if (up->port.get_divisor) 810 + uart->port.get_divisor = up->port.get_divisor; 811 + if (up->port.set_divisor) 812 + uart->port.set_divisor = up->port.set_divisor; 813 + if (up->port.startup) 814 + uart->port.startup = up->port.startup; 815 + if (up->port.shutdown) 816 + uart->port.shutdown = up->port.shutdown; 817 + if (up->port.pm) 818 + uart->port.pm = up->port.pm; 819 + if (up->port.handle_break) 820 + uart->port.handle_break = up->port.handle_break; 821 + if (up->dl_read) 822 + uart->dl_read = up->dl_read; 823 + if (up->dl_write) 824 + uart->dl_write = up->dl_write; 825 + 728 826 if (uart->port.type != PORT_8250_CIR) { 729 - struct mctrl_gpios *gpios; 827 + if (uart_console_registered(&uart->port)) 828 + pm_runtime_get_sync(uart->port.dev); 730 829 731 - if (uart->port.dev) 732 - uart_remove_one_port(&serial8250_reg, &uart->port); 830 + if (serial8250_isa_config != NULL) 831 + serial8250_isa_config(0, &uart->port, 832 + &uart->capabilities); 733 833 734 - uart->port.ctrl_id = up->port.ctrl_id; 735 - uart->port.port_id = up->port.port_id; 736 - uart->port.iobase = up->port.iobase; 737 - uart->port.membase = up->port.membase; 738 - uart->port.irq = up->port.irq; 739 - uart->port.irqflags = up->port.irqflags; 740 - uart->port.uartclk = up->port.uartclk; 741 - uart->port.fifosize = up->port.fifosize; 742 - uart->port.regshift = up->port.regshift; 743 - uart->port.iotype = up->port.iotype; 744 - uart->port.flags = up->port.flags | UPF_BOOT_AUTOCONF; 745 - uart->bugs = up->bugs; 746 - uart->port.mapbase = up->port.mapbase; 747 - uart->port.mapsize = up->port.mapsize; 748 - uart->port.private_data = up->port.private_data; 749 - uart->tx_loadsz = up->tx_loadsz; 750 - uart->capabilities = up->capabilities; 751 - uart->port.throttle = up->port.throttle; 752 - uart->port.unthrottle = up->port.unthrottle; 753 - uart->port.rs485_config = up->port.rs485_config; 754 - uart->port.rs485_supported = up->port.rs485_supported; 755 - uart->port.rs485 = up->port.rs485; 756 - uart->rs485_start_tx = up->rs485_start_tx; 757 - uart->rs485_stop_tx = up->rs485_stop_tx; 758 - uart->lsr_save_mask = up->lsr_save_mask; 759 - uart->dma = up->dma; 834 + serial8250_apply_quirks(uart); 835 + ret = uart_add_one_port(&serial8250_reg, 836 + &uart->port); 837 + if (ret) 838 + goto err; 760 839 761 - /* Take tx_loadsz from fifosize if it wasn't set separately */ 762 - if (uart->port.fifosize && !uart->tx_loadsz) 763 - uart->tx_loadsz = uart->port.fifosize; 840 + ret = uart->port.line; 841 + } else { 842 + dev_info(uart->port.dev, 843 + "skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n", 844 + uart->port.iobase, 845 + (unsigned long long)uart->port.mapbase, 846 + uart->port.irq); 764 847 765 - if (up->port.dev) { 766 - uart->port.dev = up->port.dev; 767 - ret = uart_get_rs485_mode(&uart->port); 768 - if (ret) 769 - goto err; 770 - } 848 + ret = 0; 849 + } 771 850 772 - if (up->port.flags & UPF_FIXED_TYPE) 773 - uart->port.type = up->port.type; 851 + if (!uart->lsr_save_mask) 852 + uart->lsr_save_mask = LSR_SAVE_FLAGS; /* Use default LSR mask */ 774 853 775 - /* 776 - * Only call mctrl_gpio_init(), if the device has no ACPI 777 - * companion device 778 - */ 779 - if (!has_acpi_companion(uart->port.dev)) { 780 - gpios = mctrl_gpio_init(&uart->port, 0); 781 - if (IS_ERR(gpios)) { 782 - ret = PTR_ERR(gpios); 783 - goto err; 784 - } else { 785 - uart->gpios = gpios; 786 - } 787 - } 788 - 789 - serial8250_set_defaults(uart); 790 - 791 - /* Possibly override default I/O functions. */ 792 - if (up->port.serial_in) 793 - uart->port.serial_in = up->port.serial_in; 794 - if (up->port.serial_out) 795 - uart->port.serial_out = up->port.serial_out; 796 - if (up->port.handle_irq) 797 - uart->port.handle_irq = up->port.handle_irq; 798 - /* Possibly override set_termios call */ 799 - if (up->port.set_termios) 800 - uart->port.set_termios = up->port.set_termios; 801 - if (up->port.set_ldisc) 802 - uart->port.set_ldisc = up->port.set_ldisc; 803 - if (up->port.get_mctrl) 804 - uart->port.get_mctrl = up->port.get_mctrl; 805 - if (up->port.set_mctrl) 806 - uart->port.set_mctrl = up->port.set_mctrl; 807 - if (up->port.get_divisor) 808 - uart->port.get_divisor = up->port.get_divisor; 809 - if (up->port.set_divisor) 810 - uart->port.set_divisor = up->port.set_divisor; 811 - if (up->port.startup) 812 - uart->port.startup = up->port.startup; 813 - if (up->port.shutdown) 814 - uart->port.shutdown = up->port.shutdown; 815 - if (up->port.pm) 816 - uart->port.pm = up->port.pm; 817 - if (up->port.handle_break) 818 - uart->port.handle_break = up->port.handle_break; 819 - if (up->dl_read) 820 - uart->dl_read = up->dl_read; 821 - if (up->dl_write) 822 - uart->dl_write = up->dl_write; 823 - 824 - if (uart->port.type != PORT_8250_CIR) { 825 - if (uart_console_registered(&uart->port)) 826 - pm_runtime_get_sync(uart->port.dev); 827 - 828 - if (serial8250_isa_config != NULL) 829 - serial8250_isa_config(0, &uart->port, 830 - &uart->capabilities); 831 - 832 - serial8250_apply_quirks(uart); 833 - ret = uart_add_one_port(&serial8250_reg, 834 - &uart->port); 835 - if (ret) 836 - goto err; 837 - 838 - ret = uart->port.line; 839 - } else { 840 - dev_info(uart->port.dev, 841 - "skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n", 842 - uart->port.iobase, 843 - (unsigned long long)uart->port.mapbase, 844 - uart->port.irq); 845 - 846 - ret = 0; 847 - } 848 - 849 - if (!uart->lsr_save_mask) 850 - uart->lsr_save_mask = LSR_SAVE_FLAGS; /* Use default LSR mask */ 851 - 852 - /* Initialise interrupt backoff work if required */ 853 - if (up->overrun_backoff_time_ms > 0) { 854 - uart->overrun_backoff_time_ms = 855 - up->overrun_backoff_time_ms; 856 - INIT_DELAYED_WORK(&uart->overrun_backoff, 857 - serial_8250_overrun_backoff_work); 858 - } else { 859 - uart->overrun_backoff_time_ms = 0; 860 - } 854 + /* Initialise interrupt backoff work if required */ 855 + if (up->overrun_backoff_time_ms > 0) { 856 + uart->overrun_backoff_time_ms = 857 + up->overrun_backoff_time_ms; 858 + INIT_DELAYED_WORK(&uart->overrun_backoff, 859 + serial_8250_overrun_backoff_work); 860 + } else { 861 + uart->overrun_backoff_time_ms = 0; 861 862 } 862 863 863 864 unlock: