* [PATCH] Fix Specialix SX corruption
@ 2006-02-27 11:08 Marc Zyngier
2006-02-27 12:08 ` Rogier Wolff
0 siblings, 1 reply; 2+ messages in thread
From: Marc Zyngier @ 2006-02-27 11:08 UTC (permalink / raw)
To: R.E.Wolff; +Cc: linux-kernel, akpm, torvalds, alan
Roger,
With the latest kernels, I experienced some strange corruption, some
'*****' being randomly inserted in the character flow, like this:
ashes:~#
ashes:~#
a*******shes:~#
ashes:~#
ashes:~#
Further investigation shows that the problem was introduced during
Alan's "TTY layer buffering revamp" patch, the amount of data to be
copied being reduced after buffer allocation. Moving the count fixup
around solves the problem.
Patch against v2.6.16-rc5.
Signed-off-by: Marc Zyngier <maz@misterjones.org>
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index 588e75e..a6b4f02 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -1095,17 +1095,17 @@ static inline void sx_receive_chars (str
sx_dprintk (SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c);
+ /* Don't copy past the end of the hardware receive buffer */
+ if (rx_op + c > 0x100) c = 0x100 - rx_op;
+
+ sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
+
/* Don't copy more bytes than there is room for in the buffer */
c = tty_prepare_flip_string(tty, &rp, c);
sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
- /* Don't copy past the end of the hardware receive buffer */
- if (rx_op + c > 0x100) c = 0x100 - rx_op;
-
- sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
-
/* If for one reason or another, we can't copy more data, we're done! */
if (c == 0) break;
--
And if you don't know where you're going, any road will take you there...
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix Specialix SX corruption
2006-02-27 11:08 [PATCH] Fix Specialix SX corruption Marc Zyngier
@ 2006-02-27 12:08 ` Rogier Wolff
0 siblings, 0 replies; 2+ messages in thread
From: Rogier Wolff @ 2006-02-27 12:08 UTC (permalink / raw)
To: Marc Zyngier; +Cc: R.E.Wolff, linux-kernel, akpm, torvalds, alan
On Mon, Feb 27, 2006 at 12:08:00PM +0100, Marc Zyngier wrote:
> Roger,
>
> With the latest kernels, I experienced some strange corruption, some
> '*****' being randomly inserted in the character flow, like this:
>
> ashes:~#
> ashes:~#
> a*******shes:~#
> ashes:~#
> ashes:~#
>
> Further investigation shows that the problem was introduced during
> Alan's "TTY layer buffering revamp" patch, the amount of data to be
> copied being reduced after buffer allocation. Moving the count fixup
> around solves the problem.
>
> Patch against v2.6.16-rc5.
>
> Signed-off-by: Marc Zyngier <maz@misterjones.org>
>
> diff --git a/drivers/char/sx.c b/drivers/char/sx.c
> index 588e75e..a6b4f02 100644
> --- a/drivers/char/sx.c
> +++ b/drivers/char/sx.c
> @@ -1095,17 +1095,17 @@ static inline void sx_receive_chars (str
>
> sx_dprintk (SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c);
>
> + /* Don't copy past the end of the hardware receive buffer */
> + if (rx_op + c > 0x100) c = 0x100 - rx_op;
> +
> + sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
> +
> /* Don't copy more bytes than there is room for in the buffer */
>
> c = tty_prepare_flip_string(tty, &rp, c);
>
> sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
>
> - /* Don't copy past the end of the hardware receive buffer */
> - if (rx_op + c > 0x100) c = 0x100 - rx_op;
> -
> - sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
> -
The idea behind this code is that we start out with the maximum amount of
data we'd want to copy, and then reduce it to prevent copying more data
than we should for any other reason we can think of.
The reason I do it this way is that the hardware for instance may increase
the number of bytes that can be copied, just because another byte came in.
The rest of the system may INCREASE the number of bytes we can put in the buffer
because someone copied bytes out of the buffer or something like that
(probably doesn't happen like that because it's called a flip-buffer, but
whatever).
Both of these "races" are not really races: We'd end up copying less data this
time, and we'd copy the rest the next time.
So, if the modern flip buffer stuff expects us to provide the exact number
of bytes we prepared the flip buffer for we shouldn't adjust the number of chars
copied after preparing the flip buffer.
So indeed the check for the end of the hardware buffer needs to go before the
prepare flip string.
Approved!
Roger.
--
** R.E.Wolff@BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2600998 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
Q: It doesn't work. A: Look buddy, doesn't work is an ambiguous statement.
Does it sit on the couch all day? Is it unemployed? Please be specific!
Define 'it' and what it isn't doing. --------- Adapted from lxrbot FAQ
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-02-27 12:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-27 11:08 [PATCH] Fix Specialix SX corruption Marc Zyngier
2006-02-27 12:08 ` Rogier Wolff
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.