diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2014-02-09 20:59:04 -0500 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-02-14 16:39:29 -0500 |
commit | c0fdfb80382e4901473ce0e31d1e7833c1d297be (patch) | |
tree | d17f0af1f01f44f0ec3ba21169e18606845b95b1 /include/linux/tty.h | |
parent | f87c24e74e88d767e7024c4464d0d1fb3642fb5e (diff) |
tty: Fix ref counting for port krefs
The tty core supports two models for handling tty_port lifetimes;
the tty_port can use the kref supplied by tty_port (which will
automatically destruct the tty_port when the ref count drops to
zero) or it can destruct the tty_port manually.
For tty drivers that choose to use the port kref to manage the
tty_port lifetime, it is not possible to safely acquire a port
reference conditionally. If the last reference is released after
evaluating the condition but before acquiring the reference, a
bogus reference will be held while the tty_port destruction
commences.
Rather, only acquire a port reference if the ref count is non-zero
and allow the caller to distinguish if a reference has successfully
been acquired.
Cc: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-By: Alexander Holler <holler@ahsoftware.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'include/linux/tty.h')
-rw-r--r-- | include/linux/tty.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/include/linux/tty.h b/include/linux/tty.h index 90b4fdc8a61f..4781d7b27dd3 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h | |||
@@ -518,9 +518,9 @@ extern void tty_port_put(struct tty_port *port); | |||
518 | 518 | ||
519 | static inline struct tty_port *tty_port_get(struct tty_port *port) | 519 | static inline struct tty_port *tty_port_get(struct tty_port *port) |
520 | { | 520 | { |
521 | if (port) | 521 | if (port && kref_get_unless_zero(&port->kref)) |
522 | kref_get(&port->kref); | 522 | return port; |
523 | return port; | 523 | return NULL; |
524 | } | 524 | } |
525 | 525 | ||
526 | /* If the cts flow control is enabled, return true. */ | 526 | /* If the cts flow control is enabled, return true. */ |