summaryrefslogtreecommitdiff
path: root/lib/test_hexdump.c
diff options
context:
space:
mode:
authorOkash Khawaja <okash.khawaja@gmail.com>2017-07-20 08:22:36 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-08-28 16:15:41 +0200
commita09ac3974d0c0b25dfa70f8076546bc4876dd7a8 (patch)
tree54ceaea718b5ceb2cdaaaae1a1f175f186e80be7 /lib/test_hexdump.c
parent8439a69e72888daa7d2667980efaf20d8bbe7b20 (diff)
downloadlwn-a09ac3974d0c0b25dfa70f8076546bc4876dd7a8.tar.gz
lwn-a09ac3974d0c0b25dfa70f8076546bc4876dd7a8.zip
tty: resolve tty contention between kernel and user space
The commit 12e84c71b7d4 ("tty: export tty_open_by_driver") exports tty_open_by_device to allow tty to be opened from inside kernel which works fine except that it doesn't handle contention with user space or another kernel-space open of the same tty. For example, opening a tty from user space while it is kernel opened results in failure and a kernel log message about mismatch between tty->count and tty's file open count. This patch makes kernel access to tty exclusive, so that if a user process or kernel opens a kernel opened tty, it gets -EBUSY. It does this by adding TTY_KOPENED flag to tty->flags. When this flag is set, tty_open_by_driver returns -EBUSY. Instead of overloading tty_open_by_driver for both kernel and user space, this patch creates a separate function tty_kopen which closely follows tty_open_by_driver. tty_kclose closes the tty opened by tty_kopen. To address the mismatch between tty->count and #fd's, this patch adds #kopen's to the count before comparing it with tty->count. That way check_tty_count reflects correct usage count. Returning -EBUSY on tty open is a change in the interface. I have tested this with minicom, picocom and commands like "echo foo > /dev/ttyS0". They all correctly report "Device or resource busy" when the tty is already kernel opened. Signed-off-by: Okash Khawaja <okash.khawaja@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib/test_hexdump.c')
0 files changed, 0 insertions, 0 deletions