From 0a083eddae33b6e20234d05a9cf54f87b0095511 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Sun, 8 Nov 2015 13:01:12 -0500 Subject: [PATCH] tty: core: Add helper fn to deref tty driver name Similar to tty_name(), add tty_driver_name() helper to safely dereference tty->driver->name (otherwise return empty string). Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman --- drivers/tty/tty_io.c | 7 +++++++ include/linux/tty.h | 1 + 2 files changed, 8 insertions(+) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 336714cf370a..ef8ee34670c3 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -256,6 +256,13 @@ const char *tty_name(const struct tty_struct *tty) EXPORT_SYMBOL(tty_name); +const char *tty_driver_name(const struct tty_struct *tty) +{ + if (!tty || !tty->driver) + return ""; + return tty->driver->name; +} + static int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, const char *routine) { diff --git a/include/linux/tty.h b/include/linux/tty.h index 0532465ea142..a9c1af990da9 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -420,6 +420,7 @@ static inline struct tty_struct *tty_kref_get(struct tty_struct *tty) } extern const char *tty_name(const struct tty_struct *tty); +extern const char *tty_driver_name(const struct tty_struct *tty); extern void tty_wait_until_sent(struct tty_struct *tty, long timeout); extern int __tty_check_change(struct tty_struct *tty, int sig); extern int tty_check_change(struct tty_struct *tty); -- 2.39.5