lkml.org 
[lkml]   [2002]   [Sep]   [13]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
DateFri, 13 Sep 2002 11:04:53 +0200
FromVojtech Pavlik <>
SubjectMinor input fixes [1/7]
Hi!

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.
===================================================================
ChangeSet@1.568.2.2, 2002-08-31 16:15:03+02:00, vojtech@suse.cz
  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(-)
===================================================================
diff -Nru a/drivers/char/tty_io.c b/drivers/char/tty_io.c
--- a/drivers/char/tty_io.c	Thu Sep 12 23:37:14 2002
+++ b/drivers/char/tty_io.c	Thu Sep 12 23:37:14 2002
@@ -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)
 {
diff -Nru a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
--- a/drivers/input/serio/serport.c	Thu Sep 12 23:37:14 2002
+++ b/drivers/input/serio/serport.c	Thu Sep 12 23:37:14 2002
@@ -1,32 +1,16 @@
 /*
- * $Id: serport_old.c,v 1.10 2002/01/24 19:52:57 vojtech Exp $
+ * Input device TTY line discipline
+ *
+ * Copyright (c) 1999-2002 Vojtech Pavlik
  *
- *  Copyright (c) 1999-2001 Vojtech Pavlik
- */
-
-/*
  * This is a module that converts a tty line into a much simpler
  * 'serial io port' abstraction that the input device drivers use.
  */
 
 /*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or 
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * 
- *  Should you need to contact me, the author, you can do so either by
- * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
- * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
  */
 
 #include <asm/uaccess.h>
@@ -41,10 +25,13 @@
 MODULE_DESCRIPTION("Input device TTY line discipline");
 MODULE_LICENSE("GPL");
 
+#define SERPORT_BUSY	1
+
 struct serport {
 	struct tty_struct *tty;
 	wait_queue_head_t wait;
 	struct serio serio;
+	unsigned long flags;
 	char phys[32];
 };
 
@@ -68,20 +55,20 @@
 static void serport_serio_close(struct serio *serio)
 {
 	struct serport *serport = serio->driver;
+
+	serport->serio.type = 0;
 	wake_up_interruptible(&serport->wait);
 }
 
 /*
  * serport_ldisc_open() is the routine that is called upon setting our line
- * discipline on a tty. It looks for the Mag, and if found, registers
- * it as a joystick device.
+ * discipline on a tty. It prepares the serio struct.
  */
 
 static int serport_ldisc_open(struct tty_struct *tty)
 {
 	struct serport *serport;
-	char ttyname[64];
-	int i;
+	char name[64];
 
 	MOD_INC_USE_COUNT;
 
@@ -96,11 +83,7 @@
 	serport->tty = tty;
 	tty->disc_data = serport;
 
-	strcpy(ttyname, tty->driver.name);
-	for (i = 0; ttyname[i] != 0 && ttyname[i] != '/'; 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/serio0", tty_name(tty, name));
 
 	serport->serio.name = serport_name;
 	serport->serio.phys = serport->phys;
@@ -161,29 +144,18 @@
 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];
+	char name[64];
 
-#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
+	if (test_and_set_bit(SERPORT_BUSY, &serport->flags))
+		return -EBUSY;
 
 	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();
-
-	set_current_state(TASK_RUNNING);
-	remove_wait_queue(&serport->wait, &wait);
-
+	printk(KERN_INFO "serio: Serial port %s\n", tty_name(tty, name));
+	wait_event_interruptible(serport->wait, !serport->serio.type);
 	serio_unregister_port(&serport->serio);
 
+	clear_bit(SERPORT_BUSY, &serport->flags);
+
 	return 0;
 }
 
@@ -195,10 +167,8 @@
 {
 	struct serport *serport = (struct serport*) tty->disc_data;
 	
-	switch (cmd) {
-		case SPIOCSTYPE:
-			return get_user(serport->serio.type, (unsigned long *) arg);
-	}
+	if (cmd == SPIOCSTYPE)
+		return get_user(serport->serio.type, (unsigned long *) arg);
 
 	return -EINVAL;
 }
@@ -208,7 +178,6 @@
 	struct serport *sp = (struct serport *) tty->disc_data;
 
 	serio_dev_write_wakeup(&sp->serio);
-
 }
 
 /*
===================================================================
This BitKeeper patch contains the following changesets:
1.568.2.2
## Wrapped with gzip_uu ##


begin 664 bkpatch25155
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5=><@S^VU,63PC)+9Z3C@DLZU`$:
M8(36-D1).23;5(1SW;58,*P8C]4J%.P(UKR`*,P!&YE*)=)QH<F$_<HG#2Y@
MSB=IO,8;VA52DXFR6]AX9.ZN=1\^G\.'LM09](MQED;P"?/))2N/,UA^L"%$
M$/J93$HB:G?:]KU&,]RA@?>:_67#3-)S';#)RPF+=4F&W4'_='`V>G<^O#`H
M^8*/`ZRC4>0RG>;H$N=S"G$63N41Z046FGXAQJY/.".Z;:8^2L$Q6$>D$_BX
MHA=H'XCDJN"`8$/-#Q-Z"LO&%HA+'C`4:U1$RB2=IH;7:[H:A5:ZDG)_^>[?
MZ+W5`H_TJ.7HAS)?")RRN+)'LTC6L@8R_<[XC;O5&KQX);<LLU[4KHB*/VIE
MA&H5_5/?U<&I[]T6G?I!&3Z@N,A(8Z@H)M4(.SK:#63EL)PU^'F/H2Q@M4H,
M0S!5B!SJ7;U$.PTP4R0N;>K01IG2K/*Q._@\ZGU^?PHO2LQM&.(?Y(%V!Z_D
ME_S.)(P[16B/1J^HP4^W=!'M$8GNH1%E+!2/2.H("=&AK2:.2,^V]J6)YA/<
MT6#8[YV>#,\N^MV#Y*=8+=P41.46!#6H7.?>ZRJ$8JJ[8U/<8ZYMI-<."$_<
M0)]V1KEY@K_'%6Y6-G4\U\=+UPW*7=()GK!-_E<'^>ZWDCV7M,%)X3B`H=)B
M5&0XC5JO$`6JDHFJO3U@W:':U_)^AEHC533+NG^6S!I>_/[N]%/E$EG)J?T_
9:E'"HIDLYL<N'F'<8.R1?P"OK?>'%0X`````
`
end
-- 
Vojtech Pavlik
SuSE Labs
-
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/

\
 
 \ /
  Last update: 2005-03-22 12:28    [from the cache]
©2003-2008