tty: add tty_struct->dev pointer to corresponding device instance
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Mon, 9 Aug 2010 14:22:49 +0000 (18:22 +0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 22 Oct 2010 17:19:56 +0000 (10:19 -0700)
Some device drivers (mostly tty line disciplines) would like to have way
know a struct device instance corresponding to passed tty_struct. Add
a struct device pointer to struct tty_struct and populate it during
initialize_tty_struct().

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/char/tty_io.c
include/linux/tty.h

index 613c852ee0feced279c50f6850e9e30c7c870111..dc184d4b5638ef53403e59e429a570acfa4c2f64 100644 (file)
@@ -183,6 +183,8 @@ struct tty_struct *alloc_tty_struct(void)
 
 void free_tty_struct(struct tty_struct *tty)
 {
+       if (tty->dev)
+               put_device(tty->dev);
        kfree(tty->write_buf);
        tty_buffer_free_all(tty);
        kfree(tty);
@@ -2783,6 +2785,20 @@ void do_SAK(struct tty_struct *tty)
 
 EXPORT_SYMBOL(do_SAK);
 
+static int dev_match_devt(struct device *dev, void *data)
+{
+       dev_t *devt = data;
+       return dev->devt == *devt;
+}
+
+/* Must put_device() after it's unused! */
+static struct device *tty_get_device(struct tty_struct *tty)
+{
+       dev_t devt = tty_devnum(tty);
+       return class_find_device(tty_class, NULL, &devt, dev_match_devt);
+}
+
+
 /**
  *     initialize_tty_struct
  *     @tty: tty to initialize
@@ -2823,6 +2839,7 @@ void initialize_tty_struct(struct tty_struct *tty,
        tty->ops = driver->ops;
        tty->index = idx;
        tty_line_name(driver, idx, tty->name);
+       tty->dev = tty_get_device(tty);
 }
 
 /**
index 67d64e6efe7a8c95d775b6418d2c1c8d728d667d..d94eb86266c4259a08f9f5ab6f1592b4c212f146 100644 (file)
@@ -256,6 +256,7 @@ struct tty_operations;
 struct tty_struct {
        int     magic;
        struct kref kref;
+       struct device *dev;
        struct tty_driver *driver;
        const struct tty_operations *ops;
        int index;