[PATCH] dz: test after postfix decrement fails in dz_console_putchar() - Kernel

This is a discussion on [PATCH] dz: test after postfix decrement fails in dz_console_putchar() - Kernel ; When loops reaches 0 the postfix decrement still subtracts, so the test fails Signed-off-by: Roel Kluin --- diff --git a/drivers/serial/dz.c b/drivers/serial/dz.c index 116211f..0dddd68 100644 --- a/drivers/serial/dz.c +++ b/drivers/serial/dz.c @@ -819,7 +819,7 @@ static void dz_console_putchar(struct uart_port *uport, int ch) dz_out(dport, ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: [PATCH] dz: test after postfix decrement fails in dz_console_putchar()

  1. [PATCH] dz: test after postfix decrement fails in dz_console_putchar()

    When loops reaches 0 the postfix decrement still subtracts, so the test fails

    Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
    ---
    diff --git a/drivers/serial/dz.c b/drivers/serial/dz.c
    index 116211f..0dddd68 100644
    --- a/drivers/serial/dz.c
    +++ b/drivers/serial/dz.c
    @@ -819,7 +819,7 @@ static void dz_console_putchar(struct uart_port *uport, int ch)
    dz_out(dport, DZ_TCR, mask);
    iob();
    udelay(2);
    - } while (loops--);
    + } while (--loops);

    if (loops) /* Cannot send otherwise. */
    dz_out(dport, DZ_TDR, ch);
    --
    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/

  2. Re: [PATCH] dz: test after postfix decrement fails in dz_console_putchar()

    On Wed, 9 Apr 2008, Roel Kluin wrote:

    > When loops reaches 0 the postfix decrement still subtracts, so the test
    > fails


    You are right -- thanks for spotting it!

    Acked-by: Maciej W. Rozycki

    Maciej

    --
    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/

  3. Re: [PATCH] dz: test after postfix decrement fails in dz_console_putchar()

    Hi,

    Roel Kluin <12o3l@tiscali.nl> writes:

    > When loops reaches 0 the postfix decrement still subtracts, so the test fails
    >
    > Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
    > ---
    > diff --git a/drivers/serial/dz.c b/drivers/serial/dz.c
    > index 116211f..0dddd68 100644
    > --- a/drivers/serial/dz.c
    > +++ b/drivers/serial/dz.c
    > @@ -819,7 +819,7 @@ static void dz_console_putchar(struct uart_port *uport, int ch)
    > dz_out(dport, DZ_TCR, mask);
    > iob();
    > udelay(2);
    > - } while (loops--);
    > + } while (--loops);


    It will run loops + 1 times. After your change it does run loops times.

    > if (loops) /* Cannot send otherwise. */
    > dz_out(dport, DZ_TDR, ch);


    The intention was probably that this gets executed if the break in the
    loop (trdy == dport->port.line) is reached. Without your fix, this
    branch is also taken if the while-loop terminates with loops == -1
    because of the postfix dec.

    Your fix is correct but your changelog entry is wrong.

    Hannes
    --
    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/

  4. Re: [PATCH] dz: test after postfix decrement fails in dz_console_putchar()

    On Wed, 9 Apr 2008, Johannes Weiner wrote:

    > The intention was probably that this gets executed if the break in the
    > loop (trdy == dport->port.line) is reached. Without your fix, this
    > branch is also taken if the while-loop terminates with loops == -1
    > because of the postfix dec.


    You are right about the intention -- you cannot send a character to the
    transmitter unless the intended line has been reported as selected for
    transmission by the serial controller. Otherwise it will go to the wrong
    line -- this is a serial multiplexer that selects transmission lines by
    itself.

    It used to be the other kind of a "while" loop. This is a cut & paste
    bug -- I noticed the problem with the terminating condition of the loop
    and correctly moved it to the end, but forgot to adjust the
    decrementation.

    > Your fix is correct but your changelog entry is wrong.


    s/fails/incorrectly succeeds/

    Maciej
    --
    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/

+ Reply to Thread