Commit 3b830a9c authored by Linus Torvalds's avatar Linus Torvalds
Browse files

tty: convert tty_ldisc_ops 'read()' function to take a kernel pointer



The tty line discipline .read() function was passed the final user
pointer destination as an argument, which doesn't match the 'write()'
function, and makes it very inconvenient to do a splice method for
ttys.

This is a conversion to use a kernel buffer instead.

NOTE! It does this by passing the tty line discipline ->read() function
an additional "cookie" to fill in, and an offset into the cookie data.

The line discipline can fill in the cookie data with its own private
information, and then the reader will repeat the read until either the
cookie is cleared or it runs out of data.

The only real user of this is N_HDLC, which can use this to handle big
packets, even if the kernel buffer is smaller than the whole packet.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9bb48c82
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -802,7 +802,8 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file *file,
 * We don't provide read/write/poll interface for user space.
 */
static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,
				 unsigned char __user *buf, size_t nr)
				 unsigned char *buf, size_t nr,
				 void **cookie, unsigned long offset)
{
	return 0;
}
@@ -819,29 +820,28 @@ static __poll_t hci_uart_tty_poll(struct tty_struct *tty,
	return 0;
}

static struct tty_ldisc_ops hci_uart_ldisc = {
	.owner		= THIS_MODULE,
	.magic		= TTY_LDISC_MAGIC,
	.name		= "n_hci",
	.open		= hci_uart_tty_open,
	.close		= hci_uart_tty_close,
	.read		= hci_uart_tty_read,
	.write		= hci_uart_tty_write,
	.ioctl		= hci_uart_tty_ioctl,
	.compat_ioctl	= hci_uart_tty_ioctl,
	.poll		= hci_uart_tty_poll,
	.receive_buf	= hci_uart_tty_receive,
	.write_wakeup	= hci_uart_tty_wakeup,
};

static int __init hci_uart_init(void)
{
	static struct tty_ldisc_ops hci_uart_ldisc;
	int err;

	BT_INFO("HCI UART driver ver %s", VERSION);

	/* Register the tty discipline */

	memset(&hci_uart_ldisc, 0, sizeof(hci_uart_ldisc));
	hci_uart_ldisc.magic		= TTY_LDISC_MAGIC;
	hci_uart_ldisc.name		= "n_hci";
	hci_uart_ldisc.open		= hci_uart_tty_open;
	hci_uart_ldisc.close		= hci_uart_tty_close;
	hci_uart_ldisc.read		= hci_uart_tty_read;
	hci_uart_ldisc.write		= hci_uart_tty_write;
	hci_uart_ldisc.ioctl		= hci_uart_tty_ioctl;
	hci_uart_ldisc.compat_ioctl	= hci_uart_tty_ioctl;
	hci_uart_ldisc.poll		= hci_uart_tty_poll;
	hci_uart_ldisc.receive_buf	= hci_uart_tty_receive;
	hci_uart_ldisc.write_wakeup	= hci_uart_tty_wakeup;
	hci_uart_ldisc.owner		= THIS_MODULE;

	err = tty_register_ldisc(N_HCI, &hci_uart_ldisc);
	if (err) {
		BT_ERR("HCI line discipline registration failed. (%d)", err);
+3 −1
Original line number Diff line number Diff line
@@ -156,7 +156,9 @@ static void serport_ldisc_receive(struct tty_struct *tty, const unsigned char *c
 * returning 0 characters.
 */

static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file, unsigned char __user * buf, size_t nr)
static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file,
				  unsigned char *kbuf, size_t nr,
				  void **cookie, unsigned long offset)
{
	struct serport *serport = (struct serport*) tty->disc_data;
	struct serio *serio;
+2 −1
Original line number Diff line number Diff line
@@ -259,7 +259,8 @@ static int ppp_asynctty_hangup(struct tty_struct *tty)
 */
static ssize_t
ppp_asynctty_read(struct tty_struct *tty, struct file *file,
		  unsigned char __user *buf, size_t count)
		  unsigned char *buf, size_t count,
		  void **cookie, unsigned long offset)
{
	return -EAGAIN;
}
+2 −1
Original line number Diff line number Diff line
@@ -257,7 +257,8 @@ static int ppp_sync_hangup(struct tty_struct *tty)
 */
static ssize_t
ppp_sync_read(struct tty_struct *tty, struct file *file,
	       unsigned char __user *buf, size_t count)
	      unsigned char *buf, size_t count,
	      void **cookie, unsigned long offset)
{
	return -EAGAIN;
}
+2 −1
Original line number Diff line number Diff line
@@ -2557,7 +2557,8 @@ static void gsmld_write_wakeup(struct tty_struct *tty)
 */

static ssize_t gsmld_read(struct tty_struct *tty, struct file *file,
			 unsigned char __user *buf, size_t nr)
			  unsigned char *buf, size_t nr,
			  void **cookie, unsigned long offset)
{
	return -EOPNOTSUPP;
}
Loading