lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 7 Mar 2017 10:07:56 -0600
From:   Rob Herring <robh+dt@...nel.org>
To:     Sebastian Reichel <sre@...nel.org>
Cc:     Marcel Holtmann <marcel@...tmann.org>,
        Gustavo Padovan <gustavo@...ovan.org>,
        Johan Hedberg <johan.hedberg@...il.com>,
        Tony Lindgren <tony@...mide.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Jiri Slaby <jslaby@...e.com>,
        Mark Rutland <mark.rutland@....com>,
        "open list:BLUETOOTH DRIVERS" <linux-bluetooth@...r.kernel.org>,
        "linux-serial@...r.kernel.org" <linux-serial@...r.kernel.org>,
        "devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 09/10] serdev: add serdev_device_set_rts

On Sat, Mar 4, 2017 at 5:58 AM, Sebastian Reichel <sre@...nel.org> wrote:
> Add function to enable/disable RTS line.
>
> Signed-off-by: Sebastian Reichel <sre@...nel.org>
> ---

> +static void ttyport_set_rts(struct serdev_controller *ctrl, bool enable)
> +{
> +       struct serport *serport = serdev_controller_get_drvdata(ctrl);
> +       struct tty_struct *tty = serport->tty;
> +       int status = tty->driver->ops->tiocmget(tty);
> +       unsigned int set = 0;
> +       unsigned int clear = 0;
> +
> +       if (enable) {
> +               set |= (TIOCM_OUT2 | TIOCM_RTS);
> +               clear = ~set;
> +               set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
> +                      TIOCM_OUT2 | TIOCM_LOOP;
> +               clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
> +                        TIOCM_OUT2 | TIOCM_LOOP;
> +               status = tty->driver->ops->tiocmset(tty, set, clear);
> +       } else {
> +               set &= ~(TIOCM_OUT2 | TIOCM_RTS);
> +               clear = ~set;
> +               set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
> +                      TIOCM_OUT2 | TIOCM_LOOP;
> +               clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
> +                        TIOCM_OUT2 | TIOCM_LOOP;
> +               status = tty->driver->ops->tiocmset(tty, set, clear);

The logic here can be greatly simplified. Here's a patch to the
original version that I came up with, but haven't tested:

diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index de20a438a78a..0e35663c5d04 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -264,8 +264,8 @@ void hci_uart_set_flow_control(struct hci_uart
*hu, bool enable)
        struct tty_struct *tty = hu->tty;
        struct ktermios ktermios;
        int status;
-       unsigned int set = 0;
-       unsigned int clear = 0;
+       unsigned int set;
+       unsigned int clear = TIOCM_DTR | TIOCM_OUT1 | TIOCM_LOOP;

        if (enable) {
                /* Disable hardware flow control */
@@ -280,25 +280,15 @@ void hci_uart_set_flow_control(struct hci_uart
*hu, bool enable)
                status = tty->driver->ops->tiocmget(tty);
                BT_DBG("Current tiocm 0x%x", status);

-               set &= ~(TIOCM_OUT2 | TIOCM_RTS);
-               clear = ~set;
-               set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
-                      TIOCM_OUT2 | TIOCM_LOOP;
-               clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
-                        TIOCM_OUT2 | TIOCM_LOOP;
-               status = tty->driver->ops->tiocmset(tty, set, clear);
+               clear |= TIOCM_RTS | TIOCM_OUT2;
+               status = tty->driver->ops->tiocmset(tty, 0, clear);
                BT_DBG("Clearing RTS: %s", status ? "failed" : "success");
        } else {
                /* Set RTS to allow the device to send again */
                status = tty->driver->ops->tiocmget(tty);
                BT_DBG("Current tiocm 0x%x", status);

-               set |= (TIOCM_OUT2 | TIOCM_RTS);
-               clear = ~set;
-               set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
-                      TIOCM_OUT2 | TIOCM_LOOP;
-               clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
-                        TIOCM_OUT2 | TIOCM_LOOP;
+               set = TIOCM_OUT2 | TIOCM_RTS;
                status = tty->driver->ops->tiocmset(tty, set, clear);
                BT_DBG("Setting RTS: %s", status ? "failed" : "success");

Powered by blists - more mailing lists