* [BUG/PATCH] : bug in tty_default_put_char()
@ 2002-08-26 18:07 Jean Tourrilhes
[not found] ` <1030388224.2797.2.camel@irongate.swansea.linux.org.uk>
2002-08-26 19:31 ` Russell King
0 siblings, 2 replies; 7+ messages in thread
From: Jean Tourrilhes @ 2002-08-26 18:07 UTC (permalink / raw)
To: Linux kernel mailing list, Alan Cox, tytso, Russell King,
Andrew Morton
Cc: irda-users
Hi,
Bug : tty_default_put_char() doesn't check the return value of
tty->driver.write(). However, the later may fail if buffers are full.
Solution : It's not obvious what should be done. The attached
patch is certainly wrong, but gives you an idea of what the problem
is.
Long story :
User weant to do PPP over IrCOMM. "chat" opens ircomm device
in non blocking mode and write char by char. I suspect that it's using
the above call, but can't verify (because it doesn't happen to me). As
IrCOMM has not finished its initialisation (the open was
non-blocking), it refuses the write and returns 0.
Character dropped, user unhappy, bugs me about it.
I'll try to workaround that in IrCOMM.
Regards,
Jean
-----------------------------------------------
diff -u -p linux/drivers/char/tty_io.t1.c linux/drivers/char/tty_io.c
--- linux/drivers/char/tty_io.t1.c Mon Aug 26 10:55:33 2002
+++ linux/drivers/char/tty_io.c Mon Aug 26 10:58:34 2002
@@ -2021,7 +2021,11 @@ static void initialize_tty_struct(struct
*/
void tty_default_put_char(struct tty_struct *tty, unsigned char ch)
{
- tty->driver.write(tty, 0, &ch, 1);
+ int ret = tty->driver.write(tty, 0, &ch, 1);
+ /* This might fail if the lower layer is already full - Jean II */
+ if (ret == 0)
+ printk(KERN_WARNING "Warning: dev (%s) put_char failed\n",
+ kdevname(tty->device));
}
/*
^ permalink raw reply [flat|nested] 7+ messages in thread[parent not found: <1030388224.2797.2.camel@irongate.swansea.linux.org.uk>]
* Re: [BUG/PATCH] : bug in tty_default_put_char()
[not found] ` <1030388224.2797.2.camel@irongate.swansea.linux.org.uk>
@ 2002-08-26 18:59 ` Jean Tourrilhes
2002-08-26 19:07 ` Alan Cox
0 siblings, 1 reply; 7+ messages in thread
From: Jean Tourrilhes @ 2002-08-26 18:59 UTC (permalink / raw)
To: Alan Cox; +Cc: Linux kernel mailing list
On Mon, Aug 26, 2002 at 07:57:04PM +0100, Alan Cox wrote:
> On Mon, 2002-08-26 at 19:07, Jean Tourrilhes wrote:
> > Hi,
> >
> > Bug : tty_default_put_char() doesn't check the return value of
> > tty->driver.write(). However, the later may fail if buffers are full.
> >
> > Solution : It's not obvious what should be done. The attached
> > patch is certainly wrong, but gives you an idea of what the problem
> > is.
>
> Make it an int and return the tty->driver.write value. We know that
> since its void nobody is currently checking the error code, and now they
> can where it matters
Just check drivers/char/n_tty.c for every occurence of
put_char() and be scared. The problem is to find a practical solution.
For myself, I've added some clever workaround in IrCOMM to
accept data before full setup.
Regards,
Jean
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [BUG/PATCH] : bug in tty_default_put_char()
2002-08-26 18:59 ` Jean Tourrilhes
@ 2002-08-26 19:07 ` Alan Cox
2002-08-26 20:17 ` Russell King
0 siblings, 1 reply; 7+ messages in thread
From: Alan Cox @ 2002-08-26 19:07 UTC (permalink / raw)
To: jt; +Cc: Linux kernel mailing list
On Mon, 2002-08-26 at 19:59, Jean Tourrilhes wrote:
> Just check drivers/char/n_tty.c for every occurence of
> put_char() and be scared. The problem is to find a practical solution.
> For myself, I've added some clever workaround in IrCOMM to
> accept data before full setup.
Sure making it return the right errors doesnt fix anything, but it
allows you to fix some of it bit by bit.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [BUG/PATCH] : bug in tty_default_put_char()
2002-08-26 19:07 ` Alan Cox
@ 2002-08-26 20:17 ` Russell King
0 siblings, 0 replies; 7+ messages in thread
From: Russell King @ 2002-08-26 20:17 UTC (permalink / raw)
To: Alan Cox; +Cc: jt, Linux kernel mailing list
On Mon, Aug 26, 2002 at 08:07:27PM +0100, Alan Cox wrote:
> On Mon, 2002-08-26 at 19:59, Jean Tourrilhes wrote:
> > Just check drivers/char/n_tty.c for every occurence of
> > put_char() and be scared. The problem is to find a practical solution.
> > For myself, I've added some clever workaround in IrCOMM to
> > accept data before full setup.
>
> Sure making it return the right errors doesnt fix anything, but it
> allows you to fix some of it bit by bit.
put_char() is not allowed to fail since the caller should have already
checked for buffer space via the write_room() method.
All places look adequately protected in n_tty.c, so I'm not currently
sure how Jean's users are seeing this condition; I'd need to have a
BUG() showing the call trace of such an event happening.
--
Russell King (rmk@arm.linux.org.uk) The developer of ARM Linux
http://www.arm.linux.org.uk/personal/aboutme.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [BUG/PATCH] : bug in tty_default_put_char()
2002-08-26 18:07 [BUG/PATCH] : bug in tty_default_put_char() Jean Tourrilhes
[not found] ` <1030388224.2797.2.camel@irongate.swansea.linux.org.uk>
@ 2002-08-26 19:31 ` Russell King
[not found] ` <20020826195346.GC8749@bougret.hpl.hp.com>
1 sibling, 1 reply; 7+ messages in thread
From: Russell King @ 2002-08-26 19:31 UTC (permalink / raw)
To: jt; +Cc: Linux kernel mailing list, Alan Cox, tytso, Andrew Morton,
irda-users
On Mon, Aug 26, 2002 at 11:07:49AM -0700, Jean Tourrilhes wrote:
> Bug : tty_default_put_char() doesn't check the return value of
> tty->driver.write(). However, the later may fail if buffers are full.
Hmm.
> Solution : It's not obvious what should be done. The attached
> patch is certainly wrong, but gives you an idea of what the problem
> is.
Every invocation of the put_char() method should be preceded by a check
to ensure that there is sufficient space in the drivers buffer (via the
drivers write_room() call.) Could you add a BUG() on this condition
and get some call traces please?
> I'll try to workaround that in IrCOMM.
I don't think that should be necessary. The tty layer is obviously
doing something it shouldn't (trying to stuff characters into a buffer
of zero size) so it should get fixed.
--
Russell King (rmk@arm.linux.org.uk) The developer of ARM Linux
http://www.arm.linux.org.uk/personal/aboutme.html
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2002-08-28 23:12 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-26 18:07 [BUG/PATCH] : bug in tty_default_put_char() Jean Tourrilhes
[not found] ` <1030388224.2797.2.camel@irongate.swansea.linux.org.uk>
2002-08-26 18:59 ` Jean Tourrilhes
2002-08-26 19:07 ` Alan Cox
2002-08-26 20:17 ` Russell King
2002-08-26 19:31 ` Russell King
[not found] ` <20020826195346.GC8749@bougret.hpl.hp.com>
[not found] ` <20020826210159.E4763@flint.arm.linux.org.uk>
[not found] ` <20020826201732.GE8749@bougret.hpl.hp.com>
[not found] ` <20020826212223.H4763@flint.arm.linux.org.uk>
2002-08-28 22:41 ` Jean Tourrilhes
2002-08-28 23:16 ` Russell King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox