Re: [PATCH v6 1/7] serial: Do not hold the port lock when setting rx-during-tx GPIO

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Lino Sanfilippo wrote on 2023-12-29 16:03:
Hi,

On 25.12.23 at 13:31, Maarten Brock wrote:
Lino Sanfilippo wrote on 2023-12-25 12:35:
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
+static void uart_set_rs485_rx_during_tx(struct uart_port *port,
+                    const struct serial_rs485 *rs485)
+{
+    if (!(rs485->flags & SER_RS485_ENABLED))
+        return;

How about checking port->rs485_rx_during_tx_gpio here against NULL instead of
before every call?

gpiod_set_value_cansleep() already checks for a NULL pointer, so doing
this check in the caller is not needed.

Ah, sorry, you're right.

+    gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio,
+                 !!(rs485->flags & SER_RS485_RX_DURING_TX));
+}
+
@@ -1457,6 +1472,7 @@ static int uart_set_rs485_config(struct
tty_struct *tty, struct uart_port *port,
         return ret;
     uart_sanitize_serial_rs485(port, &rs485);
     uart_set_rs485_termination(port, &rs485);
+    uart_set_rs485_rx_during_tx(port, &rs485);

     uart_port_lock_irqsave(port, &flags);
     ret = port->rs485_config(port, &tty->termios, &rs485);
@@ -1468,8 +1484,14 @@ static int uart_set_rs485_config(struct
tty_struct *tty, struct uart_port *port,
             port->ops->set_mctrl(port, port->mctrl);
     }
     uart_port_unlock_irqrestore(port, flags);
-    if (ret)
+    if (ret) {
+        /* restore old GPIO settings */
+        gpiod_set_value_cansleep(port->rs485_term_gpio,
+            !!(port->rs485.flags & SER_RS485_TERMINATE_BUS));
+        gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio,
+            !!(port->rs485.flags & SER_RS485_RX_DURING_TX));

This does not look like restoring.

Hmm. The rx-during-tx and terminate-bus GPIOs may have changed before the
drivers rs485_config() was called. If that function fails, the GPIOs
are set back to the values they had before (i.e what is still stored in
the ports serial_rs485 struct). So what is wrong with the term "restore"?

Oops, I missed that too that port-rs485 is not updated in this case.

Kind Regards,
Maarten Brock





[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux