Re: small patch for pty.c

From: Richard B. Johnson (root@chaos.analogic.com)
Date: Mon Apr 17 2000 - 07:45:44 EST


On Mon, 17 Apr 2000, Paul Mackerras wrote:

> In looking through drivers/char/pty.c, I saw a couple of places where
> the MIN() macro is used and one of its arguments is a function call
> which could potentially return a different number each time it is
> called, particularly on SMP systems. Here is a patch to fix that.
>
> Paul.
>
> diff -urN official/drivers/char/pty.c linux/drivers/char/pty.c
> --- official/drivers/char/pty.c Thu Apr 13 10:25:09 2000
> +++ linux/drivers/char/pty.c Thu Apr 13 21:37:13 2000
> @@ -149,7 +149,9 @@
> temp_buffer = &tty->flip.char_buf[0];
> while (count > 0) {
> /* check space so we don't copy needlessly */
> - n = MIN(count, to->ldisc.receive_room(to));
> + n = to->ldisc.receive_room(to);
> + if (n > count)
> + n = count;
> if (!n) break;
>
> n = MIN(n, PTY_BUF_SIZE);
> @@ -161,7 +163,9 @@
> }
>
> /* check again in case the buffer filled up */
> - n = MIN(n, to->ldisc.receive_room(to));
> + n = to->ldisc.receive_room(to);
> + if (n > count)
> + n = count;
> if (!n) break;
> buf += n;
> c += n;
>
>
> -
Shouldn't the macro be fixed (if broken)? MIN is used a lot in the
source. Several years ago I made one in which the input parameters were
not evaluated twice and it was __static__ __inline__. This was not
accepted, perhaps it's time?

Cheers,
Dick Johnson

Penguin : Linux version 2.3.41 on an i686 machine (800.63 BogoMips).

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



This archive was generated by hypermail 2b29 : Sun Apr 23 2000 - 21:00:10 EST