linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] add module reference to struct tty_driver
@ 2003-01-13  5:47 Greg KH
  2003-01-13  9:27 ` Russell King
  2003-01-14 20:07 ` Russell King
  0 siblings, 2 replies; 14+ messages in thread
From: Greg KH @ 2003-01-13  5:47 UTC (permalink / raw)
  To: linux-kernel

In digging into the tty layer locking, I noticed that the tty layer
doesn't handle module reference counting for any tty drivers.  Well, I've
known this for a long time, just finally got around to fixing it :)
Here's a patch against 2.5.56 that should fix this issue (works for
me...)

Comments?  If no one objects, I'll send it on to Linus, and add support
for this to a number of tty drivers that commonly get built as modules.

thanks,

greg k-h


# TTY: add module reference counting for tty drivers.

diff -Nru a/drivers/char/tty_io.c b/drivers/char/tty_io.c
--- a/drivers/char/tty_io.c	Sun Jan 12 21:46:53 2003
+++ b/drivers/char/tty_io.c	Sun Jan 12 21:46:53 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	Sun Jan 12 21:46:53 2003
+++ b/include/linux/tty_driver.h	Sun Jan 12 21:46:53 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] 14+ messages in thread

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

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-13  5:47 [RFC] add module reference to struct tty_driver Greg KH
2003-01-13  9:27 ` Russell King
2003-01-13 17:12   ` Greg KH
2003-01-13 19:51   ` Max Krasnyansky
2003-01-14 20:07 ` Russell King
2003-01-14 22:08   ` Greg KH
2003-01-15 10:00     ` Russell King
2003-01-15  9:09       ` Henrique Gobbi
2003-01-15 10:30       ` John Bradford
2003-01-15 10:40         ` Russell King
2003-01-15 11:12           ` John Bradford
2003-01-15 16:03           ` Randy.Dunlap
2003-01-15 15:26       ` Kai Germaschewski
2003-01-15 16:31       ` Roman Zippel

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).