Patch: fix serial.c race prevention bug

From: Russell King (rmk@arm.linux.org.uk)
Date: Thu Nov 01 2001 - 13:02:45 EST


Alan, lkml,

serial.c appears to contain a bug in the race prevention code:

        /*
         * If we're about to load something into the transmit
         * register, we'll pretend the transmitter isn't empty to
         * avoid a race condition (depending on when the transmit
         * interrupt happens).
         */
        if (info->x_char ||
            ((CIRC_CNT(info->xmit.head, info->xmit.tail,
                       SERIAL_XMIT_SIZE) > 0) &&
             !info->tty->stopped && !info->tty->hw_stopped))
                result &= TIOCSER_TEMT;

The comment doesn't agree with the action the code is taking, and,
since result is either 0 or TIOCSER_TEMT anyway, it is a no-op
whether the if condition is true or false.

The following patch makes the race prevention code actually do
something, namely what is described in the comment.

This is only an issue for people using the TIOCSERGETLSR ioctl.

--- orig/drivers/char/serial.c Sun Oct 28 20:36:48 2001
+++ linux/drivers/char/serial.c Thu Nov 1 17:58:28 2001
@@ -2250,7 +2250,7 @@
             ((CIRC_CNT(info->xmit.head, info->xmit.tail,
                        SERIAL_XMIT_SIZE) > 0) &&
              !info->tty->stopped && !info->tty->hw_stopped))
- result &= TIOCSER_TEMT;
+ result &= ~TIOCSER_TEMT;
 
         if (copy_to_user(value, &result, sizeof(int)))
                 return -EFAULT;

--
Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Nov 07 2001 - 21:00:15 EST