linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BK PATCH] TTY changes for 2.5.58
@ 2003-01-15  1:13 Greg KH
  2003-01-15  1:14 ` [PATCH] " Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2003-01-15  1:13 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel

Here are some minor tty patches.  They add a struct module to the
tty_driver structure and then increment and decrement the driver's
reference when the tty device assigned to that driver is in use.  This
is much like other subsystems do.

This patch was posted to lkml and no one objected to it.

I've also included a patch that adds this support to the tty drivers in
the drivers/usb/ directory.

Please pull from:
        bk://kernel.bkbits.net/gregkh/linux/tty-2.5

thanks,

greg k-h


 drivers/char/tty_io.c           |    7 +++++++
 drivers/usb/class/bluetty.c     |    7 +------
 drivers/usb/class/cdc-acm.c     |    4 +---
 drivers/usb/serial/usb-serial.c |    1 +
 include/linux/tty_driver.h      |    1 +
 5 files changed, 11 insertions(+), 9 deletions(-)
-----

ChangeSet@1.1026, 2003-01-14 16:57:38-08:00, greg@kroah.com
  TTY: Added .owner for tty drivers in the drivers/usb/ directory

 drivers/usb/class/bluetty.c     |    7 +------
 drivers/usb/class/cdc-acm.c     |    4 +---
 drivers/usb/serial/usb-serial.c |    1 +
 3 files changed, 3 insertions(+), 9 deletions(-)
------

ChangeSet@1.1025, 2003-01-14 16:51:58-08:00, greg@kroah.com
  TTY: add module reference counting for tty drivers.
  
  Note, there are still races with unloading modules, this patch
  does not fix that...

 drivers/char/tty_io.c      |    7 +++++++
 include/linux/tty_driver.h |    1 +
 2 files changed, 8 insertions(+)
------


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] TTY changes for 2.5.58
  2003-01-15  1:13 [BK PATCH] TTY changes for 2.5.58 Greg KH
@ 2003-01-15  1:14 ` Greg KH
  2003-01-15  1:14   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2003-01-15  1:14 UTC (permalink / raw)
  To: linux-kernel

ChangeSet 1.1025, 2003/01/14 16:51:58-08:00, greg@kroah.com

TTY: add module reference counting for tty drivers.

Note, there are still races with unloading modules, this patch
does not fix that...


diff -Nru a/drivers/char/tty_io.c b/drivers/char/tty_io.c
--- a/drivers/char/tty_io.c	Tue Jan 14 17:07:05 2003
+++ b/drivers/char/tty_io.c	Tue Jan 14 17:07:05 2003
@@ -833,6 +833,11 @@
 	 * and locked termios may be retained.)
 	 */
 
+	if (!try_module_get(driver->owner)) {
+		retval = -ENODEV;
+		goto end_init;
+	}
+
 	o_tty = NULL;
 	tp = o_tp = NULL;
 	ltp = o_ltp = NULL;
@@ -991,6 +996,7 @@
 	free_tty_struct(tty);
 
 fail_no_mem:
+	module_put(driver->owner);
 	retval = -ENOMEM;
 	goto end_init;
 
@@ -1033,6 +1039,7 @@
 	tty->magic = 0;
 	(*tty->driver.refcount)--;
 	list_del(&tty->tty_files);
+	module_put(tty->driver.owner);
 	free_tty_struct(tty);
 }
 
diff -Nru a/include/linux/tty_driver.h b/include/linux/tty_driver.h
--- a/include/linux/tty_driver.h	Tue Jan 14 17:07:05 2003
+++ b/include/linux/tty_driver.h	Tue Jan 14 17:07:05 2003
@@ -120,6 +120,7 @@
 
 struct tty_driver {
 	int	magic;		/* magic number for this structure */
+	struct module	*owner;
 	const char	*driver_name;
 	const char	*name;
 	int	name_base;	/* offset of printed name */

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] TTY changes for 2.5.58
  2003-01-15  1:14 ` [PATCH] " Greg KH
@ 2003-01-15  1:14   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2003-01-15  1:14 UTC (permalink / raw)
  To: linux-kernel

ChangeSet 1.1026, 2003/01/14 16:57:38-08:00, greg@kroah.com

TTY: Added .owner for tty drivers in the drivers/usb/ directory


diff -Nru a/drivers/usb/class/bluetty.c b/drivers/usb/class/bluetty.c
--- a/drivers/usb/class/bluetty.c	Tue Jan 14 17:07:00 2003
+++ b/drivers/usb/class/bluetty.c	Tue Jan 14 17:07:00 2003
@@ -1107,20 +1107,17 @@
 		return -EIO;
 	}
 
-	MOD_INC_USE_COUNT;
 	info("USB Bluetooth converter detected");
 
 	for (minor = 0; minor < BLUETOOTH_TTY_MINORS && bluetooth_table[minor]; ++minor)
 		;
 	if (bluetooth_table[minor]) {
 		err("No more free Bluetooth devices");
-		MOD_DEC_USE_COUNT;
 		return -ENODEV;
 	}
 
 	if (!(bluetooth = kmalloc(sizeof(struct usb_bluetooth), GFP_KERNEL))) {
 		err("Out of memory");
-		MOD_DEC_USE_COUNT;
 		return -ENOMEM;
 	}
 
@@ -1236,7 +1233,6 @@
 
 	/* free up any memory that we allocated */
 	kfree (bluetooth);
-	MOD_DEC_USE_COUNT;
 	return -EIO;
 }
 
@@ -1295,13 +1291,12 @@
 	} else {
 		info("device disconnected");
 	}
-
-	MOD_DEC_USE_COUNT;
 }
 
 
 static struct tty_driver bluetooth_tty_driver = {
 	.magic =		TTY_DRIVER_MAGIC,
+	.owner =		THIS_MODULE,
 	.driver_name =		"usb-bluetooth",
 	.name =			"usb/ttub/%d",
 	.major =		BLUETOOTH_TTY_MAJOR,
diff -Nru a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
--- a/drivers/usb/class/cdc-acm.c	Tue Jan 14 17:07:00 2003
+++ b/drivers/usb/class/cdc-acm.c	Tue Jan 14 17:07:00 2003
@@ -320,8 +320,6 @@
 	tty->driver_data = acm;
 	acm->tty = tty;
 
-	MOD_INC_USE_COUNT;
-
         lock_kernel();
 
 	if (acm->used++) {
@@ -369,7 +367,6 @@
 			kfree(acm);
 		}
 	}
-	MOD_DEC_USE_COUNT;
 }
 
 static int acm_tty_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
@@ -724,6 +721,7 @@
 
 static struct tty_driver acm_tty_driver = {
 	.magic =		TTY_DRIVER_MAGIC,
+	.owner =		THIS_MODULE,
 	.driver_name =		"acm",
 	.name =			"usb/acm/%d",
 	.major =		ACM_TTY_MAJOR,
diff -Nru a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
--- a/drivers/usb/serial/usb-serial.c	Tue Jan 14 17:07:00 2003
+++ b/drivers/usb/serial/usb-serial.c	Tue Jan 14 17:07:00 2003
@@ -1257,6 +1257,7 @@
 
 struct tty_driver usb_serial_tty_driver = {
 	.magic =		TTY_DRIVER_MAGIC,
+	.owner =		THIS_MODULE,
 	.driver_name =		"usbserial",
 #ifndef CONFIG_DEVFS_FS
 	.name =			"ttyUSB",

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-01-15  1:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-15  1:13 [BK PATCH] TTY changes for 2.5.58 Greg KH
2003-01-15  1:14 ` [PATCH] " Greg KH
2003-01-15  1:14   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).