@@ -138,9 +138,6 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */
138
138
/* Mutex to protect creating and releasing a tty */
139
139
DEFINE_MUTEX (tty_mutex );
140
140
141
- /* Spinlock to protect the tty->tty_files list */
142
- DEFINE_SPINLOCK (tty_files_lock );
143
-
144
141
static ssize_t tty_read (struct file * , char __user * , size_t , loff_t * );
145
142
static ssize_t tty_write (struct file * , const char __user * , size_t , loff_t * );
146
143
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)
202
199
priv -> tty = tty ;
203
200
priv -> file = file ;
204
201
205
- spin_lock (& tty_files_lock );
202
+ spin_lock (& tty -> files_lock );
206
203
list_add (& priv -> list , & tty -> tty_files );
207
- spin_unlock (& tty_files_lock );
204
+ spin_unlock (& tty -> files_lock );
208
205
}
209
206
210
207
/**
@@ -225,10 +222,11 @@ void tty_free_file(struct file *file)
225
222
static void tty_del_file (struct file * file )
226
223
{
227
224
struct tty_file_private * priv = file -> private_data ;
225
+ struct tty_struct * tty = priv -> tty ;
228
226
229
- spin_lock (& tty_files_lock );
227
+ spin_lock (& tty -> files_lock );
230
228
list_del (& priv -> list );
231
- spin_unlock (& tty_files_lock );
229
+ spin_unlock (& tty -> files_lock );
232
230
tty_free_file (file );
233
231
}
234
232
@@ -286,11 +284,11 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
286
284
struct list_head * p ;
287
285
int count = 0 ;
288
286
289
- spin_lock (& tty_files_lock );
287
+ spin_lock (& tty -> files_lock );
290
288
list_for_each (p , & tty -> tty_files ) {
291
289
count ++ ;
292
290
}
293
- spin_unlock (& tty_files_lock );
291
+ spin_unlock (& tty -> files_lock );
294
292
if (tty -> driver -> type == TTY_DRIVER_TYPE_PTY &&
295
293
tty -> driver -> subtype == PTY_TYPE_SLAVE &&
296
294
tty -> link && tty -> link -> count )
@@ -713,7 +711,7 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
713
711
workqueue with the lock held */
714
712
check_tty_count (tty , "tty_hangup" );
715
713
716
- spin_lock (& tty_files_lock );
714
+ spin_lock (& tty -> files_lock );
717
715
/* This breaks for file handles being sent over AF_UNIX sockets ? */
718
716
list_for_each_entry (priv , & tty -> tty_files , list ) {
719
717
filp = priv -> file ;
@@ -725,7 +723,7 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
725
723
__tty_fasync (-1 , filp , 0 ); /* can't block */
726
724
filp -> f_op = & hung_up_tty_fops ;
727
725
}
728
- spin_unlock (& tty_files_lock );
726
+ spin_unlock (& tty -> files_lock );
729
727
730
728
refs = tty_signal_session_leader (tty , exit_session );
731
729
/* Account for the p->signal references we killed */
@@ -1637,9 +1635,9 @@ static void release_one_tty(struct work_struct *work)
1637
1635
tty_driver_kref_put (driver );
1638
1636
module_put (owner );
1639
1637
1640
- spin_lock (& tty_files_lock );
1638
+ spin_lock (& tty -> files_lock );
1641
1639
list_del_init (& tty -> tty_files );
1642
- spin_unlock (& tty_files_lock );
1640
+ spin_unlock (& tty -> files_lock );
1643
1641
1644
1642
put_pid (tty -> pgrp );
1645
1643
put_pid (tty -> session );
@@ -3176,6 +3174,7 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)
3176
3174
mutex_init (& tty -> atomic_write_lock );
3177
3175
spin_lock_init (& tty -> ctrl_lock );
3178
3176
spin_lock_init (& tty -> flow_lock );
3177
+ spin_lock_init (& tty -> files_lock );
3179
3178
INIT_LIST_HEAD (& tty -> tty_files );
3180
3179
INIT_WORK (& tty -> SAK_work , do_SAK_work );
3181
3180
0 commit comments