]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Input: libps2 - use guard notation when temporarily pausing serio ports
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 5 Sep 2024 04:17:07 +0000 (21:17 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 4 Oct 2024 07:58:14 +0000 (00:58 -0700)
Using guard notation makes the code more compact and error handling
more robust by ensuring that serio ports are resumed in all code paths
when control leaves critical section.

Link: https://lore.kernel.org/r/20240905041732.2034348-3-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/serio/libps2.c

index 6d78a1fe00c1bf43c18d750b43f3391f00be4541..c22ea532276eb918758bb1bb544badeafe8b5331 100644 (file)
@@ -108,13 +108,11 @@ int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout)
 {
        int retval;
 
-       serio_pause_rx(ps2dev->serio);
+       guard(serio_pause_rx)(ps2dev->serio);
 
        retval = ps2_do_sendbyte(ps2dev, byte, timeout, 1);
        dev_dbg(&ps2dev->serio->dev, "%02x - %x\n", byte, ps2dev->nak);
 
-       serio_continue_rx(ps2dev->serio);
-
        return retval;
 }
 EXPORT_SYMBOL(ps2_sendbyte);
@@ -162,10 +160,10 @@ void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout)
 
        ps2_begin_command(ps2dev);
 
-       serio_pause_rx(ps2dev->serio);
-       ps2dev->flags = PS2_FLAG_CMD;
-       ps2dev->cmdcnt = maxbytes;
-       serio_continue_rx(ps2dev->serio);
+       scoped_guard(serio_pause_rx, ps2dev->serio) {
+               ps2dev->flags = PS2_FLAG_CMD;
+               ps2dev->cmdcnt = maxbytes;
+       }
 
        wait_event_timeout(ps2dev->wait,
                           !(ps2dev->flags & PS2_FLAG_CMD),
@@ -224,9 +222,9 @@ static int ps2_adjust_timeout(struct ps2dev *ps2dev,
                 * use alternative probe to detect it.
                 */
                if (ps2dev->cmdbuf[1] == 0xaa) {
-                       serio_pause_rx(ps2dev->serio);
-                       ps2dev->flags = 0;
-                       serio_continue_rx(ps2dev->serio);
+                       scoped_guard(serio_pause_rx, ps2dev->serio)
+                               ps2dev->flags = 0;
+
                        timeout = 0;
                }
 
@@ -235,9 +233,9 @@ static int ps2_adjust_timeout(struct ps2dev *ps2dev,
                 * won't be 2nd byte of ID response.
                 */
                if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) {
-                       serio_pause_rx(ps2dev->serio);
-                       ps2dev->flags = ps2dev->cmdcnt = 0;
-                       serio_continue_rx(ps2dev->serio);
+                       scoped_guard(serio_pause_rx, ps2dev->serio)
+                               ps2dev->flags = ps2dev->cmdcnt = 0;
+
                        timeout = 0;
                }
                break;
@@ -283,6 +281,10 @@ int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command)
 
        memcpy(send_param, param, send);
 
+       /*
+        * Not using guard notation because we need to break critical
+        * section below while waiting for the response.
+        */
        serio_pause_rx(ps2dev->serio);
 
        ps2dev->cmdcnt = receive;