[PATCH 0/6]
Subsystems (2)
cover [PATCH 0/6]
Hi Greg,
This patch series is part of the ongoing effort to cleanup and reduce the kernel tty interface; specifically removing undefined function declarations, unused macros, encapsulating global data, undefining unused exports, limiting functions and data to file scope, etc.
Regards,
Peter Hurley (6):
tty: Unexport system-wide tty_mutex
tty: Eliminate global symbol tty_ldisc_N_TTY
tty: Remove declarations to non-existent functions
tty: Move tty_check_change() helper
tty: Remove unreferenced tty flags macro TTY_DEBUG
tty: Make tty_files_lock per-tty
drivers/tty/n_tty.c | 18 ++++++++---------- drivers/tty/tty_io.c | 37 ++++++++++++++++++++----------------- drivers/tty/tty_ldisc.c | 6 ------ include/linux/tty.h | 10 ++-------- security/selinux/hooks.c | 4 ++-- 5 files changed, 32 insertions(+), 43 deletions(-)
Signature · 1 line
2.6.3
PATCH 1/6 tty: Unexport system-wide tty_mutex
tty_mutex is a core, system-wide lock; there is no reason for any code outside the tty core to have direct access.
--- drivers/tty/tty_io.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/tty/tty_io.c +1 -3
@@ -135,10 +135,8 @@ EXPORT_SYMBOL(tty_std_termios);LIST_HEAD (tty_drivers);/* linked list of tty drivers */ -/* Mutex to protect creating and releasing a tty. This is shared with -vt.c for deeply disgusting hack reasons */ +/* Mutex to protect creating and releasing a tty */ DEFINE_MUTEX (tty_mutex); -EXPORT_SYMBOL (tty_mutex);/* Spinlock to protect the tty->tty_files list */ DEFINE_SPINLOCK (tty_files_lock);
Signature · 1 line
2.6.3
PATCH 2/6 tty: Eliminate global symbol tty_ldisc_N_TTY
In reply to Peter HurleyReduce global tty symbols; move and rename tty_ldisc_begin() as n_tty_init() and redefine the N_TTY ldisc ops as file scope.
--- drivers/tty/n_tty.c | 12 ++++++++---- drivers/tty/tty_io.c | 2 +- drivers/tty/tty_ldisc.c | 6 ------ include/linux/tty.h | 3 +-- 4 files changed, 10 insertions(+), 13 deletions(-)
drivers/tty/n_tty.c +8 -4
@@ -2499,7 +2499,7 @@ static void n_tty_closing(struct tty_struct *tty) ldata->closing =1 ; } -struct tty_ldisc_ops tty_ldisc_N_TTY = { +static struct tty_ldisc_ops n_tty_ops = { .magic =TTY_LDISC_MAGIC , .name ="n_tty" , .open = n_tty_open,
@@ -2521,14 +2521,18 @@ struct tty_ldisc_ops tty_ldisc_N_TTY = {* n_tty_inherit_ops - inherit N_TTY methods * @ops: struct tty_ldisc_ops where to save N_TTY methods * -* Enables a 'subclass' line discipline to 'inherit' N_TTY -* methods. +* Enables a 'subclass' line discipline to 'inherit' N_TTY methods. */ void n_tty_inherit_ops (struct tty_ldisc_ops *ops) { - *ops = tty_ldisc_N_TTY; + *ops = n_tty_ops; ops->owner =NULL ; ops->refcount = ops->flags =0 ; }EXPORT_SYMBOL_GPL (n_tty_inherit_ops); + +void __init n_tty_init (void ) +{ +tty_register_ldisc (N_TTY , &n_tty_ops); +}
drivers/tty/tty_io.c +1 -1
@@ -3566,7 +3566,7 @@ void __init console_init(void)initcall_t *call;/* Setup the default TTY line discipline. */ -tty_ldisc_begin (); +n_tty_init ();/* * set up the console device so that later boot sequences can
drivers/tty/tty_ldisc.c +0 -6
@@ -840,9 +840,3 @@ void tty_ldisc_deinit(struct tty_struct *tty)tty_ldisc_put (tty->ldisc); tty->ldisc =NULL ; } - -void tty_ldisc_begin (void ) -{ -/* Setup the default TTY line discipline. */ - (void )tty_register_ldisc (N_TTY , &tty_ldisc_N_TTY); -}
include/linux/tty.h +1 -2
@@ -577,7 +577,6 @@ extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);extern void tty_ldisc_release (struct tty_struct *tty);extern void tty_ldisc_init (struct tty_struct *tty);extern void tty_ldisc_deinit (struct tty_struct *tty); -extern void tty_ldisc_begin (void );static inline int tty_ldisc_receive_buf (struct tty_ldisc *ld,unsigned char *p,char *f,int count)
@@ -594,8 +593,8 @@ static inline int tty_ldisc_receive_buf(struct tty_ldisc *ld, unsigned char *p,/* n_tty.c */ -extern struct tty_ldisc_ops tty_ldisc_N_TTY;extern void n_tty_inherit_ops (struct tty_ldisc_ops *ops); +extern void __init n_tty_init (void );/* tty_audit.c */ #ifdef CONFIG_AUDIT
Signature · 1 line
2.6.3
PATCH 3/6 tty: Remove declarations to non-existent functions
In reply to Peter Hurleytty_read_raw_data() and tty_signal() no longer exist; remove declarations.
--- include/linux/tty.h | 3 --- 1 file changed, 3 deletions(-)
include/linux/tty.h +0 -3
@@ -432,8 +432,6 @@ extern struct device *tty_register_device_attr(struct tty_driver *driver,void *drvdata, const struct attribute_group **attr_grp);extern void tty_unregister_device (struct tty_driver *driver,unsigned index); -extern int tty_read_raw_data (struct tty_struct *tty,unsigned char *bufp, -int buflen);extern void tty_write_message (struct tty_struct *tty,char *msg);extern int tty_send_xchar (struct tty_struct *tty,char ch);extern int tty_put_char (struct tty_struct *tty,unsigned char c);
@@ -447,7 +445,6 @@ extern int tty_unthrottle_safe(struct tty_struct *tty);extern int tty_do_resize (struct tty_struct *tty,struct winsize *ws);extern int is_current_pgrp_orphaned (void );extern int is_ignored (int sig); -extern int tty_signal (int sig,struct tty_struct *tty);extern void tty_hangup (struct tty_struct *tty);extern void tty_vhangup (struct tty_struct *tty);extern int tty_hung_up_p (struct file *filp);
Signature · 1 line
2.6.3
PATCH 4/6 tty: Move tty_check_change() helper
In reply to Peter HurleyMove is_ignored() to drivers/tty/tty_io.c and re-declare in file scope.
--- drivers/tty/n_tty.c | 6 ------ drivers/tty/tty_io.c | 6 ++++++ include/linux/tty.h | 1 - 3 files changed, 6 insertions(+), 7 deletions(-)
drivers/tty/n_tty.c +0 -6
@@ -1753,12 +1753,6 @@ static int n_tty_receive_buf2(struct tty_struct *tty, const unsigned char *cp,return n_tty_receive_buf_common (tty, cp, fp, count,1 ); } -int is_ignored (int sig) -{ -return (sigismember (¤t->blocked, sig) || - current->sighand->action[sig-1 ].sa.sa_handler ==SIG_IGN ); -} -/** * n_tty_set_termios - termios data changed * @tty: terminal
drivers/tty/tty_io.c +6 -0
@@ -381,6 +381,12 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line)EXPORT_SYMBOL_GPL (tty_find_polling_driver);#endif +static int is_ignored (int sig) +{ +return (sigismember (¤t->blocked, sig) || + current->sighand->action[sig-1 ].sa.sa_handler ==SIG_IGN ); +} +/** * tty_check_change - check for POSIX terminal changes * @tty: tty to check
include/linux/tty.h +0 -1
@@ -444,7 +444,6 @@ extern int tty_throttle_safe(struct tty_struct *tty);extern int tty_unthrottle_safe (struct tty_struct *tty);extern int tty_do_resize (struct tty_struct *tty,struct winsize *ws);extern int is_current_pgrp_orphaned (void ); -extern int is_ignored (int sig);extern void tty_hangup (struct tty_struct *tty);extern void tty_vhangup (struct tty_struct *tty);extern int tty_hung_up_p (struct file *filp);
Signature · 1 line
2.6.3
PATCH 5/6 tty: Remove unreferenced tty flags macro TTY_DEBUG
In reply to Peter HurleyThe TTY_DEBUG macro is not used; remove.
--- include/linux/tty.h | 1 - 1 file changed, 1 deletion(-)
include/linux/tty.h +0 -1
@@ -335,7 +335,6 @@ struct tty_file_private {#define TTY_IO_ERROR 1/* Cause an I/O error (may be no ldisc too) */ #define TTY_OTHER_CLOSED 2/* Other side (if any) has closed */ #define TTY_EXCLUSIVE 3/* Exclusive open mode */ -#define TTY_DEBUG 4/* Debugging */ #define TTY_DO_WRITE_WAKEUP 5/* Call write_wakeup after queuing new */ #define TTY_OTHER_DONE 6/* Closed pty has completed input processing */ #define TTY_LDISC_OPEN 11/* Line discipline is open */
Signature · 1 line
2.6.3
PATCH 6/6 tty: Make tty_files_lock per-tty
In reply to Peter HurleyAccess to tty->tty_files list is always per-tty, never for all ttys simultaneously. Replace global tty_files_lock spinlock with per-tty ->files_lock. Initialize when the ->tty_files list is inited, in alloc_tty_struct().
--- drivers/tty/tty_io.c | 25 ++++++++++++------------- include/linux/tty.h | 2 +- security/selinux/hooks.c | 4 ++-- 3 files changed, 15 insertions(+), 16 deletions(-)
drivers/tty/tty_io.c +12 -13
@@ -138,9 +138,6 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers *//* Mutex to protect creating and releasing a tty */ DEFINE_MUTEX (tty_mutex); -/* Spinlock to protect the tty->tty_files list */ -DEFINE_SPINLOCK (tty_files_lock); -static ssize_t tty_read (struct file *,char __user *,size_t ,loff_t *);static ssize_t tty_write (struct file *,const char __user *,size_t ,loff_t *); ssize_t redirected_tty_write(struct file *, const char __user *,
@@ -202,9 +199,9 @@ void tty_add_file(struct tty_struct *tty, struct file *file) priv->tty = tty; priv->file = file; -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);list_add (&priv->list, &tty->tty_files); -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock); }/**
@@ -225,10 +222,11 @@ void tty_free_file(struct file *file)static void tty_del_file (struct file *file) {struct tty_file_private *priv = file->private_data; +struct tty_struct *tty = priv->tty; -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);list_del (&priv->list); -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock);tty_free_file (file); }
@@ -286,11 +284,11 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)struct list_head *p;int count =0 ; -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);list_for_each (p, &tty->tty_files) { count++; } -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock);if (tty->driver->type ==TTY_DRIVER_TYPE_PTY && tty->driver->subtype ==PTY_TYPE_SLAVE && tty->link && tty->link->count)
@@ -713,7 +711,7 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)workqueue with the lock held */ check_tty_count (tty,"tty_hangup" ); -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);/* This breaks for file handles being sent over AF_UNIX sockets ? */ list_for_each_entry (priv, &tty->tty_files, list) { filp = priv->file;
@@ -725,7 +723,7 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)__tty_fasync (-1 , filp,0 );/* can't block */ filp->f_op = &hung_up_tty_fops; } -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock); refs =tty_signal_session_leader (tty, exit_session);/* Account for the p->signal references we killed */
@@ -1641,9 +1639,9 @@ static void release_one_tty(struct work_struct *work)tty_driver_kref_put (driver);module_put (owner); -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);list_del_init (&tty->tty_files); -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock);put_pid (tty->pgrp);put_pid (tty->session);
@@ -3166,6 +3164,7 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)mutex_init (&tty->atomic_write_lock);spin_lock_init (&tty->ctrl_lock);spin_lock_init (&tty->flow_lock); +spin_lock_init (&tty->files_lock);INIT_LIST_HEAD (&tty->tty_files);INIT_WORK (&tty->SAK_work, do_SAK_work);
include/linux/tty.h +1 -1
@@ -302,6 +302,7 @@ struct tty_struct {struct work_struct hangup_work;void *disc_data;void *driver_data; +spinlock_t files_lock;/* protects tty_files list */ struct list_head tty_files;#define N_TTY_BUF_SIZE 4096
@@ -509,7 +510,6 @@ extern int tty_standard_install(struct tty_driver *driver, struct tty_struct *tty);extern struct mutex tty_mutex; -extern spinlock_t tty_files_lock;#define tty_is_writelocked (tty) (mutex_is_locked(&tty->atomic_write_lock))
security/selinux/hooks.c +2 -2
@@ -2352,7 +2352,7 @@ static inline void flush_unauthorized_files(const struct cred *cred, tty =get_current_tty ();if (tty) { -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);if (!list_empty (&tty->tty_files)) {struct tty_file_private *file_priv;
@@ -2367,7 +2367,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,if (file_path_has_perm (cred, file,FILE__READ |FILE__WRITE )) drop_tty =1 ; } -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock);tty_kref_put (tty); }/* Reset controlling tty. */
Signature · 1 line
2.6.3
v2 cover tty globals cleanup (cont'd)
In reply to Peter HurleyChanges from v2: rebased on top of current tty-next
original message follows:
Hi Greg,
This patch series is part of the ongoing effort to cleanup and reduce the kernel tty interface; specifically removing undefined function declarations, unused macros, encapsulating global data, undefining unused exports, limiting functions and data to file scope, etc.
Regards,
Peter Hurley (6):
tty: Unexport system-wide tty_mutex
tty: Eliminate global symbol tty_ldisc_N_TTY
tty: Remove declarations to non-existent functions
tty: Move tty_check_change() helper
tty: Remove unreferenced tty flags macro TTY_DEBUG
tty: Make tty_files_lock per-tty
drivers/tty/n_tty.c | 18 ++++++++---------- drivers/tty/tty_io.c | 37 ++++++++++++++++++++----------------- drivers/tty/tty_ldisc.c | 6 ------ include/linux/tty.h | 10 ++-------- security/selinux/hooks.c | 4 ++-- 5 files changed, 32 insertions(+), 43 deletions(-)
Signature · 1 line
2.7.0
PATCH v2 1/6 tty: Unexport system-wide tty_mutex
tty_mutex is a core, system-wide lock; there is no reason for any code outside the tty core to have direct access.
--- drivers/tty/tty_io.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/tty/tty_io.c +1 -3
@@ -135,10 +135,8 @@ EXPORT_SYMBOL(tty_std_termios);LIST_HEAD (tty_drivers);/* linked list of tty drivers */ -/* Mutex to protect creating and releasing a tty. This is shared with -vt.c for deeply disgusting hack reasons */ +/* Mutex to protect creating and releasing a tty */ DEFINE_MUTEX (tty_mutex); -EXPORT_SYMBOL (tty_mutex);/* Spinlock to protect the tty->tty_files list */ DEFINE_SPINLOCK (tty_files_lock);
Signature · 1 line
2.7.0
PATCH v2 2/6 tty: Eliminate global symbol tty_ldisc_N_TTY
In reply to Peter HurleyReduce global tty symbols; move and rename tty_ldisc_begin() as n_tty_init() and redefine the N_TTY ldisc ops as file scope.
--- drivers/tty/n_tty.c | 12 ++++++++---- drivers/tty/tty_io.c | 2 +- drivers/tty/tty_ldisc.c | 6 ------ include/linux/tty.h | 3 +-- 4 files changed, 10 insertions(+), 13 deletions(-)
drivers/tty/n_tty.c +8 -4
@@ -2488,7 +2488,7 @@ static void n_tty_fasync(struct tty_struct *tty, int on) } } -struct tty_ldisc_ops tty_ldisc_N_TTY = { +static struct tty_ldisc_ops n_tty_ops = { .magic =TTY_LDISC_MAGIC , .name ="n_tty" , .open = n_tty_open,
@@ -2509,14 +2509,18 @@ struct tty_ldisc_ops tty_ldisc_N_TTY = {* n_tty_inherit_ops - inherit N_TTY methods * @ops: struct tty_ldisc_ops where to save N_TTY methods * -* Enables a 'subclass' line discipline to 'inherit' N_TTY -* methods. +* Enables a 'subclass' line discipline to 'inherit' N_TTY methods. */ void n_tty_inherit_ops (struct tty_ldisc_ops *ops) { - *ops = tty_ldisc_N_TTY; + *ops = n_tty_ops; ops->owner =NULL ; ops->refcount = ops->flags =0 ; }EXPORT_SYMBOL_GPL (n_tty_inherit_ops); + +void __init n_tty_init (void ) +{ +tty_register_ldisc (N_TTY , &n_tty_ops); +}
drivers/tty/tty_io.c +1 -1
@@ -3576,7 +3576,7 @@ void __init console_init(void)initcall_t *call;/* Setup the default TTY line discipline. */ -tty_ldisc_begin (); +n_tty_init ();/* * set up the console device so that later boot sequences can
drivers/tty/tty_ldisc.c +0 -6
@@ -824,9 +824,3 @@ void tty_ldisc_deinit(struct tty_struct *tty)tty_ldisc_put (tty->ldisc); tty->ldisc =NULL ; } - -void tty_ldisc_begin (void ) -{ -/* Setup the default TTY line discipline. */ - (void )tty_register_ldisc (N_TTY , &tty_ldisc_N_TTY); -}
include/linux/tty.h +1 -2
@@ -576,7 +576,6 @@ extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);extern void tty_ldisc_release (struct tty_struct *tty);extern void tty_ldisc_init (struct tty_struct *tty);extern void tty_ldisc_deinit (struct tty_struct *tty); -extern void tty_ldisc_begin (void );static inline int tty_ldisc_receive_buf (struct tty_ldisc *ld,unsigned char *p,char *f,int count)
@@ -593,8 +592,8 @@ static inline int tty_ldisc_receive_buf(struct tty_ldisc *ld, unsigned char *p,/* n_tty.c */ -extern struct tty_ldisc_ops tty_ldisc_N_TTY;extern void n_tty_inherit_ops (struct tty_ldisc_ops *ops); +extern void __init n_tty_init (void );/* tty_audit.c */ #ifdef CONFIG_AUDIT
Signature · 1 line
2.7.0
PATCH v2 3/6 tty: Remove declarations to non-existent functions
In reply to Peter Hurleytty_read_raw_data() and tty_signal() no longer exist; remove declarations.
--- include/linux/tty.h | 3 --- 1 file changed, 3 deletions(-)
include/linux/tty.h +0 -3
@@ -433,8 +433,6 @@ extern struct device *tty_register_device_attr(struct tty_driver *driver,void *drvdata, const struct attribute_group **attr_grp);extern void tty_unregister_device (struct tty_driver *driver,unsigned index); -extern int tty_read_raw_data (struct tty_struct *tty,unsigned char *bufp, -int buflen);extern void tty_write_message (struct tty_struct *tty,char *msg);extern int tty_send_xchar (struct tty_struct *tty,char ch);extern int tty_put_char (struct tty_struct *tty,unsigned char c);
@@ -448,7 +446,6 @@ extern int tty_unthrottle_safe(struct tty_struct *tty);extern int tty_do_resize (struct tty_struct *tty,struct winsize *ws);extern int is_current_pgrp_orphaned (void );extern int is_ignored (int sig); -extern int tty_signal (int sig,struct tty_struct *tty);extern void tty_hangup (struct tty_struct *tty);extern void tty_vhangup (struct tty_struct *tty);extern int tty_hung_up_p (struct file *filp);
Signature · 1 line
2.7.0
PATCH v2 4/6 tty: Move tty_check_change() helper
In reply to Peter HurleyMove is_ignored() to drivers/tty/tty_io.c and re-declare in file scope.
--- drivers/tty/n_tty.c | 6 ------ drivers/tty/tty_io.c | 6 ++++++ include/linux/tty.h | 1 - 3 files changed, 6 insertions(+), 7 deletions(-)
drivers/tty/n_tty.c +0 -6
@@ -1754,12 +1754,6 @@ static int n_tty_receive_buf2(struct tty_struct *tty, const unsigned char *cp,return n_tty_receive_buf_common (tty, cp, fp, count,1 ); } -int is_ignored (int sig) -{ -return (sigismember (¤t->blocked, sig) || - current->sighand->action[sig-1 ].sa.sa_handler ==SIG_IGN ); -} -/** * n_tty_set_termios - termios data changed * @tty: terminal
drivers/tty/tty_io.c +6 -0
@@ -381,6 +381,12 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line)EXPORT_SYMBOL_GPL (tty_find_polling_driver);#endif +static int is_ignored (int sig) +{ +return (sigismember (¤t->blocked, sig) || + current->sighand->action[sig-1 ].sa.sa_handler ==SIG_IGN ); +} +/** * tty_check_change - check for POSIX terminal changes * @tty: tty to check
include/linux/tty.h +0 -1
@@ -445,7 +445,6 @@ extern int tty_throttle_safe(struct tty_struct *tty);extern int tty_unthrottle_safe (struct tty_struct *tty);extern int tty_do_resize (struct tty_struct *tty,struct winsize *ws);extern int is_current_pgrp_orphaned (void ); -extern int is_ignored (int sig);extern void tty_hangup (struct tty_struct *tty);extern void tty_vhangup (struct tty_struct *tty);extern int tty_hung_up_p (struct file *filp);
Signature · 1 line
2.7.0
PATCH v2 5/6 tty: Remove unreferenced tty flags macro TTY_DEBUG
In reply to Peter HurleyThe TTY_DEBUG macro is not used; remove.
--- include/linux/tty.h | 1 - 1 file changed, 1 deletion(-)
include/linux/tty.h +0 -1
@@ -336,7 +336,6 @@ struct tty_file_private {#define TTY_IO_ERROR 1/* Cause an I/O error (may be no ldisc too) */ #define TTY_OTHER_CLOSED 2/* Other side (if any) has closed */ #define TTY_EXCLUSIVE 3/* Exclusive open mode */ -#define TTY_DEBUG 4/* Debugging */ #define TTY_DO_WRITE_WAKEUP 5/* Call write_wakeup after queuing new */ #define TTY_OTHER_DONE 6/* Closed pty has completed input processing */ #define TTY_LDISC_OPEN 11/* Line discipline is open */
Signature · 1 line
2.7.0
PATCH v2 6/6 tty: Make tty_files_lock per-tty
In reply to Peter HurleyAccess to tty->tty_files list is always per-tty, never for all ttys simultaneously. Replace global tty_files_lock spinlock with per-tty ->files_lock. Initialize when the ->tty_files list is inited, in alloc_tty_struct().
--- drivers/tty/tty_io.c | 25 ++++++++++++------------- include/linux/tty.h | 2 +- security/selinux/hooks.c | 4 ++-- 3 files changed, 15 insertions(+), 16 deletions(-)
drivers/tty/tty_io.c +12 -13
@@ -138,9 +138,6 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers *//* Mutex to protect creating and releasing a tty */ DEFINE_MUTEX (tty_mutex); -/* Spinlock to protect the tty->tty_files list */ -DEFINE_SPINLOCK (tty_files_lock); -static ssize_t tty_read (struct file *,char __user *,size_t ,loff_t *);static ssize_t tty_write (struct file *,const char __user *,size_t ,loff_t *); ssize_t redirected_tty_write(struct file *, const char __user *,
@@ -202,9 +199,9 @@ void tty_add_file(struct tty_struct *tty, struct file *file) priv->tty = tty; priv->file = file; -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);list_add (&priv->list, &tty->tty_files); -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock); }/**
@@ -225,10 +222,11 @@ void tty_free_file(struct file *file)static void tty_del_file (struct file *file) {struct tty_file_private *priv = file->private_data; +struct tty_struct *tty = priv->tty; -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);list_del (&priv->list); -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock);tty_free_file (file); }
@@ -286,11 +284,11 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)struct list_head *p;int count =0 ; -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);list_for_each (p, &tty->tty_files) { count++; } -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock);if (tty->driver->type ==TTY_DRIVER_TYPE_PTY && tty->driver->subtype ==PTY_TYPE_SLAVE && tty->link && tty->link->count)
@@ -713,7 +711,7 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)workqueue with the lock held */ check_tty_count (tty,"tty_hangup" ); -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);/* This breaks for file handles being sent over AF_UNIX sockets ? */ list_for_each_entry (priv, &tty->tty_files, list) { filp = priv->file;
@@ -725,7 +723,7 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)__tty_fasync (-1 , filp,0 );/* can't block */ filp->f_op = &hung_up_tty_fops; } -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock); refs =tty_signal_session_leader (tty, exit_session);/* Account for the p->signal references we killed */
@@ -1637,9 +1635,9 @@ static void release_one_tty(struct work_struct *work)tty_driver_kref_put (driver);module_put (owner); -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);list_del_init (&tty->tty_files); -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock);put_pid (tty->pgrp);put_pid (tty->session);
@@ -3176,6 +3174,7 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)mutex_init (&tty->atomic_write_lock);spin_lock_init (&tty->ctrl_lock);spin_lock_init (&tty->flow_lock); +spin_lock_init (&tty->files_lock);INIT_LIST_HEAD (&tty->tty_files);INIT_WORK (&tty->SAK_work, do_SAK_work);
include/linux/tty.h +1 -1
@@ -302,6 +302,7 @@ struct tty_struct {struct work_struct hangup_work;void *disc_data;void *driver_data; +spinlock_t files_lock;/* protects tty_files list */ struct list_head tty_files;#define N_TTY_BUF_SIZE 4096
@@ -508,7 +509,6 @@ extern int tty_standard_install(struct tty_driver *driver, struct tty_struct *tty);extern struct mutex tty_mutex; -extern spinlock_t tty_files_lock;#define tty_is_writelocked (tty) (mutex_is_locked(&tty->atomic_write_lock))
security/selinux/hooks.c +2 -2
@@ -2352,7 +2352,7 @@ static inline void flush_unauthorized_files(const struct cred *cred, tty =get_current_tty ();if (tty) { -spin_lock (&tty_files_lock); +spin_lock (&tty->files_lock);if (!list_empty (&tty->tty_files)) {struct tty_file_private *file_priv;
@@ -2367,7 +2367,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,if (file_path_has_perm (cred, file,FILE__READ |FILE__WRITE )) drop_tty =1 ; } -spin_unlock (&tty_files_lock); +spin_unlock (&tty->files_lock);tty_kref_put (tty); }/* Reset controlling tty. */
Signature · 1 line
2.7.0