From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
johan@kernel.org, Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 03/11] tty: add kfifo to tty_port
Date: Mon, 24 Jan 2022 08:14:22 +0100 [thread overview]
Message-ID: <20220124071430.14907-4-jslaby@suse.cz> (raw)
In-Reply-To: <20220124071430.14907-1-jslaby@suse.cz>
Define a kfifo inside struct tty_port. We use DECLARE_KFIFO_PTR and let
the preexisting tty_port::xmit_buf be also the buffer for the kfifo.
And handle the initialization/decomissioning along with xmit_buf, i.e.
in tty_port_alloc_xmit_buf() and tty_port_free_xmit_buf(), respectively.
This allows for kfifo use in drivers which opt-in, while others still
may use the old xmit_buf. mxser will be the first user in the next
few patches.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
drivers/tty/tty_port.c | 6 +++++-
include/linux/tty_port.h | 3 +++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 7709ce655f44..7644834640f1 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -225,8 +225,11 @@ int tty_port_alloc_xmit_buf(struct tty_port *port)
{
/* We may sleep in get_zeroed_page() */
mutex_lock(&port->buf_mutex);
- if (port->xmit_buf == NULL)
+ if (port->xmit_buf == NULL) {
port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
+ if (port->xmit_buf)
+ kfifo_init(&port->xmit_fifo, port->xmit_buf, PAGE_SIZE);
+ }
mutex_unlock(&port->buf_mutex);
if (port->xmit_buf == NULL)
return -ENOMEM;
@@ -240,6 +243,7 @@ void tty_port_free_xmit_buf(struct tty_port *port)
if (port->xmit_buf != NULL) {
free_page((unsigned long)port->xmit_buf);
port->xmit_buf = NULL;
+ INIT_KFIFO(port->xmit_fifo);
}
mutex_unlock(&port->buf_mutex);
}
diff --git a/include/linux/tty_port.h b/include/linux/tty_port.h
index d3ea9ed0b98e..58e9619116b7 100644
--- a/include/linux/tty_port.h
+++ b/include/linux/tty_port.h
@@ -2,6 +2,7 @@
#ifndef _LINUX_TTY_PORT_H
#define _LINUX_TTY_PORT_H
+#include <linux/kfifo.h>
#include <linux/kref.h>
#include <linux/mutex.h>
#include <linux/tty_buffer.h>
@@ -67,6 +68,7 @@ extern const struct tty_port_client_operations tty_port_default_client_ops;
* @mutex: locking, for open, shutdown and other port operations
* @buf_mutex: @xmit_buf alloc lock
* @xmit_buf: optional xmit buffer used by some drivers
+ * @xmit_fifo: optional xmit buffer used by some drivers
* @close_delay: delay in jiffies to wait when closing the port
* @closing_wait: delay in jiffies for output to be sent before closing
* @drain_delay: set to zero if no pure time based drain is needed else set to
@@ -110,6 +112,7 @@ struct tty_port {
struct mutex mutex;
struct mutex buf_mutex;
unsigned char *xmit_buf;
+ DECLARE_KFIFO_PTR(xmit_fifo, unsigned char);
unsigned int close_delay;
unsigned int closing_wait;
int drain_delay;
--
2.34.1
next prev parent reply other threads:[~2022-01-24 7:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 7:14 [PATCH 00/11] TTY patches for 5.18 Jiri Slaby
2022-01-24 7:14 ` [PATCH 01/11] serial: core: clean up EXPORT_SYMBOLs Jiri Slaby
2022-01-24 7:14 ` [PATCH 02/11] serial: atmel_serial: include circ_buf.h Jiri Slaby
2022-01-24 8:46 ` Richard Genoud
2022-01-24 8:49 ` Richard Genoud
2022-01-24 7:14 ` Jiri Slaby [this message]
2022-01-24 7:14 ` [PATCH 04/11] tty: tty_port_open, document shutdown vs failed activate Jiri Slaby
2022-01-24 7:14 ` [PATCH 05/11] mxser: fix xmit_buf leak in activate when LSR == 0xff Jiri Slaby
2022-01-24 7:14 ` [PATCH 06/11] mxser: use tty_port xmit_buf helpers Jiri Slaby
2022-01-24 7:14 ` [PATCH 07/11] mxser: switch from xmit_buf to kfifo Jiri Slaby
2022-01-24 7:14 ` [PATCH 08/11] serial: fsl_linflexuart: deduplicate character sending Jiri Slaby
2022-01-24 7:14 ` [PATCH 09/11] serial: fsl_linflexuart: don't call uart_write_wakeup() twice Jiri Slaby
2022-01-24 7:14 ` [PATCH 10/11] serial: make uart_console_write->putchar()'s character a char Jiri Slaby
2022-01-24 9:06 ` Richard Genoud
2022-01-24 14:30 ` kernel test robot
2022-01-26 7:26 ` Jiri Slaby
2022-01-26 13:55 ` Greg KH
2022-01-24 16:23 ` kernel test robot
2022-01-26 17:57 ` Maciej W. Rozycki
2022-01-27 8:09 ` Jiri Slaby
2022-01-24 7:14 ` [PATCH 11/11] serial: mcf: use helpers in mcf_tx_chars() Jiri Slaby
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220124071430.14907-4-jslaby@suse.cz \
--to=jslaby@suse.cz \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®