Commit d6d9d17a authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Greg Kroah-Hartman
Browse files

tty: tty_io: Switch to vmalloc() fallback in case of TTY_NO_WRITE_SPLIT



When TTY_NO_WRITE_SPLIT is set and 64 KiB chunks are used, allow
vmalloc() fallback. Supply __GFP_RETRY_MAYFAIL to make kmalloc()
preferable over vmalloc() since we may want a better performance.

Note, both current users copy data to another buffer anyway, so
the type of our allocation doesn't affect their expectations.

Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20211220133250.3070-1-andriy.shevchenko@linux.intel.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e822b497
Loading
Loading
Loading
Loading
+3 −6
Original line number Original line Diff line number Diff line
@@ -169,7 +169,7 @@ static void free_tty_struct(struct tty_struct *tty)
{
{
	tty_ldisc_deinit(tty);
	tty_ldisc_deinit(tty);
	put_device(tty->dev);
	put_device(tty->dev);
	kfree(tty->write_buf);
	kvfree(tty->write_buf);
	tty->magic = 0xDEADDEAD;
	tty->magic = 0xDEADDEAD;
	kfree(tty);
	kfree(tty);
}
}
@@ -986,9 +986,6 @@ static inline ssize_t do_tty_write(
	 * layer has problems with bigger chunks. It will
	 * layer has problems with bigger chunks. It will
	 * claim to be able to handle more characters than
	 * claim to be able to handle more characters than
	 * it actually does.
	 * it actually does.
	 *
	 * FIXME: This can probably go away now except that 64K chunks
	 * are too likely to fail unless switched to vmalloc...
	 */
	 */
	chunk = 2048;
	chunk = 2048;
	if (test_bit(TTY_NO_WRITE_SPLIT, &tty->flags))
	if (test_bit(TTY_NO_WRITE_SPLIT, &tty->flags))
@@ -1003,12 +1000,12 @@ static inline ssize_t do_tty_write(
		if (chunk < 1024)
		if (chunk < 1024)
			chunk = 1024;
			chunk = 1024;


		buf_chunk = kmalloc(chunk, GFP_KERNEL);
		buf_chunk = kvmalloc(chunk, GFP_KERNEL | __GFP_RETRY_MAYFAIL);
		if (!buf_chunk) {
		if (!buf_chunk) {
			ret = -ENOMEM;
			ret = -ENOMEM;
			goto out;
			goto out;
		}
		}
		kfree(tty->write_buf);
		kvfree(tty->write_buf);
		tty->write_cnt = chunk;
		tty->write_cnt = chunk;
		tty->write_buf = buf_chunk;
		tty->write_buf = buf_chunk;
	}
	}
+0 −4
Original line number Original line Diff line number Diff line
@@ -685,10 +685,6 @@ static int acm_port_activate(struct tty_port *port, struct tty_struct *tty)
	if (retval)
	if (retval)
		goto error_get_interface;
		goto error_get_interface;


	/*
	 * FIXME: Why do we need this? Allocating 64K of physically contiguous
	 * memory is really nasty...
	 */
	set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
	set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
	acm->control->needs_remote_wakeup = 1;
	acm->control->needs_remote_wakeup = 1;