tty: fix BKL related leak and crash

Enabling the BKL to be lockdep tracked uncovered the following
upstream kernel bug in the tty code, which caused a BKL
reference leak:

================================================
[ BUG: lock held when returning to user space! ]
------------------------------------------------
dmesg/3121 is leaving the kernel with locks still held!
1 lock held by dmesg/3121:
#0: (kernel_mutex){--..}, at: [<c02f34d9>] opost+0x24/0x194

this might explain some of the atomicity warnings and crashes
that -tip tree testing has been experiencing since the BKL
was converted back to a spinlock.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Ingo Molnar and committed by Linus Torvalds 487ad7ef 8568dae2

+10 -3
+10 -3
drivers/char/n_tty.c
··· 282 if (O_ONLRET(tty)) 283 tty->column = 0; 284 if (O_ONLCR(tty)) { 285 - if (space < 2) 286 return -1; 287 tty_put_char(tty, '\r'); 288 tty->column = 0; 289 } 290 tty->canon_column = tty->column; 291 break; 292 case '\r': 293 - if (O_ONOCR(tty) && tty->column == 0) 294 return 0; 295 if (O_OCRNL(tty)) { 296 c = '\n'; 297 if (O_ONLRET(tty)) ··· 307 case '\t': 308 spaces = 8 - (tty->column & 7); 309 if (O_TABDLY(tty) == XTABS) { 310 - if (space < spaces) 311 return -1; 312 tty->column += spaces; 313 tty->ops->write(tty, " ", spaces); 314 return 0; 315 } 316 tty->column += spaces;
··· 282 if (O_ONLRET(tty)) 283 tty->column = 0; 284 if (O_ONLCR(tty)) { 285 + if (space < 2) { 286 + unlock_kernel(); 287 return -1; 288 + } 289 tty_put_char(tty, '\r'); 290 tty->column = 0; 291 } 292 tty->canon_column = tty->column; 293 break; 294 case '\r': 295 + if (O_ONOCR(tty) && tty->column == 0) { 296 + unlock_kernel(); 297 return 0; 298 + } 299 if (O_OCRNL(tty)) { 300 c = '\n'; 301 if (O_ONLRET(tty)) ··· 303 case '\t': 304 spaces = 8 - (tty->column & 7); 305 if (O_TABDLY(tty) == XTABS) { 306 + if (space < spaces) { 307 + unlock_kernel(); 308 return -1; 309 + } 310 tty->column += spaces; 311 tty->ops->write(tty, " ", spaces); 312 + unlock_kernel(); 313 return 0; 314 } 315 tty->column += spaces;