2.5.31-serport
Subsystems (2)
PATCH 1/1 2.5.31-serport
This patch appears not to be in 2.5.32, but applies cleanly.
serport/serio presently has several problems. This is by no means a definitive list (for example, the locking problems that hch reported back in 2.4.0-test time):
1. Insomnia. When someone closes the serport device, it wakes up a thread in serport_ldisc_read(). Unfortunately, if serport->serio.type is non-zero and we haven't received a signal, we re-call schedule() without changing current->state. So schedule returns, and repeat for ever.
A better sleep solution would be:
wait_event_interruptible((&serport->wait, serport->serio.type);
which contains all the knoweldge of handling sleeping.
Someone might also think about what serport_serio_close() is actually trying to do. If its intended to cause the thread in ldisc_read exit, it should set serport->serio.type to 0.
2. What happens if I open and try to read from this port while something has the serport_ldisc attached? I suspect that you'll create nice loop of serio devices in serio.c and an infinite loop when you try to traverse the list to remove a different serio device.
3. Naming:
#ifdef CONFIG_DEVFS_FS
sprintf(name, tty->driver.name, minor(tty->device) - tty->driver.minor_start);
#else
sprintf(name, "%s%d", tty->driver.name, minor(tty->device) - tty->driver.minor_start);#endif
should probably be using tty_name(), rather than trying to construct the name itself.
4. Stack overflows. There seems to be confusion about how long a tty name can be, and we seem to add characters to the name ("/serio0") and then squash it into a smaller buffer.
char ttyname[64];
...
strcpy(ttyname, tty->driver.name);
...
sprintf(serport->phys, "%s%d/serio0", ttyname, minor(tty->device) - tty$ However, serport->phys is declared as:
struct serport {
char phys[32];
}; I'd suggest using strncpy() and snprintf() here, and adjusting the size of those strings so they're sensible.
This patch fixes (1) and (3) completey. (4) needs the sizes reviewed and fixed.
(2) is NOT fixed by this patch.
drivers/input/serio/serio.c | 8 ++++++++ drivers/input/serio/serport.c | 26 ++++++++------------------ 2 files changed, 16 insertions, 18 deletions
drivers/input/serio/serio.c +8 -0
@@ -122,6 +122,8 @@void serio_register_port (struct serio *serio) { +BUG_ON (serio->next); + serio->next = serio_list; serio_list = serio;serio_find_dev (serio);
@@ -134,6 +136,8 @@while (*serioptr && (*serioptr != serio)) serioptr = &((*serioptr)->next); *serioptr = (*serioptr)->next; + serio->next =NULL ; +if (serio->dev && serio->dev->disconnect) serio->dev->disconnect (serio); }
@@ -142,6 +146,8 @@ {struct serio *serio = serio_list; +BUG_ON (dev->next); + dev->next = serio_dev; serio_dev = dev;
@@ -159,6 +165,8 @@while (*devptr && (*devptr != dev)) devptr = &((*devptr)->next); *devptr = (*devptr)->next; + + dev->next =NULL ;while (serio) {if (serio->dev == dev && dev->disconnect)
drivers/input/serio/serport.c +8 -18
@@ -96,11 +96,14 @@ serport->tty = tty; tty->disc_data = serport; -strcpy (ttyname, tty->driver.name); -for (i =0 ; ttyname[i] !=0 && ttyname[i] !='/' ; i++); +strncpy (ttyname, tty->driver.name,sizeof (ttyname) -1 ); + +for (i =0 ; ttyname[i] !=0 && ttyname[i] !='/' && + i <sizeof (ttyname) -1 ; i++); ttyname[i] =0 ; -sprintf (serport->phys,"%s%d/serio0" , ttyname,minor (tty->device) - tty->driver.minor_start); +snprintf (serport->phys,sizeof (serport->phys),"%s%d/serio0" , + ttyname,minor (tty->device) - tty->driver.minor_start); serport->serio.name = serport_name; serport->serio.phys = serport->phys;
@@ -161,26 +164,13 @@static ssize_t serport_ldisc_read (struct tty_struct * tty,struct file * file,unsigned char * buf,size_t nr) {struct serport *serport = (struct serport *) tty->disc_data; -DECLARE_WAITQUEUE (wait, current);char name[32 ]; -#ifdef CONFIG_DEVFS_FS -sprintf (name, tty->driver.name,minor (tty->device) - tty->driver.minor_start); -#else -sprintf (name,"%s%d" , tty->driver.name,minor (tty->device) - tty->driver.minor_start); -#endif -serio_register_port (&serport->serio); -printk (KERN_INFO "serio: Serial port %s\n" , name); - -add_wait_queue (&serport->wait, &wait); -set_current_state (TASK_INTERRUPTIBLE ); - -while (serport->serio.type && !signal_pending (current))schedule (); +printk (KERN_INFO "serio: Serial port %s\n" ,tty_name (tty, name)); -set_current_state (TASK_RUNNING ); -remove_wait_queue (&serport->wait, &wait); +wait_event_interruptible (serport->wait, serport->serio.type !=0 );serio_unregister_port (&serport->serio);
From: Russell King <[email protected]>
Date: Fri, 30 Aug 2002 22:39:11 +0100
2. What happens if I open and try to read from this port while something has the serport_ldisc attached? I suspect that you'll create nice loop of serio devices in serio.c and an infinite loop when you try to traverse the list to remove a different serio device.
SERIO devices are not meant to be registered as normal TTYs. At least I don't do this for any of the Sparc serial ports when they are the keyboard/mouse serio device.
Quoted 11 lines · David S. Miller
From: Russell King <[email protected]>
Date: Fri, 30 Aug 2002 22:39:11 +01002. What happens if I open and try to read from this port while something has the
serport_ldiscattached? I suspect that you'll create nice loop of serio devices inserio.cand an infinite loop when you try to traverse the list to remove a different serio device.SERIO devices are not meant to be registered as normal TTYs. At least I don't do this for any of the Sparc serial ports when they are the keyboard/mouse serio device.
No, but using serport.c, you can bind a serio to a tty via a line discipline, for example if you want a PC serial mouse on /dev/ttyS0 to talk to sermouse.c via serio. I don't like the approach much, I hope(d) we could switch somewhere below the tty layer, but it sort of works, and maybe will have the bugs fixed sooner or later.
Signature · 2 lines
Vojtech Pavlik SuSE Labs
From: Vojtech Pavlik <[email protected]>
Date: Sat, 31 Aug 2002 00:36:18 +0200
No, but using serport.c, you can bind a serio to a tty via a line discipline, for example if you want a PC serial mouse on /dev/ttyS0 to talk to sermouse.c via serio. I don't like the approach much, I hope(d) we could switch somewhere below the tty layer, but it sort of works, and maybe will have the bugs fixed sooner or later.
So how about this:
1) When SERIO device is claimed, we fail of TTY copy is opened by any user.
2) Once we allow SERIO device to be claimed, we prevent opens of TTY copy.
I guess this is sort of what Russell is recommending.
Quoted 5 lines · David S. Miller
1) When SERIO device is claimed, we fail of TTY copy is opened by any user.
2) Once we allow SERIO device to be claimed, we prevent opens of TTY copy.
Should it not be a line discipline question ?
Quoted 14 lines · Russell King
This patch appears not to be in 2.5.32, but applies cleanly.
serport/serio presently has several problems. This is by no means a definitive list (for example, the locking problems that hch reported back in 2.4.0-test time):
1. Insomnia. When someone closes the serport device, it wakes up a thread in
serport_ldisc_read(). Unfortunately, ifserport->serio.typeis non-zero and we haven't received a signal, we re-callschedule()without changingcurrent->state. So schedule returns, and repeat for ever.A better sleep solution would be:
Quoted 7 lines
wait_event_interruptible((&serport->wait, serport->serio.type);which contains all the knoweldge of handling sleeping.
Someone might also think about what
serport_serio_close()is actually trying to do. If its intended to cause the thread inldisc_readexit, it should setserport->serio.typeto 0.
I'll answer to this as soon as I get some sleep. No pun originally intended.
Quoted 4 lines
2. What happens if I open and try to read from this port while something has the
serport_ldiscattached? I suspect that you'll create nice loop of serio devices inserio.cand an infinite loop when you try to traverse the list to remove a different serio device.
Just to make sure - the scenario would be: inputattach opening /dev/ttyS0, setting N_MOUSE ldisc. Mouse driver opening that serio, etc, etc. Then I run minicom on /dev/ttyS0?
Quoted 10 lines
3. Naming:
#ifdef CONFIG_DEVFS_FS sprintf(name, tty->driver.name, minor(tty->device) - tty->driver.minor_start); #else sprintf(name, "%s%d", tty->driver.name, minor(tty->device) - tty->driver.minor_start);#endif
should probably be using
tty_name(), rather than trying to construct the name itself.
Definitely. Not sure if that existed at the time this was written. Probably yes, though.
Quoted 9 lines
4. Stack overflows. There seems to be confusion about how long a tty name can be, and we seem to add characters to the name ("/serio0") and then squash it into a smaller buffer.
char ttyname[64]; ... strcpy(ttyname, tty->driver.name); ... sprintf(serport->phys, "%s%d/serio0", ttyname, minor(tty->device) - tty$
Quoted 8 lines
However,
serport->physis declared as:struct serport { char phys[32]; };I'd suggest using
strncpy()andsnprintf()here, and adjusting the size of those strings so they're sensible.
Indeed.
Quoted 38 lines
This patch fixes (1) and (3) completey. (4) needs the sizes reviewed and fixed.
(2) is NOT fixed by this patch.drivers/input/serio/serio.c | 8 ++++++++ drivers/input/serio/serport.c | 26 ++++++++------------------ 2 files changed, 16 insertions, 18 deletionsdiff -ur
orig/drivers/input/serio/serio.clinux/drivers/input/serio/serio.cdrivers/input/serio/serio.c +6
-0@@ -122,6 +122,8 @@void serio_register_port (struct serio *serio) { +BUG_ON (serio->next); + serio->next = serio_list; serio_list = serio;serio_find_dev (serio);@@ -134,6 +136,8 @@while (*serioptr && (*serioptr != serio)) serioptr = &((*serioptr)->next); *serioptr = (*serioptr)->next; + serio->next =NULL ; +if (serio->dev && serio->dev->disconnect) serio->dev->disconnect (serio); }@@ -142,6 +146,8 @@ {struct serio *serio = serio_list; +BUG_ON (dev->next); + dev->next = serio_dev; serio_dev = dev;
drivers/input/serio/serio.c line 172
Quoted 8 lines
drivers/input/serio/serio.c +2
-0@@ -159,6 +165,8 @@while (*devptr && (*devptr != dev)) devptr = &((*devptr)->next); *devptr = (*devptr)->next; + + dev->next =NULL ;while (serio) {if (serio->dev == dev && dev->disconnect)
This should better be fixed by switching to <linux/list.h> for the linked lists.
Quoted 50 lines
diff -ur
orig/drivers/input/serio/serport.clinux/drivers/input/serio/serport.cdrivers/input/serio/serport.c +8
-18@@ -96,11 +96,14 @@ serport->tty = tty; tty->disc_data = serport; -strcpy (ttyname, tty->driver.name); -for (i =0 ; ttyname[i] !=0 && ttyname[i] !='/' ; i++); +strncpy (ttyname, tty->driver.name,sizeof (ttyname) -1 ); + +for (i =0 ; ttyname[i] !=0 && ttyname[i] !='/' && + i <sizeof (ttyname) -1 ; i++); ttyname[i] =0 ; -sprintf (serport->phys,"%s%d/serio0" , ttyname,minor (tty->device) - tty->driver.minor_start); +snprintf (serport->phys,sizeof (serport->phys),"%s%d/serio0" , + ttyname,minor (tty->device) - tty->driver.minor_start); serport->serio.name = serport_name; serport->serio.phys = serport->phys;@@ -161,26 +164,13 @@static ssize_t serport_ldisc_read (struct tty_struct * tty,struct file * file,unsigned char * buf,size_t nr) {struct serport *serport = (struct serport *) tty->disc_data; -DECLARE_WAITQUEUE (wait, current);char name[32 ]; -#ifdef CONFIG_DEVFS_FS -sprintf (name, tty->driver.name,minor (tty->device) - tty->driver.minor_start); -#else -sprintf (name,"%s%d" , tty->driver.name,minor (tty->device) - tty->driver.minor_start); -#endif -serio_register_port (&serport->serio); -printk (KERN_INFO "serio: Serial port %s\n" , name); - -add_wait_queue (&serport->wait, &wait); -set_current_state (TASK_INTERRUPTIBLE ); - -while (serport->serio.type && !signal_pending (current))schedule (); +printk (KERN_INFO "serio: Serial port %s\n" ,tty_name (tty, name)); -set_current_state (TASK_RUNNING ); -remove_wait_queue (&serport->wait, &wait); +wait_event_interruptible (serport->wait, serport->serio.type !=0 );serio_unregister_port (&serport->serio);
Signature · 2 lines
Vojtech Pavlik SuSE Labs
PATCH 1/1 Fixes in serport.c
In reply to Russell KingQuoted 5 lines · Russell King
This patch appears not to be in 2.5.32, but applies cleanly.
serport/serio presently has several problems. This is by no means a definitive list (for example, the locking problems that hch reported back in 2.4.0-test time):
This patch should fix all four of them:
You can import this changeset into BK by piping this whole message to:
'| bk receive [path to repository]' or apply the patch as usual. 'bk pull bk://linux-input.bkbits.net/linux-input' should work as well.
===================================================================
[email protected], 2002-08-31 16:15:03+02:00, [email protected]
This fixes problems in serport.c found by Russell King:
1) Problem with current->state in serport_ldisc_read. Solved by using wait_event_interruptible()
2) Problem when serport_ldisc_read() is entered twice. Solved using set_bit et al.
3) Complex naming of the serio ports.
Using tty_name() instead.
4) Possible stack overflows in name generations. Using tty_name() instead.
char/tty_io.c | 2 + input/serio/serport.c | 77 ++++++++++++++------------------------------------ 2 files changed, 25 insertions(+), 54 deletions(-)
===================================================================
drivers/char/tty_io.c +2 -0
@@ -204,6 +204,8 @@return _tty_make_name (tty, (tty)?tty->driver.name:NULL , buf); } +EXPORT_SYMBOL (tty_name); +inline int tty_paranoia_check (struct tty_struct *tty,kdev_t device,const char *routine) {
drivers/input/serio/serport.c +23 -54
142 lines not on this page · raw message
===================================================================
This BitKeeper patch contains the following changesets:
+
## Wrapped with gzip_uu ##
begin 664 bkpatch64481 M'XL(`';/<#T``\U7^X_:1A#^V?M73!.E@H2'UT_,Z:HT!TE1TAR"NZJGID+& MK+&#\:+=-82(/[ZSAN.XZ[V52N6AP_;LS#<SWWR[]Q+.)1-M8\F_*A8EY"7\
MQJ5J&[*0K!%]Q^L!YWC=3/B<-7=6S?&LF>:+0A%\W@]5E,"2"=DV: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