Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S377083AbdD2Tyf (ORCPT ); Sat, 29 Apr 2017 15:54:35 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:36518 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S377040AbdD2TyH (ORCPT ); Sat, 29 Apr 2017 15:54:07 -0400 Message-Id: <20170429195403.522579504@gmail.com> User-Agent: quilt/0.65 Date: Sat, 29 Apr 2017 20:52:59 +0100 From: Okash Khawaja To: Greg Kroah-Hartman , Jiri Slaby , Samuel Thibault , linux-kernel@vger.kernel.org Cc: William Hubbs , Chris Brannon , Kirk Reiser , speakup@linux-speakup.org, devel@driverdev.osuosl.org Subject: [patch 2/6] tty: export tty_open_by_driver References: <20170429195257.630355823@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Disposition: inline; filename=02_export_tty_open_by_driver Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2094 Lines: 61 This applies on top of the changes already in staging-next branch which allow kernel access to TTY dev. Signe-doff-by: Okash Khawaja Reviewed-by: Samuel Thibault Index: linux-staging/drivers/tty/tty_io.c =================================================================== --- linux-staging.orig/drivers/tty/tty_io.c +++ linux-staging/drivers/tty/tty_io.c @@ -1369,7 +1369,10 @@ static struct tty_struct *tty_driver_loo struct tty_struct *tty; if (driver->ops->lookup) - tty = driver->ops->lookup(driver, file, idx); + if (!file) + tty = ERR_PTR(-EIO); + else + tty = driver->ops->lookup(driver, file, idx); else tty = driver->ttys[idx]; @@ -2001,7 +2004,7 @@ static struct tty_driver *tty_lookup_dri struct tty_driver *console_driver = console_device(index); if (console_driver) { driver = tty_driver_kref_get(console_driver); - if (driver) { + if (driver && filp) { /* Don't let /dev/console block */ filp->f_flags |= O_NONBLOCK; break; @@ -2034,7 +2037,7 @@ static struct tty_driver *tty_lookup_dri * - concurrent tty driver removal w/ lookup * - concurrent tty removal from driver table */ -static struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode, +struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode, struct file *filp) { struct tty_struct *tty; @@ -2079,6 +2082,7 @@ out: tty_driver_kref_put(driver); return tty; } +EXPORT_SYMBOL(tty_open_by_driver); /** * tty_open - open a tty device Index: linux-staging/include/linux/tty.h =================================================================== --- linux-staging.orig/include/linux/tty.h +++ linux-staging/include/linux/tty.h @@ -401,6 +401,8 @@ extern struct tty_struct *get_current_tt /* tty_io.c */ extern int __init tty_init(void); extern const char *tty_name(const struct tty_struct *tty); +extern struct tty_struct *tty_open_by_driver(dev_t device, struct inode *inode, + struct file *filp); #else static inline void console_init(void) { }