The drivers RS485 support is deactivated if there is no RTS GPIO available. This is done by nullifying the ports rs485_supported struct. After that however the settings in serial_omap_rs485_supported are assigned to the same structure unconditionally, which results in an unintended reactivation of RS485 support.
Fix this by moving the assignment to the beginning of serial_omap_probe_rs485() and thus before uart_get_rs485_mode() gets called.
Also replace the assignment of rs485_config() to have the complete RS485 setup in one function.
Fixes: e2752ae3cfc9 ("serial: omap: Disallow RS-485 if rts-gpio is not specified") Cc: stable@vger.kernel.org Signed-off-by: Lino Sanfilippo l.sanfilippo@kunbus.com --- drivers/tty/serial/omap-serial.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c index ad4c1c5d0a7f..b563c109caa9 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -1497,6 +1497,9 @@ static int serial_omap_probe_rs485(struct uart_omap_port *up, if (!np) return 0;
+ up->port.rs485_config = serial_omap_config_rs485; + up->port.rs485_supported = serial_omap_rs485_supported; + ret = uart_get_rs485_mode(&up->port); if (ret) return ret; @@ -1604,17 +1607,11 @@ static int serial_omap_probe(struct platform_device *pdev) dev_info(up->port.dev, "no wakeirq for uart%d\n", up->port.line);
- ret = serial_omap_probe_rs485(up, &pdev->dev); - if (ret < 0) - goto err_rs485; - sprintf(up->name, "OMAP UART%d", up->port.line); up->port.mapbase = mem->start; up->port.membase = base; up->port.flags = omap_up_info->flags; up->port.uartclk = omap_up_info->uartclk; - up->port.rs485_config = serial_omap_config_rs485; - up->port.rs485_supported = serial_omap_rs485_supported; if (!up->port.uartclk) { up->port.uartclk = DEFAULT_CLK_SPEED; dev_warn(&pdev->dev, @@ -1622,6 +1619,10 @@ static int serial_omap_probe(struct platform_device *pdev) DEFAULT_CLK_SPEED); }
+ ret = serial_omap_probe_rs485(up, &pdev->dev); + if (ret < 0) + goto err_rs485; + up->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; up->calc_latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; cpu_latency_qos_add_request(&up->pm_qos_request, up->latency);
Hi Lino,
kernel test robot noticed the following build errors:
[auto build test ERROR on ceb6a6f023fd3e8b07761ed900352ef574010bcb]
url: https://github.com/intel-lab-lkp/linux/commits/Lino-Sanfilippo/serial-Do-not... base: ceb6a6f023fd3e8b07761ed900352ef574010bcb patch link: https://lore.kernel.org/r/20231225113524.8800-7-l.sanfilippo%40kunbus.com patch subject: [PATCH v6 6/7] serial: omap: do not override settings for RS485 support config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20231226/202312260601.aT9SYjjo-lkp@i...) compiler: sh4-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231226/202312260601.aT9SYjjo-lkp@i...)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot lkp@intel.com | Closes: https://lore.kernel.org/oe-kbuild-all/202312260601.aT9SYjjo-lkp@intel.com/
All error/warnings (new ones prefixed by >>):
drivers/tty/serial/omap-serial.c: In function 'serial_omap_probe_rs485':
drivers/tty/serial/omap-serial.c:1501:36: error: 'serial_omap_rs485_supported' undeclared (first use in this function); did you mean 'serial_omap_request_port'?
1501 | up->port.rs485_supported = serial_omap_rs485_supported; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ | serial_omap_request_port drivers/tty/serial/omap-serial.c:1501:36: note: each undeclared identifier is reported only once for each function it appears in drivers/tty/serial/omap-serial.c: At top level:
drivers/tty/serial/omap-serial.c:1537:34: warning: 'serial_omap_rs485_supported' defined but not used [-Wunused-const-variable=]
1537 | static const struct serial_rs485 serial_omap_rs485_supported = { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +1501 drivers/tty/serial/omap-serial.c
1485 1486 static int serial_omap_probe_rs485(struct uart_omap_port *up, 1487 struct device *dev) 1488 { 1489 struct serial_rs485 *rs485conf = &up->port.rs485; 1490 struct device_node *np = dev->of_node; 1491 enum gpiod_flags gflags; 1492 int ret; 1493 1494 rs485conf->flags = 0; 1495 up->rts_gpiod = NULL; 1496 1497 if (!np) 1498 return 0; 1499 1500 up->port.rs485_config = serial_omap_config_rs485;
1501 up->port.rs485_supported = serial_omap_rs485_supported;
1502 1503 ret = uart_get_rs485_mode(&up->port); 1504 if (ret) 1505 return ret; 1506 1507 if (of_property_read_bool(np, "rs485-rts-active-high")) { 1508 rs485conf->flags |= SER_RS485_RTS_ON_SEND; 1509 rs485conf->flags &= ~SER_RS485_RTS_AFTER_SEND; 1510 } else { 1511 rs485conf->flags &= ~SER_RS485_RTS_ON_SEND; 1512 rs485conf->flags |= SER_RS485_RTS_AFTER_SEND; 1513 } 1514 1515 /* check for tx enable gpio */ 1516 gflags = rs485conf->flags & SER_RS485_RTS_AFTER_SEND ? 1517 GPIOD_OUT_HIGH : GPIOD_OUT_LOW; 1518 up->rts_gpiod = devm_gpiod_get_optional(dev, "rts", gflags); 1519 if (IS_ERR(up->rts_gpiod)) { 1520 ret = PTR_ERR(up->rts_gpiod); 1521 if (ret == -EPROBE_DEFER) 1522 return ret; 1523 1524 up->rts_gpiod = NULL; 1525 up->port.rs485_supported = (const struct serial_rs485) { }; 1526 if (rs485conf->flags & SER_RS485_ENABLED) { 1527 dev_err(dev, "disabling RS-485 (rts-gpio missing in device tree)\n"); 1528 memset(rs485conf, 0, sizeof(*rs485conf)); 1529 } 1530 } else { 1531 gpiod_set_consumer_name(up->rts_gpiod, "omap-serial"); 1532 } 1533 1534 return 0; 1535 } 1536
1537 static const struct serial_rs485 serial_omap_rs485_supported = {
1538 .flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND | 1539 SER_RS485_RX_DURING_TX, 1540 .delay_rts_before_send = 1, 1541 .delay_rts_after_send = 1, 1542 }; 1543
Hi Lino,
kernel test robot noticed the following build errors:
[auto build test ERROR on ceb6a6f023fd3e8b07761ed900352ef574010bcb]
url: https://github.com/intel-lab-lkp/linux/commits/Lino-Sanfilippo/serial-Do-not... base: ceb6a6f023fd3e8b07761ed900352ef574010bcb patch link: https://lore.kernel.org/r/20231225113524.8800-7-l.sanfilippo%40kunbus.com patch subject: [PATCH v6 6/7] serial: omap: do not override settings for RS485 support config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20231226/202312260719.mI12i497-lkp@i...) compiler: clang version 18.0.0git (https://github.com/llvm/llvm-project d3ef86708241a3bee902615c190dead1638c4e09) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231226/202312260719.mI12i497-lkp@i...)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot lkp@intel.com | Closes: https://lore.kernel.org/oe-kbuild-all/202312260719.mI12i497-lkp@intel.com/
All errors (new ones prefixed by >>):
drivers/tty/serial/omap-serial.c:1501:29: error: use of undeclared identifier 'serial_omap_rs485_supported'
1501 | up->port.rs485_supported = serial_omap_rs485_supported; | ^ 1 error generated.
vim +/serial_omap_rs485_supported +1501 drivers/tty/serial/omap-serial.c
1485 1486 static int serial_omap_probe_rs485(struct uart_omap_port *up, 1487 struct device *dev) 1488 { 1489 struct serial_rs485 *rs485conf = &up->port.rs485; 1490 struct device_node *np = dev->of_node; 1491 enum gpiod_flags gflags; 1492 int ret; 1493 1494 rs485conf->flags = 0; 1495 up->rts_gpiod = NULL; 1496 1497 if (!np) 1498 return 0; 1499 1500 up->port.rs485_config = serial_omap_config_rs485;
1501 up->port.rs485_supported = serial_omap_rs485_supported;
1502 1503 ret = uart_get_rs485_mode(&up->port); 1504 if (ret) 1505 return ret; 1506 1507 if (of_property_read_bool(np, "rs485-rts-active-high")) { 1508 rs485conf->flags |= SER_RS485_RTS_ON_SEND; 1509 rs485conf->flags &= ~SER_RS485_RTS_AFTER_SEND; 1510 } else { 1511 rs485conf->flags &= ~SER_RS485_RTS_ON_SEND; 1512 rs485conf->flags |= SER_RS485_RTS_AFTER_SEND; 1513 } 1514 1515 /* check for tx enable gpio */ 1516 gflags = rs485conf->flags & SER_RS485_RTS_AFTER_SEND ? 1517 GPIOD_OUT_HIGH : GPIOD_OUT_LOW; 1518 up->rts_gpiod = devm_gpiod_get_optional(dev, "rts", gflags); 1519 if (IS_ERR(up->rts_gpiod)) { 1520 ret = PTR_ERR(up->rts_gpiod); 1521 if (ret == -EPROBE_DEFER) 1522 return ret; 1523 1524 up->rts_gpiod = NULL; 1525 up->port.rs485_supported = (const struct serial_rs485) { }; 1526 if (rs485conf->flags & SER_RS485_ENABLED) { 1527 dev_err(dev, "disabling RS-485 (rts-gpio missing in device tree)\n"); 1528 memset(rs485conf, 0, sizeof(*rs485conf)); 1529 } 1530 } else { 1531 gpiod_set_consumer_name(up->rts_gpiod, "omap-serial"); 1532 } 1533 1534 return 0; 1535 } 1536
linux-stable-mirror@lists.linaro.org