29
29
30
30
void tty_buffer_free_all (struct tty_struct * tty )
31
31
{
32
+ struct tty_bufhead * buf = & tty -> buf ;
32
33
struct tty_buffer * thead ;
33
- while ((thead = tty -> buf .head ) != NULL ) {
34
- tty -> buf .head = thead -> next ;
34
+
35
+ while ((thead = buf -> head ) != NULL ) {
36
+ buf -> head = thead -> next ;
35
37
kfree (thead );
36
38
}
37
- while ((thead = tty -> buf . free ) != NULL ) {
38
- tty -> buf . free = thead -> next ;
39
+ while ((thead = buf -> free ) != NULL ) {
40
+ buf -> free = thead -> next ;
39
41
kfree (thead );
40
42
}
41
- tty -> buf . tail = NULL ;
42
- tty -> buf . memory_used = 0 ;
43
+ buf -> tail = NULL ;
44
+ buf -> memory_used = 0 ;
43
45
}
44
46
45
47
/**
@@ -87,15 +89,17 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
87
89
88
90
static void tty_buffer_free (struct tty_struct * tty , struct tty_buffer * b )
89
91
{
92
+ struct tty_bufhead * buf = & tty -> buf ;
93
+
90
94
/* Dumb strategy for now - should keep some stats */
91
- tty -> buf . memory_used -= b -> size ;
92
- WARN_ON (tty -> buf . memory_used < 0 );
95
+ buf -> memory_used -= b -> size ;
96
+ WARN_ON (buf -> memory_used < 0 );
93
97
94
98
if (b -> size >= 512 )
95
99
kfree (b );
96
100
else {
97
- b -> next = tty -> buf . free ;
98
- tty -> buf . free = b ;
101
+ b -> next = buf -> free ;
102
+ buf -> free = b ;
99
103
}
100
104
}
101
105
@@ -112,13 +116,14 @@ static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
112
116
113
117
static void __tty_buffer_flush (struct tty_struct * tty )
114
118
{
119
+ struct tty_bufhead * buf = & tty -> buf ;
115
120
struct tty_buffer * thead ;
116
121
117
- while ((thead = tty -> buf . head ) != NULL ) {
118
- tty -> buf . head = thead -> next ;
122
+ while ((thead = buf -> head ) != NULL ) {
123
+ buf -> head = thead -> next ;
119
124
tty_buffer_free (tty , thead );
120
125
}
121
- tty -> buf . tail = NULL ;
126
+ buf -> tail = NULL ;
122
127
}
123
128
124
129
/**
@@ -135,21 +140,23 @@ static void __tty_buffer_flush(struct tty_struct *tty)
135
140
void tty_buffer_flush (struct tty_struct * tty )
136
141
{
137
142
struct tty_port * port = tty -> port ;
143
+ struct tty_bufhead * buf = & tty -> buf ;
138
144
unsigned long flags ;
139
- spin_lock_irqsave (& tty -> buf .lock , flags );
145
+
146
+ spin_lock_irqsave (& buf -> lock , flags );
140
147
141
148
/* If the data is being pushed to the tty layer then we can't
142
149
process it here. Instead set a flag and the flush_to_ldisc
143
150
path will process the flush request before it exits */
144
151
if (test_bit (TTYP_FLUSHING , & port -> iflags )) {
145
152
set_bit (TTYP_FLUSHPENDING , & port -> iflags );
146
- spin_unlock_irqrestore (& tty -> buf . lock , flags );
153
+ spin_unlock_irqrestore (& buf -> lock , flags );
147
154
wait_event (tty -> read_wait ,
148
155
test_bit (TTYP_FLUSHPENDING , & port -> iflags ) == 0 );
149
156
return ;
150
157
} else
151
158
__tty_buffer_flush (tty );
152
- spin_unlock_irqrestore (& tty -> buf . lock , flags );
159
+ spin_unlock_irqrestore (& buf -> lock , flags );
153
160
}
154
161
155
162
/**
@@ -197,12 +204,14 @@ static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
197
204
*/
198
205
static int __tty_buffer_request_room (struct tty_struct * tty , size_t size )
199
206
{
207
+ struct tty_bufhead * buf = & tty -> buf ;
200
208
struct tty_buffer * b , * n ;
201
209
int left ;
202
210
/* OPTIMISATION: We could keep a per tty "zero" sized buffer to
203
211
remove this conditional if its worth it. This would be invisible
204
212
to the callers */
205
- if ((b = tty -> buf .tail ) != NULL )
213
+ b = buf -> tail ;
214
+ if (b != NULL )
206
215
left = b -> size - b -> used ;
207
216
else
208
217
left = 0 ;
@@ -214,8 +223,8 @@ static int __tty_buffer_request_room(struct tty_struct *tty, size_t size)
214
223
b -> next = n ;
215
224
b -> commit = b -> used ;
216
225
} else
217
- tty -> buf . head = n ;
218
- tty -> buf . tail = n ;
226
+ buf -> head = n ;
227
+ buf -> tail = n ;
219
228
} else
220
229
size = left ;
221
230
}
@@ -262,25 +271,26 @@ EXPORT_SYMBOL_GPL(tty_buffer_request_room);
262
271
int tty_insert_flip_string_fixed_flag (struct tty_struct * tty ,
263
272
const unsigned char * chars , char flag , size_t size )
264
273
{
274
+ struct tty_bufhead * buf = & tty -> buf ;
265
275
int copied = 0 ;
266
276
do {
267
277
int goal = min_t (size_t , size - copied , TTY_BUFFER_PAGE );
268
278
int space ;
269
279
unsigned long flags ;
270
280
struct tty_buffer * tb ;
271
281
272
- spin_lock_irqsave (& tty -> buf . lock , flags );
282
+ spin_lock_irqsave (& buf -> lock , flags );
273
283
space = __tty_buffer_request_room (tty , goal );
274
- tb = tty -> buf . tail ;
284
+ tb = buf -> tail ;
275
285
/* If there is no space then tb may be NULL */
276
286
if (unlikely (space == 0 )) {
277
- spin_unlock_irqrestore (& tty -> buf . lock , flags );
287
+ spin_unlock_irqrestore (& buf -> lock , flags );
278
288
break ;
279
289
}
280
290
memcpy (tb -> char_buf_ptr + tb -> used , chars , space );
281
291
memset (tb -> flag_buf_ptr + tb -> used , flag , space );
282
292
tb -> used += space ;
283
- spin_unlock_irqrestore (& tty -> buf . lock , flags );
293
+ spin_unlock_irqrestore (& buf -> lock , flags );
284
294
copied += space ;
285
295
chars += space ;
286
296
/* There is a small chance that we need to split the data over
@@ -307,25 +317,26 @@ EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag);
307
317
int tty_insert_flip_string_flags (struct tty_struct * tty ,
308
318
const unsigned char * chars , const char * flags , size_t size )
309
319
{
320
+ struct tty_bufhead * buf = & tty -> buf ;
310
321
int copied = 0 ;
311
322
do {
312
323
int goal = min_t (size_t , size - copied , TTY_BUFFER_PAGE );
313
324
int space ;
314
325
unsigned long __flags ;
315
326
struct tty_buffer * tb ;
316
327
317
- spin_lock_irqsave (& tty -> buf . lock , __flags );
328
+ spin_lock_irqsave (& buf -> lock , __flags );
318
329
space = __tty_buffer_request_room (tty , goal );
319
- tb = tty -> buf . tail ;
330
+ tb = buf -> tail ;
320
331
/* If there is no space then tb may be NULL */
321
332
if (unlikely (space == 0 )) {
322
- spin_unlock_irqrestore (& tty -> buf . lock , __flags );
333
+ spin_unlock_irqrestore (& buf -> lock , __flags );
323
334
break ;
324
335
}
325
336
memcpy (tb -> char_buf_ptr + tb -> used , chars , space );
326
337
memcpy (tb -> flag_buf_ptr + tb -> used , flags , space );
327
338
tb -> used += space ;
328
- spin_unlock_irqrestore (& tty -> buf . lock , __flags );
339
+ spin_unlock_irqrestore (& buf -> lock , __flags );
329
340
copied += space ;
330
341
chars += space ;
331
342
flags += space ;
@@ -351,12 +362,14 @@ EXPORT_SYMBOL(tty_insert_flip_string_flags);
351
362
352
363
void tty_schedule_flip (struct tty_struct * tty )
353
364
{
365
+ struct tty_bufhead * buf = & tty -> buf ;
354
366
unsigned long flags ;
355
- spin_lock_irqsave (& tty -> buf .lock , flags );
356
- if (tty -> buf .tail != NULL )
357
- tty -> buf .tail -> commit = tty -> buf .tail -> used ;
358
- spin_unlock_irqrestore (& tty -> buf .lock , flags );
359
- schedule_work (& tty -> buf .work );
367
+
368
+ spin_lock_irqsave (& buf -> lock , flags );
369
+ if (buf -> tail != NULL )
370
+ buf -> tail -> commit = buf -> tail -> used ;
371
+ spin_unlock_irqrestore (& buf -> lock , flags );
372
+ schedule_work (& buf -> work );
360
373
}
361
374
EXPORT_SYMBOL (tty_schedule_flip );
362
375
@@ -378,20 +391,21 @@ EXPORT_SYMBOL(tty_schedule_flip);
378
391
int tty_prepare_flip_string (struct tty_struct * tty , unsigned char * * chars ,
379
392
size_t size )
380
393
{
394
+ struct tty_bufhead * buf = & tty -> buf ;
381
395
int space ;
382
396
unsigned long flags ;
383
397
struct tty_buffer * tb ;
384
398
385
- spin_lock_irqsave (& tty -> buf . lock , flags );
399
+ spin_lock_irqsave (& buf -> lock , flags );
386
400
space = __tty_buffer_request_room (tty , size );
387
401
388
- tb = tty -> buf . tail ;
402
+ tb = buf -> tail ;
389
403
if (likely (space )) {
390
404
* chars = tb -> char_buf_ptr + tb -> used ;
391
405
memset (tb -> flag_buf_ptr + tb -> used , TTY_NORMAL , space );
392
406
tb -> used += space ;
393
407
}
394
- spin_unlock_irqrestore (& tty -> buf . lock , flags );
408
+ spin_unlock_irqrestore (& buf -> lock , flags );
395
409
return space ;
396
410
}
397
411
EXPORT_SYMBOL_GPL (tty_prepare_flip_string );
@@ -415,20 +429,21 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
415
429
int tty_prepare_flip_string_flags (struct tty_struct * tty ,
416
430
unsigned char * * chars , char * * flags , size_t size )
417
431
{
432
+ struct tty_bufhead * buf = & tty -> buf ;
418
433
int space ;
419
434
unsigned long __flags ;
420
435
struct tty_buffer * tb ;
421
436
422
- spin_lock_irqsave (& tty -> buf . lock , __flags );
437
+ spin_lock_irqsave (& buf -> lock , __flags );
423
438
space = __tty_buffer_request_room (tty , size );
424
439
425
- tb = tty -> buf . tail ;
440
+ tb = buf -> tail ;
426
441
if (likely (space )) {
427
442
* chars = tb -> char_buf_ptr + tb -> used ;
428
443
* flags = tb -> flag_buf_ptr + tb -> used ;
429
444
tb -> used += space ;
430
445
}
431
- spin_unlock_irqrestore (& tty -> buf . lock , __flags );
446
+ spin_unlock_irqrestore (& buf -> lock , __flags );
432
447
return space ;
433
448
}
434
449
EXPORT_SYMBOL_GPL (tty_prepare_flip_string_flags );
@@ -452,18 +467,19 @@ static void flush_to_ldisc(struct work_struct *work)
452
467
struct tty_struct * tty =
453
468
container_of (work , struct tty_struct , buf .work );
454
469
struct tty_port * port = tty -> port ;
470
+ struct tty_bufhead * buf = & tty -> buf ;
455
471
unsigned long flags ;
456
472
struct tty_ldisc * disc ;
457
473
458
474
disc = tty_ldisc_ref (tty );
459
475
if (disc == NULL ) /* !TTY_LDISC */
460
476
return ;
461
477
462
- spin_lock_irqsave (& tty -> buf . lock , flags );
478
+ spin_lock_irqsave (& buf -> lock , flags );
463
479
464
480
if (!test_and_set_bit (TTYP_FLUSHING , & port -> iflags )) {
465
481
struct tty_buffer * head ;
466
- while ((head = tty -> buf . head ) != NULL ) {
482
+ while ((head = buf -> head ) != NULL ) {
467
483
int count ;
468
484
char * char_buf ;
469
485
unsigned char * flag_buf ;
@@ -472,7 +488,7 @@ static void flush_to_ldisc(struct work_struct *work)
472
488
if (!count ) {
473
489
if (head -> next == NULL )
474
490
break ;
475
- tty -> buf . head = head -> next ;
491
+ buf -> head = head -> next ;
476
492
tty_buffer_free (tty , head );
477
493
continue ;
478
494
}
@@ -488,10 +504,10 @@ static void flush_to_ldisc(struct work_struct *work)
488
504
char_buf = head -> char_buf_ptr + head -> read ;
489
505
flag_buf = head -> flag_buf_ptr + head -> read ;
490
506
head -> read += count ;
491
- spin_unlock_irqrestore (& tty -> buf . lock , flags );
507
+ spin_unlock_irqrestore (& buf -> lock , flags );
492
508
disc -> ops -> receive_buf (tty , char_buf ,
493
509
flag_buf , count );
494
- spin_lock_irqsave (& tty -> buf . lock , flags );
510
+ spin_lock_irqsave (& buf -> lock , flags );
495
511
}
496
512
clear_bit (TTYP_FLUSHING , & port -> iflags );
497
513
}
@@ -503,7 +519,7 @@ static void flush_to_ldisc(struct work_struct *work)
503
519
clear_bit (TTYP_FLUSHPENDING , & port -> iflags );
504
520
wake_up (& tty -> read_wait );
505
521
}
506
- spin_unlock_irqrestore (& tty -> buf . lock , flags );
522
+ spin_unlock_irqrestore (& buf -> lock , flags );
507
523
508
524
tty_ldisc_deref (disc );
509
525
}
@@ -537,16 +553,18 @@ void tty_flush_to_ldisc(struct tty_struct *tty)
537
553
538
554
void tty_flip_buffer_push (struct tty_struct * tty )
539
555
{
556
+ struct tty_bufhead * buf = & tty -> buf ;
540
557
unsigned long flags ;
541
- spin_lock_irqsave (& tty -> buf .lock , flags );
542
- if (tty -> buf .tail != NULL )
543
- tty -> buf .tail -> commit = tty -> buf .tail -> used ;
544
- spin_unlock_irqrestore (& tty -> buf .lock , flags );
558
+
559
+ spin_lock_irqsave (& buf -> lock , flags );
560
+ if (buf -> tail != NULL )
561
+ buf -> tail -> commit = buf -> tail -> used ;
562
+ spin_unlock_irqrestore (& buf -> lock , flags );
545
563
546
564
if (tty -> low_latency )
547
- flush_to_ldisc (& tty -> buf . work );
565
+ flush_to_ldisc (& buf -> work );
548
566
else
549
- schedule_work (& tty -> buf . work );
567
+ schedule_work (& buf -> work );
550
568
}
551
569
EXPORT_SYMBOL (tty_flip_buffer_push );
552
570
@@ -562,11 +580,13 @@ EXPORT_SYMBOL(tty_flip_buffer_push);
562
580
563
581
void tty_buffer_init (struct tty_struct * tty )
564
582
{
565
- spin_lock_init (& tty -> buf .lock );
566
- tty -> buf .head = NULL ;
567
- tty -> buf .tail = NULL ;
568
- tty -> buf .free = NULL ;
569
- tty -> buf .memory_used = 0 ;
570
- INIT_WORK (& tty -> buf .work , flush_to_ldisc );
583
+ struct tty_bufhead * buf = & tty -> buf ;
584
+
585
+ spin_lock_init (& buf -> lock );
586
+ buf -> head = NULL ;
587
+ buf -> tail = NULL ;
588
+ buf -> free = NULL ;
589
+ buf -> memory_used = 0 ;
590
+ INIT_WORK (& buf -> work , flush_to_ldisc );
571
591
}
572
592
0 commit comments