Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: tty_port: Add a kref object to the tty port

Users of tty port need a way to refcount ports when hotplugging is
involved.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Alan Cox and committed by
Greg Kroah-Hartman
568aafc6 338818fd

+30
+18
drivers/char/tty_port.c
··· 29 29 spin_lock_init(&port->lock); 30 30 port->close_delay = (50 * HZ) / 100; 31 31 port->closing_wait = (3000 * HZ) / 100; 32 + kref_init(&port->kref); 32 33 } 33 34 EXPORT_SYMBOL(tty_port_init); 34 35 ··· 57 56 } 58 57 EXPORT_SYMBOL(tty_port_free_xmit_buf); 59 58 59 + static void tty_port_destructor(struct kref *kref) 60 + { 61 + struct tty_port *port = container_of(kref, struct tty_port, kref); 62 + if (port->xmit_buf) 63 + free_page((unsigned long)port->xmit_buf); 64 + if (port->ops->destruct) 65 + port->ops->destruct(port); 66 + else 67 + kfree(port); 68 + } 69 + 70 + void tty_port_put(struct tty_port *port) 71 + { 72 + if (port) 73 + kref_put(&port->kref, tty_port_destructor); 74 + } 75 + EXPORT_SYMBOL(tty_port_put); 60 76 61 77 /** 62 78 * tty_port_tty_get - get a tty reference
+12
include/linux/tty.h
··· 199 199 /* FIXME: long term getting the tty argument *out* of this would be 200 200 good for consoles */ 201 201 int (*activate)(struct tty_port *port, struct tty_struct *tty); 202 + /* Called on the final put of a port */ 203 + void (*destruct)(struct tty_port *port); 202 204 }; 203 205 204 206 struct tty_port { ··· 221 219 int drain_delay; /* Set to zero if no pure time 222 220 based drain is needed else 223 221 set to size of fifo */ 222 + struct kref kref; /* Ref counter */ 224 223 }; 225 224 226 225 /* ··· 464 461 extern void tty_port_init(struct tty_port *port); 465 462 extern int tty_port_alloc_xmit_buf(struct tty_port *port); 466 463 extern void tty_port_free_xmit_buf(struct tty_port *port); 464 + extern void tty_port_put(struct tty_port *port); 465 + 466 + extern inline struct tty_port *tty_port_get(struct tty_port *port) 467 + { 468 + if (port) 469 + kref_get(&port->kref); 470 + return port; 471 + } 472 + 467 473 extern struct tty_struct *tty_port_tty_get(struct tty_port *port); 468 474 extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty); 469 475 extern int tty_port_carrier_raised(struct tty_port *port);