27
27
* Locking: none
28
28
*/
29
29
30
- void tty_buffer_free_all (struct tty_struct * tty )
30
+ void tty_buffer_free_all (struct tty_port * port )
31
31
{
32
- struct tty_bufhead * buf = & tty -> buf ;
32
+ struct tty_bufhead * buf = & port -> buf ;
33
33
struct tty_buffer * thead ;
34
34
35
35
while ((thead = buf -> head ) != NULL ) {
@@ -56,11 +56,11 @@ void tty_buffer_free_all(struct tty_struct *tty)
56
56
* Locking: Caller must hold tty->buf.lock
57
57
*/
58
58
59
- static struct tty_buffer * tty_buffer_alloc (struct tty_struct * tty , size_t size )
59
+ static struct tty_buffer * tty_buffer_alloc (struct tty_port * port , size_t size )
60
60
{
61
61
struct tty_buffer * p ;
62
62
63
- if (tty -> buf .memory_used + size > 65536 )
63
+ if (port -> buf .memory_used + size > 65536 )
64
64
return NULL ;
65
65
p = kmalloc (sizeof (struct tty_buffer ) + 2 * size , GFP_ATOMIC );
66
66
if (p == NULL )
@@ -72,7 +72,7 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
72
72
p -> read = 0 ;
73
73
p -> char_buf_ptr = (char * )(p -> data );
74
74
p -> flag_buf_ptr = (unsigned char * )p -> char_buf_ptr + size ;
75
- tty -> buf .memory_used += size ;
75
+ port -> buf .memory_used += size ;
76
76
return p ;
77
77
}
78
78
@@ -87,9 +87,9 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
87
87
* Locking: Caller must hold tty->buf.lock
88
88
*/
89
89
90
- static void tty_buffer_free (struct tty_struct * tty , struct tty_buffer * b )
90
+ static void tty_buffer_free (struct tty_port * port , struct tty_buffer * b )
91
91
{
92
- struct tty_bufhead * buf = & tty -> buf ;
92
+ struct tty_bufhead * buf = & port -> buf ;
93
93
94
94
/* Dumb strategy for now - should keep some stats */
95
95
buf -> memory_used -= b -> size ;
@@ -114,14 +114,14 @@ static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
114
114
* Locking: Caller must hold tty->buf.lock
115
115
*/
116
116
117
- static void __tty_buffer_flush (struct tty_struct * tty )
117
+ static void __tty_buffer_flush (struct tty_port * port )
118
118
{
119
- struct tty_bufhead * buf = & tty -> buf ;
119
+ struct tty_bufhead * buf = & port -> buf ;
120
120
struct tty_buffer * thead ;
121
121
122
122
while ((thead = buf -> head ) != NULL ) {
123
123
buf -> head = thead -> next ;
124
- tty_buffer_free (tty , thead );
124
+ tty_buffer_free (port , thead );
125
125
}
126
126
buf -> tail = NULL ;
127
127
}
@@ -140,7 +140,7 @@ static void __tty_buffer_flush(struct tty_struct *tty)
140
140
void tty_buffer_flush (struct tty_struct * tty )
141
141
{
142
142
struct tty_port * port = tty -> port ;
143
- struct tty_bufhead * buf = & tty -> buf ;
143
+ struct tty_bufhead * buf = & port -> buf ;
144
144
unsigned long flags ;
145
145
146
146
spin_lock_irqsave (& buf -> lock , flags );
@@ -155,7 +155,7 @@ void tty_buffer_flush(struct tty_struct *tty)
155
155
test_bit (TTYP_FLUSHPENDING , & port -> iflags ) == 0 );
156
156
return ;
157
157
} else
158
- __tty_buffer_flush (tty );
158
+ __tty_buffer_flush (port );
159
159
spin_unlock_irqrestore (& buf -> lock , flags );
160
160
}
161
161
@@ -171,9 +171,9 @@ void tty_buffer_flush(struct tty_struct *tty)
171
171
* Locking: Caller must hold tty->buf.lock
172
172
*/
173
173
174
- static struct tty_buffer * tty_buffer_find (struct tty_struct * tty , size_t size )
174
+ static struct tty_buffer * tty_buffer_find (struct tty_port * port , size_t size )
175
175
{
176
- struct tty_buffer * * tbh = & tty -> buf .free ;
176
+ struct tty_buffer * * tbh = & port -> buf .free ;
177
177
while ((* tbh ) != NULL ) {
178
178
struct tty_buffer * t = * tbh ;
179
179
if (t -> size >= size ) {
@@ -182,14 +182,14 @@ static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
182
182
t -> used = 0 ;
183
183
t -> commit = 0 ;
184
184
t -> read = 0 ;
185
- tty -> buf .memory_used += t -> size ;
185
+ port -> buf .memory_used += t -> size ;
186
186
return t ;
187
187
}
188
188
tbh = & ((* tbh )-> next );
189
189
}
190
190
/* Round the buffer size out */
191
191
size = (size + 0xFF ) & ~0xFF ;
192
- return tty_buffer_alloc (tty , size );
192
+ return tty_buffer_alloc (port , size );
193
193
/* Should possibly check if this fails for the largest buffer we
194
194
have queued and recycle that ? */
195
195
}
@@ -200,11 +200,11 @@ static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
200
200
*
201
201
* Make at least size bytes of linear space available for the tty
202
202
* buffer. If we fail return the size we managed to find.
203
- * Locking: Caller must hold tty ->buf.lock
203
+ * Locking: Caller must hold port ->buf.lock
204
204
*/
205
- static int __tty_buffer_request_room (struct tty_struct * tty , size_t size )
205
+ static int __tty_buffer_request_room (struct tty_port * port , size_t size )
206
206
{
207
- struct tty_bufhead * buf = & tty -> buf ;
207
+ struct tty_bufhead * buf = & port -> buf ;
208
208
struct tty_buffer * b , * n ;
209
209
int left ;
210
210
/* OPTIMISATION: We could keep a per tty "zero" sized buffer to
@@ -218,7 +218,7 @@ static int __tty_buffer_request_room(struct tty_struct *tty, size_t size)
218
218
219
219
if (left < size ) {
220
220
/* This is the slow path - looking for new buffers to use */
221
- if ((n = tty_buffer_find (tty , size )) != NULL ) {
221
+ if ((n = tty_buffer_find (port , size )) != NULL ) {
222
222
if (b != NULL ) {
223
223
b -> next = n ;
224
224
b -> commit = b -> used ;
@@ -241,16 +241,17 @@ static int __tty_buffer_request_room(struct tty_struct *tty, size_t size)
241
241
* Make at least size bytes of linear space available for the tty
242
242
* buffer. If we fail return the size we managed to find.
243
243
*
244
- * Locking: Takes tty ->buf.lock
244
+ * Locking: Takes port ->buf.lock
245
245
*/
246
246
int tty_buffer_request_room (struct tty_struct * tty , size_t size )
247
247
{
248
+ struct tty_port * port = tty -> port ;
248
249
unsigned long flags ;
249
250
int length ;
250
251
251
- spin_lock_irqsave (& tty -> buf .lock , flags );
252
- length = __tty_buffer_request_room (tty , size );
253
- spin_unlock_irqrestore (& tty -> buf .lock , flags );
252
+ spin_lock_irqsave (& port -> buf .lock , flags );
253
+ length = __tty_buffer_request_room (port , size );
254
+ spin_unlock_irqrestore (& port -> buf .lock , flags );
254
255
return length ;
255
256
}
256
257
EXPORT_SYMBOL_GPL (tty_buffer_request_room );
@@ -265,13 +266,13 @@ EXPORT_SYMBOL_GPL(tty_buffer_request_room);
265
266
* Queue a series of bytes to the tty buffering. All the characters
266
267
* passed are marked with the supplied flag. Returns the number added.
267
268
*
268
- * Locking: Called functions may take tty ->buf.lock
269
+ * Locking: Called functions may take port ->buf.lock
269
270
*/
270
271
271
272
int tty_insert_flip_string_fixed_flag (struct tty_struct * tty ,
272
273
const unsigned char * chars , char flag , size_t size )
273
274
{
274
- struct tty_bufhead * buf = & tty -> buf ;
275
+ struct tty_bufhead * buf = & tty -> port -> buf ;
275
276
int copied = 0 ;
276
277
do {
277
278
int goal = min_t (size_t , size - copied , TTY_BUFFER_PAGE );
@@ -280,7 +281,7 @@ int tty_insert_flip_string_fixed_flag(struct tty_struct *tty,
280
281
struct tty_buffer * tb ;
281
282
282
283
spin_lock_irqsave (& buf -> lock , flags );
283
- space = __tty_buffer_request_room (tty , goal );
284
+ space = __tty_buffer_request_room (tty -> port , goal );
284
285
tb = buf -> tail ;
285
286
/* If there is no space then tb may be NULL */
286
287
if (unlikely (space == 0 )) {
@@ -311,13 +312,13 @@ EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag);
311
312
* the flags array indicates the status of the character. Returns the
312
313
* number added.
313
314
*
314
- * Locking: Called functions may take tty ->buf.lock
315
+ * Locking: Called functions may take port ->buf.lock
315
316
*/
316
317
317
318
int tty_insert_flip_string_flags (struct tty_struct * tty ,
318
319
const unsigned char * chars , const char * flags , size_t size )
319
320
{
320
- struct tty_bufhead * buf = & tty -> buf ;
321
+ struct tty_bufhead * buf = & tty -> port -> buf ;
321
322
int copied = 0 ;
322
323
do {
323
324
int goal = min_t (size_t , size - copied , TTY_BUFFER_PAGE );
@@ -326,7 +327,7 @@ int tty_insert_flip_string_flags(struct tty_struct *tty,
326
327
struct tty_buffer * tb ;
327
328
328
329
spin_lock_irqsave (& buf -> lock , __flags );
329
- space = __tty_buffer_request_room (tty , goal );
330
+ space = __tty_buffer_request_room (tty -> port , goal );
330
331
tb = buf -> tail ;
331
332
/* If there is no space then tb may be NULL */
332
333
if (unlikely (space == 0 )) {
@@ -357,12 +358,12 @@ EXPORT_SYMBOL(tty_insert_flip_string_flags);
357
358
* Note that this function can only be used when the low_latency flag
358
359
* is unset. Otherwise the workqueue won't be flushed.
359
360
*
360
- * Locking: Takes tty ->buf.lock
361
+ * Locking: Takes port ->buf.lock
361
362
*/
362
363
363
364
void tty_schedule_flip (struct tty_struct * tty )
364
365
{
365
- struct tty_bufhead * buf = & tty -> buf ;
366
+ struct tty_bufhead * buf = & tty -> port -> buf ;
366
367
unsigned long flags ;
367
368
368
369
spin_lock_irqsave (& buf -> lock , flags );
@@ -385,19 +386,19 @@ EXPORT_SYMBOL(tty_schedule_flip);
385
386
* that need their own block copy routines into the buffer. There is no
386
387
* guarantee the buffer is a DMA target!
387
388
*
388
- * Locking: May call functions taking tty ->buf.lock
389
+ * Locking: May call functions taking port ->buf.lock
389
390
*/
390
391
391
392
int tty_prepare_flip_string (struct tty_struct * tty , unsigned char * * chars ,
392
- size_t size )
393
+ size_t size )
393
394
{
394
- struct tty_bufhead * buf = & tty -> buf ;
395
+ struct tty_bufhead * buf = & tty -> port -> buf ;
395
396
int space ;
396
397
unsigned long flags ;
397
398
struct tty_buffer * tb ;
398
399
399
400
spin_lock_irqsave (& buf -> lock , flags );
400
- space = __tty_buffer_request_room (tty , size );
401
+ space = __tty_buffer_request_room (tty -> port , size );
401
402
402
403
tb = buf -> tail ;
403
404
if (likely (space )) {
@@ -423,19 +424,19 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
423
424
* that need their own block copy routines into the buffer. There is no
424
425
* guarantee the buffer is a DMA target!
425
426
*
426
- * Locking: May call functions taking tty ->buf.lock
427
+ * Locking: May call functions taking port ->buf.lock
427
428
*/
428
429
429
430
int tty_prepare_flip_string_flags (struct tty_struct * tty ,
430
431
unsigned char * * chars , char * * flags , size_t size )
431
432
{
432
- struct tty_bufhead * buf = & tty -> buf ;
433
+ struct tty_bufhead * buf = & tty -> port -> buf ;
433
434
int space ;
434
435
unsigned long __flags ;
435
436
struct tty_buffer * tb ;
436
437
437
438
spin_lock_irqsave (& buf -> lock , __flags );
438
- space = __tty_buffer_request_room (tty , size );
439
+ space = __tty_buffer_request_room (tty -> port , size );
439
440
440
441
tb = buf -> tail ;
441
442
if (likely (space )) {
@@ -464,13 +465,16 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
464
465
465
466
static void flush_to_ldisc (struct work_struct * work )
466
467
{
467
- struct tty_struct * tty =
468
- container_of (work , struct tty_struct , buf .work );
469
- struct tty_port * port = tty -> port ;
470
- struct tty_bufhead * buf = & tty -> buf ;
468
+ struct tty_port * port = container_of (work , struct tty_port , buf .work );
469
+ struct tty_bufhead * buf = & port -> buf ;
470
+ struct tty_struct * tty ;
471
471
unsigned long flags ;
472
472
struct tty_ldisc * disc ;
473
473
474
+ tty = port -> itty ;
475
+ if (WARN_RATELIMIT (tty == NULL , "tty is NULL" ))
476
+ return ;
477
+
474
478
disc = tty_ldisc_ref (tty );
475
479
if (disc == NULL ) /* !TTY_LDISC */
476
480
return ;
@@ -489,7 +493,7 @@ static void flush_to_ldisc(struct work_struct *work)
489
493
if (head -> next == NULL )
490
494
break ;
491
495
buf -> head = head -> next ;
492
- tty_buffer_free (tty , head );
496
+ tty_buffer_free (port , head );
493
497
continue ;
494
498
}
495
499
/* Ldisc or user is trying to flush the buffers
@@ -515,7 +519,7 @@ static void flush_to_ldisc(struct work_struct *work)
515
519
/* We may have a deferred request to flush the input buffer,
516
520
if so pull the chain under the lock and empty the queue */
517
521
if (test_bit (TTYP_FLUSHPENDING , & port -> iflags )) {
518
- __tty_buffer_flush (tty );
522
+ __tty_buffer_flush (port );
519
523
clear_bit (TTYP_FLUSHPENDING , & port -> iflags );
520
524
wake_up (& tty -> read_wait );
521
525
}
@@ -535,7 +539,7 @@ static void flush_to_ldisc(struct work_struct *work)
535
539
void tty_flush_to_ldisc (struct tty_struct * tty )
536
540
{
537
541
if (!tty -> low_latency )
538
- flush_work (& tty -> buf .work );
542
+ flush_work (& tty -> port -> buf .work );
539
543
}
540
544
541
545
/**
@@ -553,7 +557,7 @@ void tty_flush_to_ldisc(struct tty_struct *tty)
553
557
554
558
void tty_flip_buffer_push (struct tty_struct * tty )
555
559
{
556
- struct tty_bufhead * buf = & tty -> buf ;
560
+ struct tty_bufhead * buf = & tty -> port -> buf ;
557
561
unsigned long flags ;
558
562
559
563
spin_lock_irqsave (& buf -> lock , flags );
@@ -578,9 +582,9 @@ EXPORT_SYMBOL(tty_flip_buffer_push);
578
582
* Locking: none
579
583
*/
580
584
581
- void tty_buffer_init (struct tty_struct * tty )
585
+ void tty_buffer_init (struct tty_port * port )
582
586
{
583
- struct tty_bufhead * buf = & tty -> buf ;
587
+ struct tty_bufhead * buf = & port -> buf ;
584
588
585
589
spin_lock_init (& buf -> lock );
586
590
buf -> head = NULL ;
0 commit comments