aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2012-11-15 03:49:54 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-11-15 20:20:58 -0500
commitde274bfe0fc81def6ddb8a17020a9a4b56477cc4 (patch)
treefb2aeacdb9fc1e94b5aa13beb6a4818c043b43d3
parent9a8e62bc68832dc55a5e6868f812b65567fe66b5 (diff)
TTY: introduce tty_port_destroy
After commit "TTY: move tty buffers to tty_port", the tty buffers are not freed in some drivers. This is because tty_port_destructor is not called whenever a tty_port is freed. This was an assumption I counted with but was unfortunately untrue. Those using refcounting are safe now, but for those which do not we introduce a function to be called right before the tty_port is freed by the drivers. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/tty/tty_port.c16
-rw-r--r--include/linux/tty.h1
2 files changed, 16 insertions, 1 deletions
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index fdc42c2d565f..b7ff59d3db88 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -122,12 +122,26 @@ void tty_port_free_xmit_buf(struct tty_port *port)
122} 122}
123EXPORT_SYMBOL(tty_port_free_xmit_buf); 123EXPORT_SYMBOL(tty_port_free_xmit_buf);
124 124
125/**
126 * tty_port_destroy -- destroy inited port
127 * @port: tty port to be doestroyed
128 *
129 * When a port was initialized using tty_port_init, one has to destroy the
130 * port by this function. Either indirectly by using tty_port refcounting
131 * (tty_port_put) or directly if refcounting is not used.
132 */
133void tty_port_destroy(struct tty_port *port)
134{
135 tty_buffer_free_all(port);
136}
137EXPORT_SYMBOL(tty_port_destroy);
138
125static void tty_port_destructor(struct kref *kref) 139static void tty_port_destructor(struct kref *kref)
126{ 140{
127 struct tty_port *port = container_of(kref, struct tty_port, kref); 141 struct tty_port *port = container_of(kref, struct tty_port, kref);
128 if (port->xmit_buf) 142 if (port->xmit_buf)
129 free_page((unsigned long)port->xmit_buf); 143 free_page((unsigned long)port->xmit_buf);
130 tty_buffer_free_all(port); 144 tty_port_destroy(port);
131 if (port->ops && port->ops->destruct) 145 if (port->ops && port->ops->destruct)
132 port->ops->destruct(port); 146 port->ops->destruct(port);
133 else 147 else
diff --git a/include/linux/tty.h b/include/linux/tty.h
index d7ff88fb8967..8db1b569c37a 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -455,6 +455,7 @@ extern struct device *tty_port_register_device_attr(struct tty_port *port,
455 const struct attribute_group **attr_grp); 455 const struct attribute_group **attr_grp);
456extern int tty_port_alloc_xmit_buf(struct tty_port *port); 456extern int tty_port_alloc_xmit_buf(struct tty_port *port);
457extern void tty_port_free_xmit_buf(struct tty_port *port); 457extern void tty_port_free_xmit_buf(struct tty_port *port);
458extern void tty_port_destroy(struct tty_port *port);
458extern void tty_port_put(struct tty_port *port); 459extern void tty_port_put(struct tty_port *port);
459 460
460static inline struct tty_port *tty_port_get(struct tty_port *port) 461static inline struct tty_port *tty_port_get(struct tty_port *port)