linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/29] tty: cleanup no. 99
@ 2025-02-20 11:15 Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 01/29] tty: convert "TTY Struct Flags" to an enum Jiri Slaby (SUSE)
                   ` (29 more replies)
  0 siblings, 30 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Alex Elder,
	Andrew Lunn, Andy Shevchenko, David Lin, David S. Miller,
	Eric Dumazet, greybus-dev, Ilpo Järvinen, Jakub Kicinski,
	Johan Hovold, linux-alpha, linux-staging, Matt Turner, netdev,
	Paolo Abeni, Richard Henderson, Rob Herring, sparclinux

Hi,

this is (again) a series of cleanup in tty. I am trying to rework
tty+serial to avoid limitations of devices (so called NR_UART or
tty_alloc_driver()'s first parameter). And the below popped up while
crawling through the code. So this is only a prep cleanup.

* many tty flags are now enums
* many functions were improved for readability
* quite a few unused or old code dropped

In particular, the runtime behaviour of the kernel before and after the
changes is supposed to be bug to bug compatible (except moxa's ioctl
and ISA evils dropped). That is, noone should notice.

Cc: Alex Elder <elder@kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: David Lin <dtwlin@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: greybus-dev@lists.linaro.org
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Johan Hovold <johan@kernel.org>
Cc: linux-alpha@vger.kernel.org
Cc: linux-staging@lists.linux.dev
Cc: Matt Turner <mattst88@gmail.com>
Cc: netdev@vger.kernel.org
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Rob Herring <robh@kernel.org>
Cc: sparclinux@vger.kernel.org

Jiri Slaby (SUSE) (29):
  tty: convert "TTY Struct Flags" to an enum
  tty: audit: do not use N_TTY_BUF_SIZE
  tty: caif: do not use N_TTY_BUF_SIZE
  tty: move N_TTY_BUF_SIZE to n_tty
  tty: n_tty: use uint for space returned by tty_write_room()
  tty: n_tty: simplify process_output()
  tty: n_tty: clean up process_output_block()
  tty: n_tty: drop n_tty_trace()
  tty: n_tty: extract n_tty_continue_cookie() from n_tty_read()
  tty: n_tty: extract n_tty_wait_for_input()
  tty: n_tty: move more_to_be_read to the end of n_tty_read()
  tty: tty_driver: move TTY macros to the top
  tty: tty_driver: convert "TTY Driver Flags" to an enum
  tty: tty_driver: document both {,__}tty_alloc_driver() properly
  tty: tty_driver: introduce TTY driver sub/types enums
  tty: serdev: drop serdev_controller_ops::write_room()
  tty: moxa: drop version dump to logs
  tty: moxa: drop ISA support
  tty: moxa: carve out special ioctls and extra tty_port
  tty: srmcons: fix retval from srmcons_init()
  tty: staging/greybus: pass tty_driver flags to tty_alloc_driver()
  tty: sunsu: drop serial_{in,out}p()
  tty: sunsu: remove unused serial_icr_read()
  serial: remove redundant tty_port_link_device()
  serial: pass struct uart_state to uart_line_info()
  serial: 8250: use serial_in/out() helpers
  serial: 8250_rsa: simplify rsa8250_{request/release}_resource()
  serial: 8250_port: do not use goto for UPQ_NO_TXEN_TEST code flow
  serial: 8250_port: simplify serial8250_request_std_resource()

 Documentation/driver-api/tty/tty_driver.rst |   4 +-
 Documentation/driver-api/tty/tty_struct.rst |   2 +-
 arch/alpha/kernel/srmcons.c                 |  62 ++---
 drivers/net/caif/caif_serial.c              |   2 +-
 drivers/staging/greybus/uart.c              |   4 +-
 drivers/tty/Kconfig                         |   2 +-
 drivers/tty/moxa.c                          | 251 +-------------------
 drivers/tty/n_tty.c                         | 212 ++++++++---------
 drivers/tty/serdev/core.c                   |  11 -
 drivers/tty/serdev/serdev-ttyport.c         |   9 -
 drivers/tty/serial/8250/8250_dw.c           |  17 +-
 drivers/tty/serial/8250/8250_fsl.c          |   8 +-
 drivers/tty/serial/8250/8250_omap.c         |   2 +-
 drivers/tty/serial/8250/8250_port.c         |  59 ++---
 drivers/tty/serial/8250/8250_rsa.c          |  21 +-
 drivers/tty/serial/serial_core.c            |   6 +-
 drivers/tty/serial/sunsu.c                  | 178 ++++++--------
 drivers/tty/tty_audit.c                     |  10 +-
 drivers/tty/tty_io.c                        |   8 +-
 include/linux/serdev.h                      |   6 -
 include/linux/tty.h                         |  53 +++--
 include/linux/tty_driver.h                  | 180 +++++++-------
 22 files changed, 410 insertions(+), 697 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 43+ messages in thread

* [PATCH 01/29] tty: convert "TTY Struct Flags" to an enum
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 02/29] tty: audit: do not use N_TTY_BUF_SIZE Jiri Slaby (SUSE)
                   ` (28 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

Convert TTY_* macros (flags) to an enum. This allows for easier
kernel-doc (the comment needed fine tuning), grouping of these nicely,
and proper checking.

Note that these are bit positions. So they are used such as
test_bit(TTY_THROTTLED, ...). Given these are not the user API (only
in-kernel API/ABI), the bit positions are NOT preserved in this patch.
All are renumbered naturally using the enum-auto-numbering.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 Documentation/driver-api/tty/tty_struct.rst |  2 +-
 include/linux/tty.h                         | 52 +++++++++++----------
 2 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/Documentation/driver-api/tty/tty_struct.rst b/Documentation/driver-api/tty/tty_struct.rst
index c72f5a4293b2..29caf1c1ca5f 100644
--- a/Documentation/driver-api/tty/tty_struct.rst
+++ b/Documentation/driver-api/tty/tty_struct.rst
@@ -72,7 +72,7 @@ TTY Struct Flags
 ================
 
 .. kernel-doc:: include/linux/tty.h
-   :doc: TTY Struct Flags
+   :identifiers: tty_struct_flags
 
 TTY Struct Reference
 ====================
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 2372f9357240..6bb4fb3845f0 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -251,7 +251,7 @@ struct tty_file_private {
 };
 
 /**
- * DOC: TTY Struct Flags
+ * enum tty_struct_flags - TTY Struct Flags
  *
  * These bits are used in the :c:member:`tty_struct.flags` field.
  *
@@ -260,62 +260,64 @@ struct tty_file_private {
  * tty->write.  Thus, you must use the inline functions set_bit() and
  * clear_bit() to make things atomic.
  *
- * TTY_THROTTLED
+ * @TTY_THROTTLED:
  *	Driver input is throttled. The ldisc should call
  *	:c:member:`tty_driver.unthrottle()` in order to resume reception when
  *	it is ready to process more data (at threshold min).
  *
- * TTY_IO_ERROR
+ * @TTY_IO_ERROR:
  *	If set, causes all subsequent userspace read/write calls on the tty to
  *	fail, returning -%EIO. (May be no ldisc too.)
  *
- * TTY_OTHER_CLOSED
+ * @TTY_OTHER_CLOSED:
  *	Device is a pty and the other side has closed.
  *
- * TTY_EXCLUSIVE
+ * @TTY_EXCLUSIVE:
  *	Exclusive open mode (a single opener).
  *
- * TTY_DO_WRITE_WAKEUP
+ * @TTY_DO_WRITE_WAKEUP:
  *	If set, causes the driver to call the
  *	:c:member:`tty_ldisc_ops.write_wakeup()` method in order to resume
  *	transmission when it can accept more data to transmit.
  *
- * TTY_LDISC_OPEN
+ * @TTY_LDISC_OPEN:
  *	Indicates that a line discipline is open. For debugging purposes only.
  *
- * TTY_PTY_LOCK
+ * @TTY_PTY_LOCK:
  *	A flag private to pty code to implement %TIOCSPTLCK/%TIOCGPTLCK logic.
  *
- * TTY_NO_WRITE_SPLIT
+ * @TTY_NO_WRITE_SPLIT:
  *	Prevent driver from splitting up writes into smaller chunks (preserve
  *	write boundaries to driver).
  *
- * TTY_HUPPED
+ * @TTY_HUPPED:
  *	The TTY was hung up. This is set post :c:member:`tty_driver.hangup()`.
  *
- * TTY_HUPPING
+ * @TTY_HUPPING:
  *	The TTY is in the process of hanging up to abort potential readers.
  *
- * TTY_LDISC_CHANGING
+ * @TTY_LDISC_CHANGING:
  *	Line discipline for this TTY is being changed. I/O should not block
  *	when this is set. Use tty_io_nonblock() to check.
  *
- * TTY_LDISC_HALTED
+ * @TTY_LDISC_HALTED:
  *	Line discipline for this TTY was stopped. No work should be queued to
  *	this ldisc.
  */
-#define TTY_THROTTLED		0
-#define TTY_IO_ERROR		1
-#define TTY_OTHER_CLOSED	2
-#define TTY_EXCLUSIVE		3
-#define TTY_DO_WRITE_WAKEUP	5
-#define TTY_LDISC_OPEN		11
-#define TTY_PTY_LOCK		16
-#define TTY_NO_WRITE_SPLIT	17
-#define TTY_HUPPED		18
-#define TTY_HUPPING		19
-#define TTY_LDISC_CHANGING	20
-#define TTY_LDISC_HALTED	22
+enum tty_struct_flags {
+	TTY_THROTTLED,
+	TTY_IO_ERROR,
+	TTY_OTHER_CLOSED,
+	TTY_EXCLUSIVE,
+	TTY_DO_WRITE_WAKEUP,
+	TTY_LDISC_OPEN,
+	TTY_PTY_LOCK,
+	TTY_NO_WRITE_SPLIT,
+	TTY_HUPPED,
+	TTY_HUPPING,
+	TTY_LDISC_CHANGING,
+	TTY_LDISC_HALTED,
+};
 
 static inline bool tty_io_nonblock(struct tty_struct *tty, struct file *file)
 {
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 02/29] tty: audit: do not use N_TTY_BUF_SIZE
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 01/29] tty: convert "TTY Struct Flags" to an enum Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 03/29] tty: caif: " Jiri Slaby (SUSE)
                   ` (27 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

N_TTY_BUF_SIZE -- as the name suggests -- is the N_TTY's buffer size.
There is no reason to couple that to audit's buffer size, so define an
own TTY_AUDIT_BUF_SIZE macro (with the same size).

N_TTY_BUF_SIZE is private and will be moved to n_tty.c later.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/tty_audit.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index 1d81eeefb068..75542333c54a 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -12,12 +12,14 @@
 #include <linux/tty.h>
 #include "tty.h"
 
+#define TTY_AUDIT_BUF_SIZE	4096
+
 struct tty_audit_buf {
 	struct mutex mutex;	/* Protects all data below */
 	dev_t dev;		/* The TTY which the data is from */
 	bool icanon;
 	size_t valid;
-	u8 *data;		/* Allocated size N_TTY_BUF_SIZE */
+	u8 *data;		/* Allocated size TTY_AUDIT_BUF_SIZE */
 };
 
 static struct tty_audit_buf *tty_audit_buf_ref(void)
@@ -37,7 +39,7 @@ static struct tty_audit_buf *tty_audit_buf_alloc(void)
 	if (!buf)
 		goto err;
 
-	buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
+	buf->data = kmalloc(TTY_AUDIT_BUF_SIZE, GFP_KERNEL);
 	if (!buf->data)
 		goto err_buf;
 
@@ -235,14 +237,14 @@ void tty_audit_add_data(const struct tty_struct *tty, const void *data,
 	do {
 		size_t run;
 
-		run = N_TTY_BUF_SIZE - buf->valid;
+		run = TTY_AUDIT_BUF_SIZE - buf->valid;
 		if (run > size)
 			run = size;
 		memcpy(buf->data + buf->valid, data, run);
 		buf->valid += run;
 		data += run;
 		size -= run;
-		if (buf->valid == N_TTY_BUF_SIZE)
+		if (buf->valid == TTY_AUDIT_BUF_SIZE)
 			tty_audit_buf_push(buf);
 	} while (size != 0);
 	mutex_unlock(&buf->mutex);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 03/29] tty: caif: do not use N_TTY_BUF_SIZE
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 01/29] tty: convert "TTY Struct Flags" to an enum Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 02/29] tty: audit: do not use N_TTY_BUF_SIZE Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 14:27   ` Jakub Kicinski
  2025-02-20 11:15 ` [PATCH 04/29] tty: move N_TTY_BUF_SIZE to n_tty Jiri Slaby (SUSE)
                   ` (26 subsequent siblings)
  29 siblings, 1 reply; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev

N_TTY_BUF_SIZE -- as the name suggests -- is the N_TTY's buffer size.
There is no reason to couple that to caif's tty->receive_room. Use 4096
directly -- even though, it should be some sort of "SKB_MAX_ALLOC" or
alike. But definitely not N_TTY_BUF_SIZE.

N_TTY_BUF_SIZE is private and will be moved to n_tty.c later.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
---
 drivers/net/caif/caif_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c
index ed3a589def6b..e7d1b9301fde 100644
--- a/drivers/net/caif/caif_serial.c
+++ b/drivers/net/caif/caif_serial.c
@@ -344,7 +344,7 @@ static int ldisc_open(struct tty_struct *tty)
 	ser->tty = tty_kref_get(tty);
 	ser->dev = dev;
 	debugfs_init(ser, tty);
-	tty->receive_room = N_TTY_BUF_SIZE;
+	tty->receive_room = 4096;
 	tty->disc_data = ser;
 	set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
 	rtnl_lock();
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 04/29] tty: move N_TTY_BUF_SIZE to n_tty
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (2 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 03/29] tty: caif: " Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 05/29] tty: n_tty: use uint for space returned by tty_write_room() Jiri Slaby (SUSE)
                   ` (25 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

"N_TTY_BUF_SIZE" is private to n_tty and shall not be exposed to the
world. Definitely not in tty.h somewhere in the middle of "struct
tty_struct".

This is a remnant of moving "read_flags" to "struct n_tty_data" in
commit 3fe780b379fa ("TTY: move ldisc data from tty_struct: bitmaps").
But some cleanup was needed first (in previous patches).

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/n_tty.c | 2 ++
 include/linux/tty.h | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 5e9ca4376d68..2c5995019dd1 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -56,6 +56,8 @@
  */
 #define WAKEUP_CHARS 256
 
+#define N_TTY_BUF_SIZE 4096
+
 /*
  * This defines the low- and high-watermarks for throttling and
  * unthrottling the TTY driver.  These watermarks are used for
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 6bb4fb3845f0..0a46e4054dec 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -239,7 +239,6 @@ struct tty_struct {
 
 	struct list_head tty_files;
 
-#define N_TTY_BUF_SIZE 4096
 	struct work_struct SAK_work;
 } __randomize_layout;
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 05/29] tty: n_tty: use uint for space returned by tty_write_room()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (3 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 04/29] tty: move N_TTY_BUF_SIZE to n_tty Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 06/29] tty: n_tty: simplify process_output() Jiri Slaby (SUSE)
                   ` (24 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

tty_write_room() returns an "unsigned int". So in case some insane
driver (like my tty test driver) returns (legitimate) UINT_MAX from its
tty_operations::write_room(), n_tty is confused on several places.

For example, in process_output_block(), the result of tty_write_room()
is stored into (signed) "int". So this UINT_MAX suddenly becomes -1. And
that is extended to ssize_t and returned from process_output_block().
This causes a write() to such a node to receive -EPERM (which is -1).

Fix that by using proper "unsigned int" and proper "== 0" test. And
return 0 constant directly in that "if", so that it is immediately clear
what is returned ("space" equals to 0 at that point).

Similarly for process_output() and __process_echoes().

Note this does not fix any in-tree driver as of now.

If you want "Fixes: something", it would be commit 03b3b1a2405c ("tty:
make tty_operations::write_room return uint"). I intentionally do not
mark this patch by a real tag below.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/n_tty.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 2c5995019dd1..765d24268d75 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -488,7 +488,8 @@ static int do_output_char(u8 c, struct tty_struct *tty, int space)
 static int process_output(u8 c, struct tty_struct *tty)
 {
 	struct n_tty_data *ldata = tty->disc_data;
-	int	space, retval;
+	unsigned int space;
+	int retval;
 
 	mutex_lock(&ldata->output_lock);
 
@@ -524,16 +525,16 @@ static ssize_t process_output_block(struct tty_struct *tty,
 				    const u8 *buf, unsigned int nr)
 {
 	struct n_tty_data *ldata = tty->disc_data;
-	int	space;
-	int	i;
+	unsigned int space;
+	int i;
 	const u8 *cp;
 
 	mutex_lock(&ldata->output_lock);
 
 	space = tty_write_room(tty);
-	if (space <= 0) {
+	if (space == 0) {
 		mutex_unlock(&ldata->output_lock);
-		return space;
+		return 0;
 	}
 	if (nr > space)
 		nr = space;
@@ -698,7 +699,7 @@ static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail,
 static size_t __process_echoes(struct tty_struct *tty)
 {
 	struct n_tty_data *ldata = tty->disc_data;
-	int	space, old_space;
+	unsigned int space, old_space;
 	size_t tail;
 	u8 c;
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 06/29] tty: n_tty: simplify process_output()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (4 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 05/29] tty: n_tty: use uint for space returned by tty_write_room() Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 07/29] tty: n_tty: clean up process_output_block() Jiri Slaby (SUSE)
                   ` (23 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

Using guard(mutex), the function can be written in a much more efficient
way.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/n_tty.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 765d24268d75..df52aae5f71a 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -488,19 +488,13 @@ static int do_output_char(u8 c, struct tty_struct *tty, int space)
 static int process_output(u8 c, struct tty_struct *tty)
 {
 	struct n_tty_data *ldata = tty->disc_data;
-	unsigned int space;
-	int retval;
 
-	mutex_lock(&ldata->output_lock);
+	guard(mutex)(&ldata->output_lock);
 
-	space = tty_write_room(tty);
-	retval = do_output_char(c, tty, space);
-
-	mutex_unlock(&ldata->output_lock);
-	if (retval < 0)
+	if (do_output_char(c, tty, tty_write_room(tty)) < 0)
 		return -1;
-	else
-		return 0;
+
+	return 0;
 }
 
 /**
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 07/29] tty: n_tty: clean up process_output_block()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (5 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 06/29] tty: n_tty: simplify process_output() Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 08/29] tty: n_tty: drop n_tty_trace() Jiri Slaby (SUSE)
                   ` (22 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

* Use guard(mutex), which results in:
  - the function can return directly when "space == 0".
  - "i" can now be "unsigned" as it is no longer abused to hold a retval
    from tty->ops->write(). Note the compared-to "nr" is already
    "unsigned".
* The end label is now dubbed "do_write" as that is what happens there.
  Unlike the uncertain "break_out" name.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/n_tty.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index df52aae5f71a..5d172edbb03c 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -519,17 +519,15 @@ static ssize_t process_output_block(struct tty_struct *tty,
 				    const u8 *buf, unsigned int nr)
 {
 	struct n_tty_data *ldata = tty->disc_data;
-	unsigned int space;
-	int i;
+	unsigned int space, i;
 	const u8 *cp;
 
-	mutex_lock(&ldata->output_lock);
+	guard(mutex)(&ldata->output_lock);
 
 	space = tty_write_room(tty);
-	if (space == 0) {
-		mutex_unlock(&ldata->output_lock);
+	if (space == 0)
 		return 0;
-	}
+
 	if (nr > space)
 		nr = space;
 
@@ -541,18 +539,18 @@ static ssize_t process_output_block(struct tty_struct *tty,
 			if (O_ONLRET(tty))
 				ldata->column = 0;
 			if (O_ONLCR(tty))
-				goto break_out;
+				goto do_write;
 			ldata->canon_column = ldata->column;
 			break;
 		case '\r':
 			if (O_ONOCR(tty) && ldata->column == 0)
-				goto break_out;
+				goto do_write;
 			if (O_OCRNL(tty))
-				goto break_out;
+				goto do_write;
 			ldata->canon_column = ldata->column = 0;
 			break;
 		case '\t':
-			goto break_out;
+			goto do_write;
 		case '\b':
 			if (ldata->column > 0)
 				ldata->column--;
@@ -560,18 +558,15 @@ static ssize_t process_output_block(struct tty_struct *tty,
 		default:
 			if (!iscntrl(c)) {
 				if (O_OLCUC(tty))
-					goto break_out;
+					goto do_write;
 				if (!is_continuation(c, tty))
 					ldata->column++;
 			}
 			break;
 		}
 	}
-break_out:
-	i = tty->ops->write(tty, buf, i);
-
-	mutex_unlock(&ldata->output_lock);
-	return i;
+do_write:
+	return tty->ops->write(tty, buf, i);
 }
 
 static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail,
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 08/29] tty: n_tty: drop n_tty_trace()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (6 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 07/29] tty: n_tty: clean up process_output_block() Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 09/29] tty: n_tty: extract n_tty_continue_cookie() from n_tty_read() Jiri Slaby (SUSE)
                   ` (21 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

This n_tty_trace() is an always disabled debugging macro. It comes from
commit 32f13521ca68 ("n_tty: Line copy to user buffer in canonical
mode").

Drop it as it is dead for over a decade.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/n_tty.c | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 5d172edbb03c..43ba740792d9 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -81,14 +81,6 @@
 #define ECHO_BLOCK		256
 #define ECHO_DISCARD_WATERMARK	N_TTY_BUF_SIZE - (ECHO_BLOCK + 32)
 
-
-#undef N_TTY_TRACE
-#ifdef N_TTY_TRACE
-# define n_tty_trace(f, args...)	trace_printk(f, ##args)
-#else
-# define n_tty_trace(f, args...)	no_printk(f, ##args)
-#endif
-
 struct n_tty_data {
 	/* producer-published */
 	size_t read_head;
@@ -2026,9 +2018,6 @@ static bool canon_copy_from_read_buf(const struct tty_struct *tty, u8 **kbp,
 	tail = MASK(ldata->read_tail);
 	size = min_t(size_t, tail + n, N_TTY_BUF_SIZE);
 
-	n_tty_trace("%s: nr:%zu tail:%zu n:%zu size:%zu\n",
-		    __func__, *nr, tail, n, size);
-
 	eol = find_next_bit(ldata->read_flags, size, tail);
 	more = n - (size - tail);
 	if (eol == N_TTY_BUF_SIZE && more) {
@@ -2046,9 +2035,6 @@ static bool canon_copy_from_read_buf(const struct tty_struct *tty, u8 **kbp,
 	if (!found || read_buf(ldata, eol) != __DISABLED_CHAR)
 		n = c;
 
-	n_tty_trace("%s: eol:%zu found:%d n:%zu c:%zu tail:%zu more:%zu\n",
-		    __func__, eol, found, n, c, tail, more);
-
 	tty_copy(tty, *kbp, tail, n);
 	*kbp += n;
 	*nr -= n;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 09/29] tty: n_tty: extract n_tty_continue_cookie() from n_tty_read()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (7 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 08/29] tty: n_tty: drop n_tty_trace() Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 10/29] tty: n_tty: extract n_tty_wait_for_input() Jiri Slaby (SUSE)
                   ` (20 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

n_tty_read() is a very long function doing too much of different stuff.
Extract the "cookie" (continuation read) handling to a separate
function: n_tty_continue_cookie().

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/n_tty.c | 66 ++++++++++++++++++++++++---------------------
 1 file changed, 36 insertions(+), 30 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 43ba740792d9..88aa5f9cbe5e 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2111,6 +2111,39 @@ static int job_control(struct tty_struct *tty, struct file *file)
 	return __tty_check_change(tty, SIGTTIN);
 }
 
+/*
+ * We still hold the atomic_read_lock and the termios_rwsem, and can just
+ * continue to copy data.
+ */
+static ssize_t n_tty_continue_cookie(struct tty_struct *tty, u8 *kbuf,
+				   size_t nr, void **cookie)
+{
+	struct n_tty_data *ldata = tty->disc_data;
+	u8 *kb = kbuf;
+
+	if (ldata->icanon && !L_EXTPROC(tty)) {
+		/*
+		 * If we have filled the user buffer, see if we should skip an
+		 * EOF character before releasing the lock and returning done.
+		 */
+		if (!nr)
+			canon_skip_eof(ldata);
+		else if (canon_copy_from_read_buf(tty, &kb, &nr))
+			return kb - kbuf;
+	} else {
+		if (copy_from_read_buf(tty, &kb, &nr))
+			return kb - kbuf;
+	}
+
+	/* No more data - release locks and stop retries */
+	n_tty_kick_worker(tty);
+	n_tty_check_unthrottle(tty);
+	up_read(&tty->termios_rwsem);
+	mutex_unlock(&ldata->atomic_read_lock);
+	*cookie = NULL;
+
+	return kb - kbuf;
+}
 
 /**
  * n_tty_read		-	read function for tty
@@ -2144,36 +2177,9 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
 	bool packet;
 	size_t old_tail;
 
-	/*
-	 * Is this a continuation of a read started earler?
-	 *
-	 * If so, we still hold the atomic_read_lock and the
-	 * termios_rwsem, and can just continue to copy data.
-	 */
-	if (*cookie) {
-		if (ldata->icanon && !L_EXTPROC(tty)) {
-			/*
-			 * If we have filled the user buffer, see
-			 * if we should skip an EOF character before
-			 * releasing the lock and returning done.
-			 */
-			if (!nr)
-				canon_skip_eof(ldata);
-			else if (canon_copy_from_read_buf(tty, &kb, &nr))
-				return kb - kbuf;
-		} else {
-			if (copy_from_read_buf(tty, &kb, &nr))
-				return kb - kbuf;
-		}
-
-		/* No more data - release locks and stop retries */
-		n_tty_kick_worker(tty);
-		n_tty_check_unthrottle(tty);
-		up_read(&tty->termios_rwsem);
-		mutex_unlock(&ldata->atomic_read_lock);
-		*cookie = NULL;
-		return kb - kbuf;
-	}
+	/* Is this a continuation of a read started earlier? */
+	if (*cookie)
+		return n_tty_continue_cookie(tty, kbuf, nr, cookie);
 
 	retval = job_control(tty, file);
 	if (retval < 0)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 10/29] tty: n_tty: extract n_tty_wait_for_input()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (8 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 09/29] tty: n_tty: extract n_tty_continue_cookie() from n_tty_read() Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 11/29] tty: n_tty: move more_to_be_read to the end of n_tty_read() Jiri Slaby (SUSE)
                   ` (19 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

n_tty_read() is a very long function doing too much of different stuff.
Extract the "wait for input" to a separate function:
n_tty_wait_for_input(). It returns an error (< 0), no input (0), or has
potential input (1).

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/n_tty.c | 57 ++++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 26 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 88aa5f9cbe5e..0e3eb18490f0 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2145,6 +2145,33 @@ static ssize_t n_tty_continue_cookie(struct tty_struct *tty, u8 *kbuf,
 	return kb - kbuf;
 }
 
+static int n_tty_wait_for_input(struct tty_struct *tty, struct file *file,
+				struct wait_queue_entry *wait, long *timeout)
+{
+	if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
+		return -EIO;
+	if (tty_hung_up_p(file))
+		return 0;
+	/*
+	 * Abort readers for ttys which never actually get hung up.
+	 * See __tty_hangup().
+	 */
+	if (test_bit(TTY_HUPPING, &tty->flags))
+		return 0;
+	if (!*timeout)
+		return 0;
+	if (tty_io_nonblock(tty, file))
+		return -EAGAIN;
+	if (signal_pending(current))
+		return -ERESTARTSYS;
+
+	up_read(&tty->termios_rwsem);
+	*timeout = wait_woken(wait, TASK_INTERRUPTIBLE, *timeout);
+	down_read(&tty->termios_rwsem);
+
+	return 1;
+}
+
 /**
  * n_tty_read		-	read function for tty
  * @tty: tty device
@@ -2234,34 +2261,12 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
 			tty_buffer_flush_work(tty->port);
 			down_read(&tty->termios_rwsem);
 			if (!input_available_p(tty, 0)) {
-				if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
-					retval = -EIO;
+				int ret = n_tty_wait_for_input(tty, file, &wait,
+							       &timeout);
+				if (ret <= 0) {
+					retval = ret;
 					break;
 				}
-				if (tty_hung_up_p(file))
-					break;
-				/*
-				 * Abort readers for ttys which never actually
-				 * get hung up.  See __tty_hangup().
-				 */
-				if (test_bit(TTY_HUPPING, &tty->flags))
-					break;
-				if (!timeout)
-					break;
-				if (tty_io_nonblock(tty, file)) {
-					retval = -EAGAIN;
-					break;
-				}
-				if (signal_pending(current)) {
-					retval = -ERESTARTSYS;
-					break;
-				}
-				up_read(&tty->termios_rwsem);
-
-				timeout = wait_woken(&wait, TASK_INTERRUPTIBLE,
-						timeout);
-
-				down_read(&tty->termios_rwsem);
 				continue;
 			}
 		}
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 11/29] tty: n_tty: move more_to_be_read to the end of n_tty_read()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (9 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 10/29] tty: n_tty: extract n_tty_wait_for_input() Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 12/29] tty: tty_driver: move TTY macros to the top Jiri Slaby (SUSE)
                   ` (18 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

n_tty_read() contains "we need more data" handling deep in that
function. And there is also a label (more_to_be_read) as we handle this
situation from two places.

It makes more sense to have all "return"s accumulated at the end of
functions. And "goto" from multiple places there. Therefore, do this
with the "more_to_be_read" label in n_tty_read().

After this and the previous changes, n_tty_read() is now much more
easier to follow.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/n_tty.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 0e3eb18490f0..6af3f3a0b531 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2281,21 +2281,8 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
 				nr--;
 			}
 
-			/*
-			 * Copy data, and if there is more to be had
-			 * and we have nothing more to wait for, then
-			 * let's mark us for retries.
-			 *
-			 * NOTE! We return here with both the termios_sem
-			 * and atomic_read_lock still held, the retries
-			 * will release them when done.
-			 */
-			if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) {
-more_to_be_read:
-				remove_wait_queue(&tty->read_wait, &wait);
-				*cookie = cookie;
-				return kb - kbuf;
-			}
+			if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum)
+				goto more_to_be_read;
 		}
 
 		n_tty_check_unthrottle(tty);
@@ -2322,6 +2309,18 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
 		retval = kb - kbuf;
 
 	return retval;
+more_to_be_read:
+	/*
+	 * There is more to be had and we have nothing more to wait for, so
+	 * let's mark us for retries.
+	 *
+	 * NOTE! We return here with both the termios_sem and atomic_read_lock
+	 * still held, the retries will release them when done.
+	 */
+	remove_wait_queue(&tty->read_wait, &wait);
+	*cookie = cookie;
+
+	return kb - kbuf;
 }
 
 /**
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 12/29] tty: tty_driver: move TTY macros to the top
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (10 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 11/29] tty: n_tty: move more_to_be_read to the end of n_tty_read() Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 13/29] tty: tty_driver: convert "TTY Driver Flags" to an enum Jiri Slaby (SUSE)
                   ` (17 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

So that they can be referenced in structs once converted to enums (in
the next patches).

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 include/linux/tty_driver.h | 156 ++++++++++++++++++-------------------
 1 file changed, 78 insertions(+), 78 deletions(-)

diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index d4cdc089f6c3..f3be6d56e9e5 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -16,6 +16,84 @@ struct tty_driver;
 struct serial_icounter_struct;
 struct serial_struct;
 
+/**
+ * DOC: TTY Driver Flags
+ *
+ * TTY_DRIVER_RESET_TERMIOS
+ *	Requests the tty layer to reset the termios setting when the last
+ *	process has closed the device. Used for PTYs, in particular.
+ *
+ * TTY_DRIVER_REAL_RAW
+ *	Indicates that the driver will guarantee not to set any special
+ *	character handling flags if this is set for the tty:
+ *
+ *	``(IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR || !INPCK)``
+ *
+ *	That is, if there is no reason for the driver to
+ *	send notifications of parity and break characters up to the line
+ *	driver, it won't do so.  This allows the line driver to optimize for
+ *	this case if this flag is set.  (Note that there is also a promise, if
+ *	the above case is true, not to signal overruns, either.)
+ *
+ * TTY_DRIVER_DYNAMIC_DEV
+ *	The individual tty devices need to be registered with a call to
+ *	tty_register_device() when the device is found in the system and
+ *	unregistered with a call to tty_unregister_device() so the devices will
+ *	be show up properly in sysfs.  If not set, all &tty_driver.num entries
+ *	will be created by the tty core in sysfs when tty_register_driver() is
+ *	called.  This is to be used by drivers that have tty devices that can
+ *	appear and disappear while the main tty driver is registered with the
+ *	tty core.
+ *
+ * TTY_DRIVER_DEVPTS_MEM
+ *	Don't use the standard arrays (&tty_driver.ttys and
+ *	&tty_driver.termios), instead use dynamic memory keyed through the
+ *	devpts filesystem. This is only applicable to the PTY driver.
+ *
+ * TTY_DRIVER_HARDWARE_BREAK
+ *	Hardware handles break signals. Pass the requested timeout to the
+ *	&tty_operations.break_ctl instead of using a simple on/off interface.
+ *
+ * TTY_DRIVER_DYNAMIC_ALLOC
+ *	Do not allocate structures which are needed per line for this driver
+ *	(&tty_driver.ports) as it would waste memory. The driver will take
+ *	care. This is only applicable to the PTY driver.
+ *
+ * TTY_DRIVER_UNNUMBERED_NODE
+ *	Do not create numbered ``/dev`` nodes. For example, create
+ *	``/dev/ttyprintk`` and not ``/dev/ttyprintk0``. Applicable only when a
+ *	driver for a single tty device is being allocated.
+ */
+#define TTY_DRIVER_INSTALLED		0x0001
+#define TTY_DRIVER_RESET_TERMIOS	0x0002
+#define TTY_DRIVER_REAL_RAW		0x0004
+#define TTY_DRIVER_DYNAMIC_DEV		0x0008
+#define TTY_DRIVER_DEVPTS_MEM		0x0010
+#define TTY_DRIVER_HARDWARE_BREAK	0x0020
+#define TTY_DRIVER_DYNAMIC_ALLOC	0x0040
+#define TTY_DRIVER_UNNUMBERED_NODE	0x0080
+
+/* tty driver types */
+#define TTY_DRIVER_TYPE_SYSTEM		0x0001
+#define TTY_DRIVER_TYPE_CONSOLE		0x0002
+#define TTY_DRIVER_TYPE_SERIAL		0x0003
+#define TTY_DRIVER_TYPE_PTY		0x0004
+#define TTY_DRIVER_TYPE_SCC		0x0005	/* scc driver */
+#define TTY_DRIVER_TYPE_SYSCONS		0x0006
+
+/* system subtypes (magic, used by tty_io.c) */
+#define SYSTEM_TYPE_TTY			0x0001
+#define SYSTEM_TYPE_CONSOLE		0x0002
+#define SYSTEM_TYPE_SYSCONS		0x0003
+#define SYSTEM_TYPE_SYSPTMX		0x0004
+
+/* pty subtypes (magic, used by tty_io.c) */
+#define PTY_TYPE_MASTER			0x0001
+#define PTY_TYPE_SLAVE			0x0002
+
+/* serial subtype definitions */
+#define SERIAL_TYPE_NORMAL	1
+
 /**
  * struct tty_operations -- interface between driver and tty
  *
@@ -494,84 +572,6 @@ static inline void tty_set_operations(struct tty_driver *driver,
 	driver->ops = op;
 }
 
-/**
- * DOC: TTY Driver Flags
- *
- * TTY_DRIVER_RESET_TERMIOS
- *	Requests the tty layer to reset the termios setting when the last
- *	process has closed the device. Used for PTYs, in particular.
- *
- * TTY_DRIVER_REAL_RAW
- *	Indicates that the driver will guarantee not to set any special
- *	character handling flags if this is set for the tty:
- *
- *	``(IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR || !INPCK)``
- *
- *	That is, if there is no reason for the driver to
- *	send notifications of parity and break characters up to the line
- *	driver, it won't do so.  This allows the line driver to optimize for
- *	this case if this flag is set.  (Note that there is also a promise, if
- *	the above case is true, not to signal overruns, either.)
- *
- * TTY_DRIVER_DYNAMIC_DEV
- *	The individual tty devices need to be registered with a call to
- *	tty_register_device() when the device is found in the system and
- *	unregistered with a call to tty_unregister_device() so the devices will
- *	be show up properly in sysfs.  If not set, all &tty_driver.num entries
- *	will be created by the tty core in sysfs when tty_register_driver() is
- *	called.  This is to be used by drivers that have tty devices that can
- *	appear and disappear while the main tty driver is registered with the
- *	tty core.
- *
- * TTY_DRIVER_DEVPTS_MEM
- *	Don't use the standard arrays (&tty_driver.ttys and
- *	&tty_driver.termios), instead use dynamic memory keyed through the
- *	devpts filesystem. This is only applicable to the PTY driver.
- *
- * TTY_DRIVER_HARDWARE_BREAK
- *	Hardware handles break signals. Pass the requested timeout to the
- *	&tty_operations.break_ctl instead of using a simple on/off interface.
- *
- * TTY_DRIVER_DYNAMIC_ALLOC
- *	Do not allocate structures which are needed per line for this driver
- *	(&tty_driver.ports) as it would waste memory. The driver will take
- *	care. This is only applicable to the PTY driver.
- *
- * TTY_DRIVER_UNNUMBERED_NODE
- *	Do not create numbered ``/dev`` nodes. For example, create
- *	``/dev/ttyprintk`` and not ``/dev/ttyprintk0``. Applicable only when a
- *	driver for a single tty device is being allocated.
- */
-#define TTY_DRIVER_INSTALLED		0x0001
-#define TTY_DRIVER_RESET_TERMIOS	0x0002
-#define TTY_DRIVER_REAL_RAW		0x0004
-#define TTY_DRIVER_DYNAMIC_DEV		0x0008
-#define TTY_DRIVER_DEVPTS_MEM		0x0010
-#define TTY_DRIVER_HARDWARE_BREAK	0x0020
-#define TTY_DRIVER_DYNAMIC_ALLOC	0x0040
-#define TTY_DRIVER_UNNUMBERED_NODE	0x0080
-
-/* tty driver types */
-#define TTY_DRIVER_TYPE_SYSTEM		0x0001
-#define TTY_DRIVER_TYPE_CONSOLE		0x0002
-#define TTY_DRIVER_TYPE_SERIAL		0x0003
-#define TTY_DRIVER_TYPE_PTY		0x0004
-#define TTY_DRIVER_TYPE_SCC		0x0005	/* scc driver */
-#define TTY_DRIVER_TYPE_SYSCONS		0x0006
-
-/* system subtypes (magic, used by tty_io.c) */
-#define SYSTEM_TYPE_TTY			0x0001
-#define SYSTEM_TYPE_CONSOLE		0x0002
-#define SYSTEM_TYPE_SYSCONS		0x0003
-#define SYSTEM_TYPE_SYSPTMX		0x0004
-
-/* pty subtypes (magic, used by tty_io.c) */
-#define PTY_TYPE_MASTER			0x0001
-#define PTY_TYPE_SLAVE			0x0002
-
-/* serial subtype definitions */
-#define SERIAL_TYPE_NORMAL	1
-
 int tty_register_driver(struct tty_driver *driver);
 void tty_unregister_driver(struct tty_driver *driver);
 struct device *tty_register_device(struct tty_driver *driver, unsigned index,
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 13/29] tty: tty_driver: convert "TTY Driver Flags" to an enum
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (11 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 12/29] tty: tty_driver: move TTY macros to the top Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 14/29] tty: tty_driver: document both {,__}tty_alloc_driver() properly Jiri Slaby (SUSE)
                   ` (16 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

Convert TTY_DRIVER_* macros (flags) to an enum. This allows for easier
kernel-doc (the comment needed fine tuning), grouping of these nicely,
and proper checking.

Given these are flags, define them using modern BIT() instead of hex
constants.

It turns out (thanks, kernel-doc checker) that internal
TTY_DRIVER_INSTALLED was undocumented. Fix that too.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 Documentation/driver-api/tty/tty_driver.rst |  2 +-
 include/linux/tty_driver.h                  | 40 ++++++++++++---------
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/Documentation/driver-api/tty/tty_driver.rst b/Documentation/driver-api/tty/tty_driver.rst
index cc529f863406..f6cbffdb6e01 100644
--- a/Documentation/driver-api/tty/tty_driver.rst
+++ b/Documentation/driver-api/tty/tty_driver.rst
@@ -35,7 +35,7 @@ Here comes the documentation of flags accepted by tty_alloc_driver() (or
 __tty_alloc_driver()):
 
 .. kernel-doc:: include/linux/tty_driver.h
-   :doc: TTY Driver Flags
+   :identifiers: tty_driver_flag
 
 ----
 
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index f3be6d56e9e5..d0d940236580 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -17,13 +17,19 @@ struct serial_icounter_struct;
 struct serial_struct;
 
 /**
- * DOC: TTY Driver Flags
+ * enum tty_driver_flag -- TTY Driver Flags
  *
- * TTY_DRIVER_RESET_TERMIOS
+ * These are flags passed to tty_alloc_driver().
+ *
+ * @TTY_DRIVER_INSTALLED:
+ *	Whether this driver was succesfully installed. This is a tty internal
+ *	flag. Do not touch.
+ *
+ * @TTY_DRIVER_RESET_TERMIOS:
  *	Requests the tty layer to reset the termios setting when the last
  *	process has closed the device. Used for PTYs, in particular.
  *
- * TTY_DRIVER_REAL_RAW
+ * @TTY_DRIVER_REAL_RAW:
  *	Indicates that the driver will guarantee not to set any special
  *	character handling flags if this is set for the tty:
  *
@@ -35,7 +41,7 @@ struct serial_struct;
  *	this case if this flag is set.  (Note that there is also a promise, if
  *	the above case is true, not to signal overruns, either.)
  *
- * TTY_DRIVER_DYNAMIC_DEV
+ * @TTY_DRIVER_DYNAMIC_DEV:
  *	The individual tty devices need to be registered with a call to
  *	tty_register_device() when the device is found in the system and
  *	unregistered with a call to tty_unregister_device() so the devices will
@@ -45,33 +51,35 @@ struct serial_struct;
  *	appear and disappear while the main tty driver is registered with the
  *	tty core.
  *
- * TTY_DRIVER_DEVPTS_MEM
+ * @TTY_DRIVER_DEVPTS_MEM:
  *	Don't use the standard arrays (&tty_driver.ttys and
  *	&tty_driver.termios), instead use dynamic memory keyed through the
  *	devpts filesystem. This is only applicable to the PTY driver.
  *
- * TTY_DRIVER_HARDWARE_BREAK
+ * @TTY_DRIVER_HARDWARE_BREAK:
  *	Hardware handles break signals. Pass the requested timeout to the
  *	&tty_operations.break_ctl instead of using a simple on/off interface.
  *
- * TTY_DRIVER_DYNAMIC_ALLOC
+ * @TTY_DRIVER_DYNAMIC_ALLOC:
  *	Do not allocate structures which are needed per line for this driver
  *	(&tty_driver.ports) as it would waste memory. The driver will take
  *	care. This is only applicable to the PTY driver.
  *
- * TTY_DRIVER_UNNUMBERED_NODE
+ * @TTY_DRIVER_UNNUMBERED_NODE:
  *	Do not create numbered ``/dev`` nodes. For example, create
  *	``/dev/ttyprintk`` and not ``/dev/ttyprintk0``. Applicable only when a
  *	driver for a single tty device is being allocated.
  */
-#define TTY_DRIVER_INSTALLED		0x0001
-#define TTY_DRIVER_RESET_TERMIOS	0x0002
-#define TTY_DRIVER_REAL_RAW		0x0004
-#define TTY_DRIVER_DYNAMIC_DEV		0x0008
-#define TTY_DRIVER_DEVPTS_MEM		0x0010
-#define TTY_DRIVER_HARDWARE_BREAK	0x0020
-#define TTY_DRIVER_DYNAMIC_ALLOC	0x0040
-#define TTY_DRIVER_UNNUMBERED_NODE	0x0080
+enum tty_driver_flag {
+	TTY_DRIVER_INSTALLED		= BIT(0),
+	TTY_DRIVER_RESET_TERMIOS	= BIT(1),
+	TTY_DRIVER_REAL_RAW		= BIT(2),
+	TTY_DRIVER_DYNAMIC_DEV		= BIT(3),
+	TTY_DRIVER_DEVPTS_MEM		= BIT(4),
+	TTY_DRIVER_HARDWARE_BREAK	= BIT(5),
+	TTY_DRIVER_DYNAMIC_ALLOC	= BIT(6),
+	TTY_DRIVER_UNNUMBERED_NODE	= BIT(7),
+};
 
 /* tty driver types */
 #define TTY_DRIVER_TYPE_SYSTEM		0x0001
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 14/29] tty: tty_driver: document both {,__}tty_alloc_driver() properly
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (12 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 13/29] tty: tty_driver: convert "TTY Driver Flags" to an enum Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 15/29] tty: tty_driver: introduce TTY driver sub/types enums Jiri Slaby (SUSE)
                   ` (15 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

__tty_alloc_driver()'s kernel-doc needed some care: describe the return
value using the standard "Returns:", and use the new enum tty_driver_flag
for @flags.

Then, the tty_alloc_driver() macro was undocumented, but referenced many
times in the docs. Copy the docs from the above (except the @owner
parameter, obviously).

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 Documentation/driver-api/tty/tty_driver.rst | 2 ++
 drivers/tty/tty_io.c                        | 8 +++++---
 include/linux/tty_driver.h                  | 8 +++++++-
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/Documentation/driver-api/tty/tty_driver.rst b/Documentation/driver-api/tty/tty_driver.rst
index f6cbffdb6e01..7138222a70f2 100644
--- a/Documentation/driver-api/tty/tty_driver.rst
+++ b/Documentation/driver-api/tty/tty_driver.rst
@@ -25,6 +25,8 @@ freed.
 For reference, both allocation and deallocation functions are explained here in
 detail:
 
+.. kernel-doc:: include/linux/tty_driver.h
+   :identifiers: tty_alloc_driver
 .. kernel-doc:: drivers/tty/tty_io.c
    :identifiers: __tty_alloc_driver tty_driver_kref_put
 
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 449dbd216460..ca9b7d7bad2b 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3329,10 +3329,12 @@ EXPORT_SYMBOL(tty_unregister_device);
  * __tty_alloc_driver - allocate tty driver
  * @lines: count of lines this driver can handle at most
  * @owner: module which is responsible for this driver
- * @flags: some of %TTY_DRIVER_ flags, will be set in driver->flags
+ * @flags: some of enum tty_driver_flag, will be set in driver->flags
  *
- * This should not be called directly, some of the provided macros should be
- * used instead. Use IS_ERR() and friends on @retval.
+ * This should not be called directly, tty_alloc_driver() should be used
+ * instead.
+ *
+ * Returns: struct tty_driver or a PTR-encoded error (use IS_ERR() and friends).
  */
 struct tty_driver *__tty_alloc_driver(unsigned int lines, struct module *owner,
 		unsigned long flags)
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index d0d940236580..0fe38befa1b8 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -564,7 +564,13 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line);
 
 void tty_driver_kref_put(struct tty_driver *driver);
 
-/* Use TTY_DRIVER_* flags below */
+/**
+ * tty_alloc_driver - allocate tty driver
+ * @lines: count of lines this driver can handle at most
+ * @flags: some of enum tty_driver_flag, will be set in driver->flags
+ *
+ * Returns: struct tty_driver or a PTR-encoded error (use IS_ERR() and friends).
+ */
 #define tty_alloc_driver(lines, flags) \
 		__tty_alloc_driver(lines, THIS_MODULE, flags)
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 15/29] tty: tty_driver: introduce TTY driver sub/types enums
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (13 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 14/29] tty: tty_driver: document both {,__}tty_alloc_driver() properly Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 16/29] tty: serdev: drop serdev_controller_ops::write_room() Jiri Slaby (SUSE)
                   ` (14 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

Convert TTY_DRIVER_TYPE_*, and subtype macros to two enums:
tty_driver_type and tty_driver_subtype. This allows for easier
kernel-doc (later), grouping of these nicely, and proper checking.

The tty_driver's ::type and ::subtype now use these enums instead of
bare "short".

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 include/linux/tty_driver.h | 42 +++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index 0fe38befa1b8..188ee9b768eb 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -81,26 +81,26 @@ enum tty_driver_flag {
 	TTY_DRIVER_UNNUMBERED_NODE	= BIT(7),
 };
 
-/* tty driver types */
-#define TTY_DRIVER_TYPE_SYSTEM		0x0001
-#define TTY_DRIVER_TYPE_CONSOLE		0x0002
-#define TTY_DRIVER_TYPE_SERIAL		0x0003
-#define TTY_DRIVER_TYPE_PTY		0x0004
-#define TTY_DRIVER_TYPE_SCC		0x0005	/* scc driver */
-#define TTY_DRIVER_TYPE_SYSCONS		0x0006
+enum tty_driver_type {
+	TTY_DRIVER_TYPE_SYSTEM,
+	TTY_DRIVER_TYPE_CONSOLE,
+	TTY_DRIVER_TYPE_SERIAL,
+	TTY_DRIVER_TYPE_PTY,
+	TTY_DRIVER_TYPE_SCC,
+	TTY_DRIVER_TYPE_SYSCONS,
+};
 
-/* system subtypes (magic, used by tty_io.c) */
-#define SYSTEM_TYPE_TTY			0x0001
-#define SYSTEM_TYPE_CONSOLE		0x0002
-#define SYSTEM_TYPE_SYSCONS		0x0003
-#define SYSTEM_TYPE_SYSPTMX		0x0004
+enum tty_driver_subtype {
+	SYSTEM_TYPE_TTY = 1,
+	SYSTEM_TYPE_CONSOLE,
+	SYSTEM_TYPE_SYSCONS,
+	SYSTEM_TYPE_SYSPTMX,
 
-/* pty subtypes (magic, used by tty_io.c) */
-#define PTY_TYPE_MASTER			0x0001
-#define PTY_TYPE_SLAVE			0x0002
+	PTY_TYPE_MASTER = 1,
+	PTY_TYPE_SLAVE,
 
-/* serial subtype definitions */
-#define SERIAL_TYPE_NORMAL	1
+	SERIAL_TYPE_NORMAL = 1,
+};
 
 /**
  * struct tty_operations -- interface between driver and tty
@@ -500,8 +500,8 @@ struct tty_operations {
  * @major: major /dev device number (zero for autoassignment)
  * @minor_start: the first minor /dev device number
  * @num: number of devices allocated
- * @type: type of tty driver (%TTY_DRIVER_TYPE_)
- * @subtype: subtype of tty driver (%SYSTEM_TYPE_, %PTY_TYPE_, %SERIAL_TYPE_)
+ * @type: type of tty driver (enum tty_driver_type)
+ * @subtype: subtype of tty driver (enum tty_driver_subtype)
  * @init_termios: termios to set to each tty initially (e.g. %tty_std_termios)
  * @flags: tty driver flags (%TTY_DRIVER_)
  * @proc_entry: proc fs entry, used internally
@@ -533,8 +533,8 @@ struct tty_driver {
 	int	major;
 	int	minor_start;
 	unsigned int	num;
-	short	type;
-	short	subtype;
+	enum tty_driver_type type;
+	enum tty_driver_subtype subtype;
 	struct ktermios init_termios;
 	unsigned long	flags;
 	struct proc_dir_entry *proc_entry;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 16/29] tty: serdev: drop serdev_controller_ops::write_room()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (14 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 15/29] tty: tty_driver: introduce TTY driver sub/types enums Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 17/29] tty: moxa: drop version dump to logs Jiri Slaby (SUSE)
                   ` (13 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Rob Herring

In particular, serdev_device_write_room() is not called, so the whole
serdev's write_room() can go.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Rob Herring <robh@kernel.org>
---
 drivers/tty/serdev/core.c           | 11 -----------
 drivers/tty/serdev/serdev-ttyport.c |  9 ---------
 include/linux/serdev.h              |  6 ------
 3 files changed, 26 deletions(-)

diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
index ebf0bbc2cff2..eb2a2e58fe78 100644
--- a/drivers/tty/serdev/core.c
+++ b/drivers/tty/serdev/core.c
@@ -316,17 +316,6 @@ void serdev_device_write_flush(struct serdev_device *serdev)
 }
 EXPORT_SYMBOL_GPL(serdev_device_write_flush);
 
-int serdev_device_write_room(struct serdev_device *serdev)
-{
-	struct serdev_controller *ctrl = serdev->ctrl;
-
-	if (!ctrl || !ctrl->ops->write_room)
-		return 0;
-
-	return serdev->ctrl->ops->write_room(ctrl);
-}
-EXPORT_SYMBOL_GPL(serdev_device_write_room);
-
 unsigned int serdev_device_set_baudrate(struct serdev_device *serdev, unsigned int speed)
 {
 	struct serdev_controller *ctrl = serdev->ctrl;
diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c
index 3d7ae7fa5018..bab1b143b8a6 100644
--- a/drivers/tty/serdev/serdev-ttyport.c
+++ b/drivers/tty/serdev/serdev-ttyport.c
@@ -92,14 +92,6 @@ static void ttyport_write_flush(struct serdev_controller *ctrl)
 	tty_driver_flush_buffer(tty);
 }
 
-static int ttyport_write_room(struct serdev_controller *ctrl)
-{
-	struct serport *serport = serdev_controller_get_drvdata(ctrl);
-	struct tty_struct *tty = serport->tty;
-
-	return tty_write_room(tty);
-}
-
 static int ttyport_open(struct serdev_controller *ctrl)
 {
 	struct serport *serport = serdev_controller_get_drvdata(ctrl);
@@ -259,7 +251,6 @@ static int ttyport_break_ctl(struct serdev_controller *ctrl, unsigned int break_
 static const struct serdev_controller_ops ctrl_ops = {
 	.write_buf = ttyport_write_buf,
 	.write_flush = ttyport_write_flush,
-	.write_room = ttyport_write_room,
 	.open = ttyport_open,
 	.close = ttyport_close,
 	.set_flow_control = ttyport_set_flow_control,
diff --git a/include/linux/serdev.h b/include/linux/serdev.h
index ff78efc1f60d..34562eb99931 100644
--- a/include/linux/serdev.h
+++ b/include/linux/serdev.h
@@ -84,7 +84,6 @@ enum serdev_parity {
 struct serdev_controller_ops {
 	ssize_t (*write_buf)(struct serdev_controller *, const u8 *, size_t);
 	void (*write_flush)(struct serdev_controller *);
-	int (*write_room)(struct serdev_controller *);
 	int (*open)(struct serdev_controller *);
 	void (*close)(struct serdev_controller *);
 	void (*set_flow_control)(struct serdev_controller *, bool);
@@ -212,7 +211,6 @@ int serdev_device_break_ctl(struct serdev_device *serdev, int break_state);
 void serdev_device_write_wakeup(struct serdev_device *);
 ssize_t serdev_device_write(struct serdev_device *, const u8 *, size_t, long);
 void serdev_device_write_flush(struct serdev_device *);
-int serdev_device_write_room(struct serdev_device *);
 
 /*
  * serdev device driver functions
@@ -273,10 +271,6 @@ static inline ssize_t serdev_device_write(struct serdev_device *sdev,
 	return -ENODEV;
 }
 static inline void serdev_device_write_flush(struct serdev_device *sdev) {}
-static inline int serdev_device_write_room(struct serdev_device *sdev)
-{
-	return 0;
-}
 
 #define serdev_device_driver_register(x)
 #define serdev_device_driver_unregister(x)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 17/29] tty: moxa: drop version dump to logs
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (15 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 16/29] tty: serdev: drop serdev_controller_ops::write_room() Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 18/29] tty: moxa: drop ISA support Jiri Slaby (SUSE)
                   ` (12 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

The arbitrary MOXA_VERSION is dumped to the logs when the driver is
loaded. Avoid this as a driver should be silent unless something breaks.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/moxa.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index ebaada8db929..2b75ca12cbc9 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -347,8 +347,6 @@
 #define	MX_PARMARK	0xA0
 #define	MX_PARSPACE	0x20
 
-#define MOXA_VERSION		"6.0k"
-
 #define MOXA_FW_HDRLEN		32
 
 #define MOXAMAJOR		172
@@ -1327,9 +1325,6 @@ static int __init moxa_init(void)
 	struct moxa_board_conf *brd = moxa_boards;
 	unsigned int i;
 
-	printk(KERN_INFO "MOXA Intellio family driver version %s\n",
-			MOXA_VERSION);
-
 	tty_port_init(&moxa_service_port);
 
 	moxaDriver = tty_alloc_driver(MAX_PORTS + 1,
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 18/29] tty: moxa: drop ISA support
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (16 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 17/29] tty: moxa: drop version dump to logs Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 19/29] tty: moxa: carve out special ioctls and extra tty_port Jiri Slaby (SUSE)
                   ` (11 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

I doubt anyone actually uses this driver (unlike mxser.c and serial
moxa driven devices). Even less there is anyone with a moxa ISA card.
The newer mxser dropped the support for ISA in 2021. Let this moxa
follow now.

Good diet.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/Kconfig |   2 +-
 drivers/tty/moxa.c  | 100 +++-----------------------------------------
 2 files changed, 6 insertions(+), 96 deletions(-)

diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 63a494d36a1f..0f3f55372c11 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -210,7 +210,7 @@ config SERIAL_NONSTANDARD
 
 config MOXA_INTELLIO
 	tristate "Moxa Intellio support"
-	depends on SERIAL_NONSTANDARD && (ISA || EISA || PCI)
+	depends on SERIAL_NONSTANDARD && PCI
 	select FW_LOADER
 	help
 	  Say Y here if you have a Moxa Intellio multiport serial card.
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index 2b75ca12cbc9..a753afcb53b5 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -355,33 +355,21 @@
 #define MAX_PORTS_PER_BOARD	32	/* Don't change this value */
 #define MAX_PORTS		(MAX_BOARDS * MAX_PORTS_PER_BOARD)
 
-#define MOXA_IS_320(brd) ((brd)->boardType == MOXA_BOARD_C320_ISA || \
-		(brd)->boardType == MOXA_BOARD_C320_PCI)
-
-/*
- *    Define the Moxa PCI vendor and device IDs.
- */
-#define MOXA_BUS_TYPE_ISA	0
-#define MOXA_BUS_TYPE_PCI	1
+#define MOXA_IS_320(brd)	((brd)->boardType == MOXA_BOARD_C320_PCI)
 
 enum {
 	MOXA_BOARD_C218_PCI = 1,
-	MOXA_BOARD_C218_ISA,
 	MOXA_BOARD_C320_PCI,
-	MOXA_BOARD_C320_ISA,
 	MOXA_BOARD_CP204J,
 };
 
 static char *moxa_brdname[] =
 {
 	"C218 Turbo PCI series",
-	"C218 Turbo ISA series",
 	"C320 Turbo PCI series",
-	"C320 Turbo ISA series",
 	"CP-204J series",
 };
 
-#ifdef CONFIG_PCI
 static const struct pci_device_id moxa_pcibrds[] = {
 	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C218),
 		.driver_data = MOXA_BOARD_C218_PCI },
@@ -392,14 +380,12 @@ static const struct pci_device_id moxa_pcibrds[] = {
 	{ 0 }
 };
 MODULE_DEVICE_TABLE(pci, moxa_pcibrds);
-#endif /* CONFIG_PCI */
 
 struct moxa_port;
 
 static struct moxa_board_conf {
 	int boardType;
 	int numPorts;
-	int busType;
 
 	unsigned int ready;
 
@@ -459,9 +445,6 @@ static unsigned int moxaLowWaterChk;
 static DEFINE_MUTEX(moxa_openlock);
 static DEFINE_SPINLOCK(moxa_lock);
 
-static unsigned long baseaddr[MAX_BOARDS];
-static unsigned int type[MAX_BOARDS];
-static unsigned int numports[MAX_BOARDS];
 static struct tty_port moxa_service_port;
 
 MODULE_AUTHOR("William Chen");
@@ -471,13 +454,6 @@ MODULE_FIRMWARE("c218tunx.cod");
 MODULE_FIRMWARE("cp204unx.cod");
 MODULE_FIRMWARE("c320tunx.cod");
 
-module_param_array(type, uint, NULL, 0);
-MODULE_PARM_DESC(type, "card type: C218=2, C320=4");
-module_param_hw_array(baseaddr, ulong, ioport, NULL, 0);
-MODULE_PARM_DESC(baseaddr, "base address");
-module_param_array(numports, uint, NULL, 0);
-MODULE_PARM_DESC(numports, "numports (ignored for C218)");
-
 module_param(ttymajor, int, 0);
 
 /*
@@ -723,7 +699,6 @@ static DEFINE_TIMER(moxaTimer, moxa_poll);
 static int moxa_check_fw_model(struct moxa_board_conf *brd, u8 model)
 {
 	switch (brd->boardType) {
-	case MOXA_BOARD_C218_ISA:
 	case MOXA_BOARD_C218_PCI:
 		if (model != 1)
 			goto err;
@@ -767,7 +742,6 @@ static int moxa_load_bios(struct moxa_board_conf *brd, const u8 *buf,
 	msleep(2000);
 
 	switch (brd->boardType) {
-	case MOXA_BOARD_C218_ISA:
 	case MOXA_BOARD_C218_PCI:
 		tmp = readw(baseAddr + C218_key);
 		if (tmp != C218_KeyCode)
@@ -831,7 +805,6 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
 
 	switch (brd->boardType) {
 	case MOXA_BOARD_CP204J:
-	case MOXA_BOARD_C218_ISA:
 	case MOXA_BOARD_C218_PCI:
 		key = C218_key;
 		loadbuf = C218_LoadBuf;
@@ -896,15 +869,9 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
 		return -EIO;
 
 	if (MOXA_IS_320(brd)) {
-		if (brd->busType == MOXA_BUS_TYPE_PCI) {	/* ASIC board */
-			writew(0x3800, baseAddr + TMS320_PORT1);
-			writew(0x3900, baseAddr + TMS320_PORT2);
-			writew(28499, baseAddr + TMS320_CLOCK);
-		} else {
-			writew(0x3200, baseAddr + TMS320_PORT1);
-			writew(0x3400, baseAddr + TMS320_PORT2);
-			writew(19999, baseAddr + TMS320_CLOCK);
-		}
+		writew(0x3800, baseAddr + TMS320_PORT1);
+		writew(0x3900, baseAddr + TMS320_PORT2);
+		writew(28499, baseAddr + TMS320_CLOCK);
 	}
 	writew(1, baseAddr + Disable_IRQ);
 	writew(0, baseAddr + Magic_no);
@@ -955,7 +922,6 @@ static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr,
 		return retval;
 
 	switch (brd->boardType) {
-	case MOXA_BOARD_C218_ISA:
 	case MOXA_BOARD_C218_PCI:
 	case MOXA_BOARD_CP204J:
 		port = brd->ports;
@@ -1139,7 +1105,6 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
 	}
 
 	switch (brd->boardType) {
-	case MOXA_BOARD_C218_ISA:
 	case MOXA_BOARD_C218_PCI:
 		file = "c218tunx.cod";
 		break;
@@ -1225,7 +1190,6 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
 	kfree(brd->ports);
 }
 
-#ifdef CONFIG_PCI
 static int moxa_pci_probe(struct pci_dev *pdev,
 		const struct pci_device_id *ent)
 {
@@ -1268,7 +1232,6 @@ static int moxa_pci_probe(struct pci_dev *pdev,
 
 	board->boardType = board_type;
 	switch (board_type) {
-	case MOXA_BOARD_C218_ISA:
 	case MOXA_BOARD_C218_PCI:
 		board->numPorts = 8;
 		break;
@@ -1280,7 +1243,6 @@ static int moxa_pci_probe(struct pci_dev *pdev,
 		board->numPorts = 0;
 		break;
 	}
-	board->busType = MOXA_BUS_TYPE_PCI;
 
 	retval = moxa_init_board(board, &pdev->dev);
 	if (retval)
@@ -1316,14 +1278,10 @@ static struct pci_driver moxa_pci_driver = {
 	.probe = moxa_pci_probe,
 	.remove = moxa_pci_remove
 };
-#endif /* CONFIG_PCI */
 
 static int __init moxa_init(void)
 {
-	unsigned int isabrds = 0;
 	int retval = 0;
-	struct moxa_board_conf *brd = moxa_boards;
-	unsigned int i;
 
 	tty_port_init(&moxa_service_port);
 
@@ -1352,64 +1310,16 @@ static int __init moxa_init(void)
 		return -1;
 	}
 
-	/* Find the boards defined from module args. */
-
-	for (i = 0; i < MAX_BOARDS; i++) {
-		if (!baseaddr[i])
-			break;
-		if (type[i] == MOXA_BOARD_C218_ISA ||
-				type[i] == MOXA_BOARD_C320_ISA) {
-			pr_debug("Moxa board %2d: %s board(baseAddr=%lx)\n",
-					isabrds + 1, moxa_brdname[type[i] - 1],
-					baseaddr[i]);
-			brd->boardType = type[i];
-			brd->numPorts = type[i] == MOXA_BOARD_C218_ISA ? 8 :
-					numports[i];
-			brd->busType = MOXA_BUS_TYPE_ISA;
-			brd->basemem = ioremap(baseaddr[i], 0x4000);
-			if (!brd->basemem) {
-				printk(KERN_ERR "MOXA: can't remap %lx\n",
-						baseaddr[i]);
-				continue;
-			}
-			if (moxa_init_board(brd, NULL)) {
-				iounmap(brd->basemem);
-				brd->basemem = NULL;
-				continue;
-			}
-
-			printk(KERN_INFO "MOXA isa board found at 0x%.8lx and "
-					"ready (%u ports, firmware loaded)\n",
-					baseaddr[i], brd->numPorts);
-
-			brd++;
-			isabrds++;
-		}
-	}
-
-#ifdef CONFIG_PCI
 	retval = pci_register_driver(&moxa_pci_driver);
-	if (retval) {
+	if (retval)
 		printk(KERN_ERR "Can't register MOXA pci driver!\n");
-		if (isabrds)
-			retval = 0;
-	}
-#endif
 
 	return retval;
 }
 
 static void __exit moxa_exit(void)
 {
-	unsigned int i;
-
-#ifdef CONFIG_PCI
 	pci_unregister_driver(&moxa_pci_driver);
-#endif
-
-	for (i = 0; i < MAX_BOARDS; i++) /* ISA boards */
-		if (moxa_boards[i].ready)
-			moxa_board_deinit(&moxa_boards[i]);
 
 	del_timer_sync(&moxaTimer);
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 19/29] tty: moxa: carve out special ioctls and extra tty_port
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (17 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 18/29] tty: moxa: drop ISA support Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:15 ` [PATCH 20/29] tty: srmcons: fix retval from srmcons_init() Jiri Slaby (SUSE)
                   ` (10 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

These ioctls are undocumented and not exposed -- they are defined
locally. Given they need a special tty_port just for them, this is very
ugly. So drop this whole functionality. It is barely used for something
real. (And if it is, we'd need a common functionality to all drivers.)

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/moxa.c | 146 +--------------------------------------------
 1 file changed, 1 insertion(+), 145 deletions(-)

diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index a753afcb53b5..1348e2214b81 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -43,15 +43,6 @@
 #include <linux/ratelimit.h>
 
 #include <asm/io.h>
-#include <linux/uaccess.h>
-
-#define	MOXA			0x400
-#define MOXA_GET_IQUEUE		(MOXA + 1)	/* get input buffered count */
-#define MOXA_GET_OQUEUE		(MOXA + 2)	/* get output buffered count */
-#define MOXA_GETDATACOUNT       (MOXA + 23)
-#define MOXA_GET_IOQUEUE	(MOXA + 27)
-#define MOXA_FLUSH_QUEUE	(MOXA + 28)
-#define MOXA_GETMSTATUS         (MOXA + 65)
 
 /*
  *    System Configuration
@@ -397,19 +388,6 @@ static struct moxa_board_conf {
 	void __iomem *intTable;
 } moxa_boards[MAX_BOARDS];
 
-struct mxser_mstatus {
-	tcflag_t cflag;
-	int cts;
-	int dsr;
-	int ri;
-	int dcd;
-};
-
-struct moxaq_str {
-	int inq;
-	int outq;
-};
-
 struct moxa_port {
 	struct tty_port port;
 	struct moxa_board_conf *board;
@@ -424,12 +402,6 @@ struct moxa_port {
 	u8 lowChkFlag;
 };
 
-struct mon_str {
-	int tick;
-	int rxcnt[MAX_PORTS];
-	int txcnt[MAX_PORTS];
-};
-
 /* statusflags */
 #define TXSTOPPED	1
 #define LOWWAIT 	2
@@ -439,14 +411,11 @@ struct mon_str {
 #define WAKEUP_CHARS		256
 
 static int ttymajor = MOXAMAJOR;
-static struct mon_str moxaLog;
 static unsigned int moxaFuncTout = HZ / 2;
 static unsigned int moxaLowWaterChk;
 static DEFINE_MUTEX(moxa_openlock);
 static DEFINE_SPINLOCK(moxa_lock);
 
-static struct tty_port moxa_service_port;
-
 MODULE_AUTHOR("William Chen");
 MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
 MODULE_LICENSE("GPL");
@@ -557,104 +526,6 @@ static void moxa_low_water_check(void __iomem *ofsAddr)
  * TTY operations
  */
 
-static int moxa_ioctl(struct tty_struct *tty,
-		      unsigned int cmd, unsigned long arg)
-{
-	struct moxa_port *ch = tty->driver_data;
-	void __user *argp = (void __user *)arg;
-	int status, ret = 0;
-
-	if (tty->index == MAX_PORTS) {
-		if (cmd != MOXA_GETDATACOUNT && cmd != MOXA_GET_IOQUEUE &&
-				cmd != MOXA_GETMSTATUS)
-			return -EINVAL;
-	} else if (!ch)
-		return -ENODEV;
-
-	switch (cmd) {
-	case MOXA_GETDATACOUNT:
-		moxaLog.tick = jiffies;
-		if (copy_to_user(argp, &moxaLog, sizeof(moxaLog)))
-			ret = -EFAULT;
-		break;
-	case MOXA_FLUSH_QUEUE:
-		MoxaPortFlushData(ch, arg);
-		break;
-	case MOXA_GET_IOQUEUE: {
-		struct moxaq_str __user *argm = argp;
-		struct moxaq_str tmp;
-		struct moxa_port *p;
-		unsigned int i, j;
-
-		for (i = 0; i < MAX_BOARDS; i++) {
-			p = moxa_boards[i].ports;
-			for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
-				memset(&tmp, 0, sizeof(tmp));
-				spin_lock_bh(&moxa_lock);
-				if (moxa_boards[i].ready) {
-					tmp.inq = MoxaPortRxQueue(p);
-					tmp.outq = MoxaPortTxQueue(p);
-				}
-				spin_unlock_bh(&moxa_lock);
-				if (copy_to_user(argm, &tmp, sizeof(tmp)))
-					return -EFAULT;
-			}
-		}
-		break;
-	} case MOXA_GET_OQUEUE:
-		status = MoxaPortTxQueue(ch);
-		ret = put_user(status, (unsigned long __user *)argp);
-		break;
-	case MOXA_GET_IQUEUE:
-		status = MoxaPortRxQueue(ch);
-		ret = put_user(status, (unsigned long __user *)argp);
-		break;
-	case MOXA_GETMSTATUS: {
-		struct mxser_mstatus __user *argm = argp;
-		struct mxser_mstatus tmp;
-		struct moxa_port *p;
-		unsigned int i, j;
-
-		for (i = 0; i < MAX_BOARDS; i++) {
-			p = moxa_boards[i].ports;
-			for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
-				struct tty_struct *ttyp;
-				memset(&tmp, 0, sizeof(tmp));
-				spin_lock_bh(&moxa_lock);
-				if (!moxa_boards[i].ready) {
-				        spin_unlock_bh(&moxa_lock);
-					goto copy;
-                                }
-
-				status = MoxaPortLineStatus(p);
-				spin_unlock_bh(&moxa_lock);
-
-				if (status & 1)
-					tmp.cts = 1;
-				if (status & 2)
-					tmp.dsr = 1;
-				if (status & 4)
-					tmp.dcd = 1;
-
-				ttyp = tty_port_tty_get(&p->port);
-				if (!ttyp)
-					tmp.cflag = p->cflag;
-				else
-					tmp.cflag = ttyp->termios.c_cflag;
-				tty_kref_put(ttyp);
-copy:
-				if (copy_to_user(argm, &tmp, sizeof(tmp)))
-					return -EFAULT;
-			}
-		}
-		break;
-	}
-	default:
-		ret = -ENOIOCTLCMD;
-	}
-	return ret;
-}
-
 static int moxa_break_ctl(struct tty_struct *tty, int state)
 {
 	struct moxa_port *port = tty->driver_data;
@@ -671,7 +542,6 @@ static const struct tty_operations moxa_ops = {
 	.write_room = moxa_write_room,
 	.flush_buffer = moxa_flush_buffer,
 	.chars_in_buffer = moxa_chars_in_buffer,
-	.ioctl = moxa_ioctl,
 	.set_termios = moxa_set_termios,
 	.stop = moxa_stop,
 	.start = moxa_start,
@@ -1283,9 +1153,7 @@ static int __init moxa_init(void)
 {
 	int retval = 0;
 
-	tty_port_init(&moxa_service_port);
-
-	moxaDriver = tty_alloc_driver(MAX_PORTS + 1,
+	moxaDriver = tty_alloc_driver(MAX_PORTS,
 			TTY_DRIVER_REAL_RAW |
 			TTY_DRIVER_DYNAMIC_DEV);
 	if (IS_ERR(moxaDriver))
@@ -1301,8 +1169,6 @@ static int __init moxa_init(void)
 	moxaDriver->init_termios.c_ispeed = 9600;
 	moxaDriver->init_termios.c_ospeed = 9600;
 	tty_set_operations(moxaDriver, &moxa_ops);
-	/* Having one more port only for ioctls is ugly */
-	tty_port_link_device(&moxa_service_port, moxaDriver, MAX_PORTS);
 
 	if (tty_register_driver(moxaDriver)) {
 		printk(KERN_ERR "can't register MOXA Smartio tty driver!\n");
@@ -1362,9 +1228,6 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
 	int port;
 
 	port = tty->index;
-	if (port == MAX_PORTS) {
-		return capable(CAP_SYS_ADMIN) ? 0 : -EPERM;
-	}
 	if (mutex_lock_interruptible(&moxa_openlock))
 		return -ERESTARTSYS;
 	brd = &moxa_boards[port / MAX_PORTS_PER_BOARD];
@@ -2087,7 +1950,6 @@ static ssize_t MoxaPortWriteData(struct tty_struct *tty, const u8 *buffer,
 	c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask);
 	if (c > len)
 		c = len;
-	moxaLog.txcnt[port->port.tty->index] += c;
 	total = c;
 	if (spage == epage) {
 		bufhead = readw(ofsAddr + Ofs_txb);
@@ -2129,7 +1991,6 @@ static ssize_t MoxaPortWriteData(struct tty_struct *tty, const u8 *buffer,
 
 static int MoxaPortReadData(struct moxa_port *port)
 {
-	struct tty_struct *tty = port->port.tty;
 	void __iomem *baseAddr, *ofsAddr, *ofs;
 	u8 *dst;
 	unsigned int count, len, total;
@@ -2148,7 +2009,6 @@ static int MoxaPortReadData(struct moxa_port *port)
 		return 0;
 
 	total = count;
-	moxaLog.rxcnt[tty->index] += total;
 	if (spage == epage) {
 		bufhead = readw(ofsAddr + Ofs_rxb);
 		writew(spage, baseAddr + Control_reg);
@@ -2236,8 +2096,6 @@ static int moxa_get_serial_info(struct tty_struct *tty,
 {
 	struct moxa_port *info = tty->driver_data;
 
-	if (tty->index == MAX_PORTS)
-		return -EINVAL;
 	if (!info)
 		return -ENODEV;
 	mutex_lock(&info->port.mutex);
@@ -2257,8 +2115,6 @@ static int moxa_set_serial_info(struct tty_struct *tty,
 	struct moxa_port *info = tty->driver_data;
 	unsigned int close_delay;
 
-	if (tty->index == MAX_PORTS)
-		return -EINVAL;
 	if (!info)
 		return -ENODEV;
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 20/29] tty: srmcons: fix retval from srmcons_init()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (18 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 19/29] tty: moxa: carve out special ioctls and extra tty_port Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 21:48   ` Magnus Lindholm
  2025-02-20 11:15 ` [PATCH 21/29] tty: staging/greybus: pass tty_driver flags to tty_alloc_driver() Jiri Slaby (SUSE)
                   ` (9 subsequent siblings)
  29 siblings, 1 reply; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Richard Henderson,
	Matt Turner, linux-alpha

The value returned from srmcons_init() was -ENODEV for over 2 decades.
But it does not matter, given device_initcall() ignores retvals.

But to be honest, return 0 in case the tty driver was registered
properly.

To do that, the condition is inverted and a short path taken in case of
error.

err_free_drv is introduced as it will be used from more places later.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
---
 arch/alpha/kernel/srmcons.c | 62 ++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
index 3e61073f4b30..b9cd364e814e 100644
--- a/arch/alpha/kernel/srmcons.c
+++ b/arch/alpha/kernel/srmcons.c
@@ -196,40 +196,44 @@ static const struct tty_operations srmcons_ops = {
 static int __init
 srmcons_init(void)
 {
+	struct tty_driver *driver;
+	int err;
+
 	timer_setup(&srmcons_singleton.timer, srmcons_receive_chars, 0);
-	if (srm_is_registered_console) {
-		struct tty_driver *driver;
-		int err;
-
-		driver = tty_alloc_driver(MAX_SRM_CONSOLE_DEVICES, 0);
-		if (IS_ERR(driver))
-			return PTR_ERR(driver);
-
-		tty_port_init(&srmcons_singleton.port);
-
-		driver->driver_name = "srm";
-		driver->name = "srm";
-		driver->major = 0; 	/* dynamic */
-		driver->minor_start = 0;
-		driver->type = TTY_DRIVER_TYPE_SYSTEM;
-		driver->subtype = SYSTEM_TYPE_SYSCONS;
-		driver->init_termios = tty_std_termios;
-		tty_set_operations(driver, &srmcons_ops);
-		tty_port_link_device(&srmcons_singleton.port, driver, 0);
-		err = tty_register_driver(driver);
-		if (err) {
-			tty_driver_kref_put(driver);
-			tty_port_destroy(&srmcons_singleton.port);
-			return err;
-		}
-		srmcons_driver = driver;
-	}
 
-	return -ENODEV;
+	if (!srm_is_registered_console)
+		return -ENODEV;
+
+	driver = tty_alloc_driver(MAX_SRM_CONSOLE_DEVICES, 0);
+	if (IS_ERR(driver))
+		return PTR_ERR(driver);
+
+	tty_port_init(&srmcons_singleton.port);
+
+	driver->driver_name = "srm";
+	driver->name = "srm";
+	driver->major = 0;	/* dynamic */
+	driver->minor_start = 0;
+	driver->type = TTY_DRIVER_TYPE_SYSTEM;
+	driver->subtype = SYSTEM_TYPE_SYSCONS;
+	driver->init_termios = tty_std_termios;
+	tty_set_operations(driver, &srmcons_ops);
+	tty_port_link_device(&srmcons_singleton.port, driver, 0);
+	err = tty_register_driver(driver);
+	if (err)
+		goto err_free_drv;
+
+	srmcons_driver = driver;
+
+	return 0;
+err_free_drv:
+	tty_driver_kref_put(driver);
+	tty_port_destroy(&srmcons_singleton.port);
+
+	return err;
 }
 device_initcall(srmcons_init);
 
-\f
 /*
  * The console driver
  */
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 21/29] tty: staging/greybus: pass tty_driver flags to tty_alloc_driver()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (19 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 20/29] tty: srmcons: fix retval from srmcons_init() Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-21 12:25   ` Johan Hovold
  2025-02-20 11:15 ` [PATCH 22/29] tty: sunsu: drop serial_{in,out}p() Jiri Slaby (SUSE)
                   ` (8 subsequent siblings)
  29 siblings, 1 reply; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), David Lin,
	Johan Hovold, Alex Elder, greybus-dev, linux-staging

tty_alloc_driver() is supposed to receive tty driver flags.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: greybus-dev@lists.linaro.org
Cc: linux-staging@lists.linux.dev
---
 drivers/staging/greybus/uart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 8eab94cb06fa..308ed1ca9947 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -948,7 +948,8 @@ static int gb_tty_init(void)
 {
 	int retval = 0;
 
-	gb_tty_driver = tty_alloc_driver(GB_NUM_MINORS, 0);
+	gb_tty_driver = tty_alloc_driver(GB_NUM_MINORS, TTY_DRIVER_REAL_RAW |
+					 TTY_DRIVER_DYNAMIC_DEV);
 	if (IS_ERR(gb_tty_driver)) {
 		pr_err("Can not allocate tty driver\n");
 		retval = -ENOMEM;
@@ -961,7 +962,6 @@ static int gb_tty_init(void)
 	gb_tty_driver->minor_start = 0;
 	gb_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
 	gb_tty_driver->subtype = SERIAL_TYPE_NORMAL;
-	gb_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
 	gb_tty_driver->init_termios = tty_std_termios;
 	gb_tty_driver->init_termios.c_cflag = B9600 | CS8 |
 		CREAD | HUPCL | CLOCAL;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 22/29] tty: sunsu: drop serial_{in,out}p()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (20 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 21/29] tty: staging/greybus: pass tty_driver flags to tty_alloc_driver() Jiri Slaby (SUSE)
@ 2025-02-20 11:15 ` Jiri Slaby (SUSE)
  2025-02-20 11:16 ` [PATCH 23/29] tty: sunsu: remove unused serial_icr_read() Jiri Slaby (SUSE)
                   ` (7 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:15 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), David S. Miller,
	sparclinux

They are simple wrappers around serial_{in/out}() without actually
pausing the execution. Since ever. So drop these useless wrappers.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
---
 drivers/tty/serial/sunsu.c | 164 +++++++++++++++++--------------------
 1 file changed, 77 insertions(+), 87 deletions(-)

diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c
index 7f0fef07e141..2dc68b3201a4 100644
--- a/drivers/tty/serial/sunsu.c
+++ b/drivers/tty/serial/sunsu.c
@@ -150,16 +150,6 @@ static void serial_out(struct uart_sunsu_port *up, int offset, int value)
 	}
 }
 
-/*
- * We used to support using pause I/O for certain machines.  We
- * haven't supported this for a while, but just in case it's badly
- * needed for certain old 386 machines, I've left these #define's
- * in....
- */
-#define serial_inp(up, offset)		serial_in(up, offset)
-#define serial_outp(up, offset, value)	serial_out(up, offset, value)
-
-
 /*
  * For the 16C950
  */
@@ -193,12 +183,12 @@ static int __enable_rsa(struct uart_sunsu_port *up)
 	unsigned char mode;
 	int result;
 
-	mode = serial_inp(up, UART_RSA_MSR);
+	mode = serial_in(up, UART_RSA_MSR);
 	result = mode & UART_RSA_MSR_FIFO;
 
 	if (!result) {
-		serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
-		mode = serial_inp(up, UART_RSA_MSR);
+		serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
+		mode = serial_in(up, UART_RSA_MSR);
 		result = mode & UART_RSA_MSR_FIFO;
 	}
 
@@ -217,7 +207,7 @@ static void enable_rsa(struct uart_sunsu_port *up)
 			uart_port_unlock_irq(&up->port);
 		}
 		if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
-			serial_outp(up, UART_RSA_FRR, 0);
+			serial_out(up, UART_RSA_FRR, 0);
 	}
 }
 
@@ -236,12 +226,12 @@ static void disable_rsa(struct uart_sunsu_port *up)
 	    up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
 		uart_port_lock_irq(&up->port);
 
-		mode = serial_inp(up, UART_RSA_MSR);
+		mode = serial_in(up, UART_RSA_MSR);
 		result = !(mode & UART_RSA_MSR_FIFO);
 
 		if (!result) {
-			serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
-			mode = serial_inp(up, UART_RSA_MSR);
+			serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
+			mode = serial_in(up, UART_RSA_MSR);
 			result = !(mode & UART_RSA_MSR_FIFO);
 		}
 
@@ -326,7 +316,7 @@ receive_chars(struct uart_sunsu_port *up, unsigned char *status)
 	int saw_console_brk = 0;
 
 	do {
-		ch = serial_inp(up, UART_RX);
+		ch = serial_in(up, UART_RX);
 		flag = TTY_NORMAL;
 		up->port.icount.rx++;
 
@@ -387,7 +377,7 @@ receive_chars(struct uart_sunsu_port *up, unsigned char *status)
 			 */
 			 tty_insert_flip_char(port, 0, TTY_OVERRUN);
 	ignore_char:
-		*status = serial_inp(up, UART_LSR);
+		*status = serial_in(up, UART_LSR);
 	} while ((*status & UART_LSR_DR) && (max_count-- > 0));
 
 	if (saw_console_brk)
@@ -401,7 +391,7 @@ static void transmit_chars(struct uart_sunsu_port *up)
 	int count;
 
 	if (up->port.x_char) {
-		serial_outp(up, UART_TX, up->port.x_char);
+		serial_out(up, UART_TX, up->port.x_char);
 		up->port.icount.tx++;
 		up->port.x_char = 0;
 		return;
@@ -460,7 +450,7 @@ static irqreturn_t sunsu_serial_interrupt(int irq, void *dev_id)
 	uart_port_lock_irqsave(&up->port, &flags);
 
 	do {
-		status = serial_inp(up, UART_LSR);
+		status = serial_in(up, UART_LSR);
 		if (status & UART_LSR_DR)
 			receive_chars(up, &status);
 		check_modem_status(up);
@@ -498,7 +488,7 @@ static void sunsu_change_mouse_baud(struct uart_sunsu_port *up)
 static void receive_kbd_ms_chars(struct uart_sunsu_port *up, int is_break)
 {
 	do {
-		unsigned char ch = serial_inp(up, UART_RX);
+		unsigned char ch = serial_in(up, UART_RX);
 
 		/* Stop-A is handled by drivers/char/keyboard.c now. */
 		if (up->su_type == SU_PORT_KBD) {
@@ -530,7 +520,7 @@ static irqreturn_t sunsu_kbd_ms_interrupt(int irq, void *dev_id)
 	struct uart_sunsu_port *up = dev_id;
 
 	if (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)) {
-		unsigned char status = serial_inp(up, UART_LSR);
+		unsigned char status = serial_in(up, UART_LSR);
 
 		if ((status & UART_LSR_DR) || (status & UART_LSR_BI))
 			receive_kbd_ms_chars(up, (status & UART_LSR_BI) != 0);
@@ -619,14 +609,14 @@ static int sunsu_startup(struct uart_port *port)
 	if (up->port.type == PORT_16C950) {
 		/* Wake up and initialize UART */
 		up->acr = 0;
-		serial_outp(up, UART_LCR, 0xBF);
-		serial_outp(up, UART_EFR, UART_EFR_ECB);
-		serial_outp(up, UART_IER, 0);
-		serial_outp(up, UART_LCR, 0);
+		serial_out(up, UART_LCR, 0xBF);
+		serial_out(up, UART_EFR, UART_EFR_ECB);
+		serial_out(up, UART_IER, 0);
+		serial_out(up, UART_LCR, 0);
 		serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
-		serial_outp(up, UART_LCR, 0xBF);
-		serial_outp(up, UART_EFR, UART_EFR_ECB);
-		serial_outp(up, UART_LCR, 0);
+		serial_out(up, UART_LCR, 0xBF);
+		serial_out(up, UART_EFR, UART_EFR_ECB);
+		serial_out(up, UART_LCR, 0);
 	}
 
 #ifdef CONFIG_SERIAL_8250_RSA
@@ -642,19 +632,19 @@ static int sunsu_startup(struct uart_port *port)
 	 * (they will be reenabled in set_termios())
 	 */
 	if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) {
-		serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
-		serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
+		serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
+		serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
 				UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
-		serial_outp(up, UART_FCR, 0);
+		serial_out(up, UART_FCR, 0);
 	}
 
 	/*
 	 * Clear the interrupt registers.
 	 */
-	(void) serial_inp(up, UART_LSR);
-	(void) serial_inp(up, UART_RX);
-	(void) serial_inp(up, UART_IIR);
-	(void) serial_inp(up, UART_MSR);
+	(void) serial_in(up, UART_LSR);
+	(void) serial_in(up, UART_RX);
+	(void) serial_in(up, UART_IIR);
+	(void) serial_in(up, UART_MSR);
 
 	/*
 	 * At this point, there's no way the LSR could still be 0xff;
@@ -662,7 +652,7 @@ static int sunsu_startup(struct uart_port *port)
 	 * here.
 	 */
 	if (!(up->port.flags & UPF_BUGGY_UART) &&
-	    (serial_inp(up, UART_LSR) == 0xff)) {
+	    (serial_in(up, UART_LSR) == 0xff)) {
 		printk("ttyS%d: LSR safety check engaged!\n", up->port.line);
 		return -ENODEV;
 	}
@@ -682,7 +672,7 @@ static int sunsu_startup(struct uart_port *port)
 	/*
 	 * Now, initialize the UART
 	 */
-	serial_outp(up, UART_LCR, UART_LCR_WLEN8);
+	serial_out(up, UART_LCR, UART_LCR_WLEN8);
 
 	uart_port_lock_irqsave(&up->port, &flags);
 
@@ -697,7 +687,7 @@ static int sunsu_startup(struct uart_port *port)
 	 * anyway, so we don't enable them here.
 	 */
 	up->ier = UART_IER_RLSI | UART_IER_RDI;
-	serial_outp(up, UART_IER, up->ier);
+	serial_out(up, UART_IER, up->ier);
 
 	if (up->port.flags & UPF_FOURPORT) {
 		unsigned int icp;
@@ -712,10 +702,10 @@ static int sunsu_startup(struct uart_port *port)
 	/*
 	 * And clear the interrupt registers again for luck.
 	 */
-	(void) serial_inp(up, UART_LSR);
-	(void) serial_inp(up, UART_RX);
-	(void) serial_inp(up, UART_IIR);
-	(void) serial_inp(up, UART_MSR);
+	(void) serial_in(up, UART_LSR);
+	(void) serial_in(up, UART_RX);
+	(void) serial_in(up, UART_IIR);
+	(void) serial_in(up, UART_MSR);
 
 	return 0;
 }
@@ -730,7 +720,7 @@ static void sunsu_shutdown(struct uart_port *port)
 	 * Disable interrupts from this port
 	 */
 	up->ier = 0;
-	serial_outp(up, UART_IER, 0);
+	serial_out(up, UART_IER, 0);
 
 	uart_port_lock_irqsave(&up->port, &flags);
 	if (up->port.flags & UPF_FOURPORT) {
@@ -746,11 +736,11 @@ static void sunsu_shutdown(struct uart_port *port)
 	/*
 	 * Disable break condition and FIFOs
 	 */
-	serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC);
-	serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
+	serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC);
+	serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
 				  UART_FCR_CLEAR_RCVR |
 				  UART_FCR_CLEAR_XMIT);
-	serial_outp(up, UART_FCR, 0);
+	serial_out(up, UART_FCR, 0);
 
 #ifdef CONFIG_SERIAL_8250_RSA
 	/*
@@ -872,22 +862,22 @@ sunsu_change_speed(struct uart_port *port, unsigned int cflag,
 	serial_out(up, UART_IER, up->ier);
 
 	if (uart_config[up->port.type].flags & UART_STARTECH) {
-		serial_outp(up, UART_LCR, 0xBF);
-		serial_outp(up, UART_EFR, cflag & CRTSCTS ? UART_EFR_CTS :0);
+		serial_out(up, UART_LCR, 0xBF);
+		serial_out(up, UART_EFR, cflag & CRTSCTS ? UART_EFR_CTS :0);
 	}
-	serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
-	serial_outp(up, UART_DLL, quot & 0xff);		/* LS of divisor */
-	serial_outp(up, UART_DLM, quot >> 8);		/* MS of divisor */
+	serial_out(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
+	serial_out(up, UART_DLL, quot & 0xff);		/* LS of divisor */
+	serial_out(up, UART_DLM, quot >> 8);		/* MS of divisor */
 	if (up->port.type == PORT_16750)
-		serial_outp(up, UART_FCR, fcr);		/* set fcr */
-	serial_outp(up, UART_LCR, cval);		/* reset DLAB */
+		serial_out(up, UART_FCR, fcr);		/* set fcr */
+	serial_out(up, UART_LCR, cval);		/* reset DLAB */
 	up->lcr = cval;					/* Save LCR */
 	if (up->port.type != PORT_16750) {
 		if (fcr & UART_FCR_ENABLE_FIFO) {
 			/* emulated UARTs (Lucent Venus 167x) need two steps */
-			serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
+			serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
 		}
-		serial_outp(up, UART_FCR, fcr);		/* set fcr */
+		serial_out(up, UART_FCR, fcr);		/* set fcr */
 	}
 
 	up->cflag = cflag;
@@ -1051,18 +1041,18 @@ static void sunsu_autoconfig(struct uart_sunsu_port *up)
 		 * 0x80 is a non-existent port; which should be safe since
 		 * include/asm/io.h also makes this assumption.
 		 */
-		scratch = serial_inp(up, UART_IER);
-		serial_outp(up, UART_IER, 0);
+		scratch = serial_in(up, UART_IER);
+		serial_out(up, UART_IER, 0);
 #ifdef __i386__
 		outb(0xff, 0x080);
 #endif
-		scratch2 = serial_inp(up, UART_IER);
-		serial_outp(up, UART_IER, 0x0f);
+		scratch2 = serial_in(up, UART_IER);
+		serial_out(up, UART_IER, 0x0f);
 #ifdef __i386__
 		outb(0, 0x080);
 #endif
-		scratch3 = serial_inp(up, UART_IER);
-		serial_outp(up, UART_IER, scratch);
+		scratch3 = serial_in(up, UART_IER);
+		serial_out(up, UART_IER, scratch);
 		if (scratch2 != 0 || scratch3 != 0x0F)
 			goto out;	/* We failed; there's nothing here */
 	}
@@ -1080,16 +1070,16 @@ static void sunsu_autoconfig(struct uart_sunsu_port *up)
 	 * that conflicts with COM 1-4 --- we hope!
 	 */
 	if (!(up->port.flags & UPF_SKIP_TEST)) {
-		serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A);
-		status1 = serial_inp(up, UART_MSR) & 0xF0;
-		serial_outp(up, UART_MCR, save_mcr);
+		serial_out(up, UART_MCR, UART_MCR_LOOP | 0x0A);
+		status1 = serial_in(up, UART_MSR) & 0xF0;
+		serial_out(up, UART_MCR, save_mcr);
 		if (status1 != 0x90)
 			goto out;	/* We failed loopback test */
 	}
-	serial_outp(up, UART_LCR, 0xBF);	/* set up for StarTech test */
-	serial_outp(up, UART_EFR, 0);		/* EFR is the same as FCR */
-	serial_outp(up, UART_LCR, 0);
-	serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
+	serial_out(up, UART_LCR, 0xBF);	/* set up for StarTech test */
+	serial_out(up, UART_EFR, 0);		/* EFR is the same as FCR */
+	serial_out(up, UART_LCR, 0);
+	serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
 	scratch = serial_in(up, UART_IIR) >> 6;
 	switch (scratch) {
 		case 0:
@@ -1107,19 +1097,19 @@ static void sunsu_autoconfig(struct uart_sunsu_port *up)
 	}
 	if (up->port.type == PORT_16550A) {
 		/* Check for Startech UART's */
-		serial_outp(up, UART_LCR, UART_LCR_DLAB);
+		serial_out(up, UART_LCR, UART_LCR_DLAB);
 		if (serial_in(up, UART_EFR) == 0) {
 			up->port.type = PORT_16650;
 		} else {
-			serial_outp(up, UART_LCR, 0xBF);
+			serial_out(up, UART_LCR, 0xBF);
 			if (serial_in(up, UART_EFR) == 0)
 				up->port.type = PORT_16650V2;
 		}
 	}
 	if (up->port.type == PORT_16550A) {
 		/* Check for TI 16750 */
-		serial_outp(up, UART_LCR, save_lcr | UART_LCR_DLAB);
-		serial_outp(up, UART_FCR,
+		serial_out(up, UART_LCR, save_lcr | UART_LCR_DLAB);
+		serial_out(up, UART_FCR,
 			    UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
 		scratch = serial_in(up, UART_IIR) >> 5;
 		if (scratch == 7) {
@@ -1129,24 +1119,24 @@ static void sunsu_autoconfig(struct uart_sunsu_port *up)
 			 * mode if the UART_FCR7_64BYTE bit was set
 			 * while UART_LCR_DLAB was latched.
 			 */
- 			serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
-			serial_outp(up, UART_LCR, 0);
-			serial_outp(up, UART_FCR,
+			serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
+			serial_out(up, UART_LCR, 0);
+			serial_out(up, UART_FCR,
 				    UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
 			scratch = serial_in(up, UART_IIR) >> 5;
 			if (scratch == 6)
 				up->port.type = PORT_16750;
 		}
-		serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
+		serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
 	}
-	serial_outp(up, UART_LCR, save_lcr);
+	serial_out(up, UART_LCR, save_lcr);
 	if (up->port.type == PORT_16450) {
 		scratch = serial_in(up, UART_SCR);
-		serial_outp(up, UART_SCR, 0xa5);
+		serial_out(up, UART_SCR, 0xa5);
 		status1 = serial_in(up, UART_SCR);
-		serial_outp(up, UART_SCR, 0x5a);
+		serial_out(up, UART_SCR, 0x5a);
 		status2 = serial_in(up, UART_SCR);
-		serial_outp(up, UART_SCR, scratch);
+		serial_out(up, UART_SCR, scratch);
 
 		if ((status1 != 0xa5) || (status2 != 0x5a))
 			up->port.type = PORT_8250;
@@ -1163,15 +1153,15 @@ static void sunsu_autoconfig(struct uart_sunsu_port *up)
 	 */
 #ifdef CONFIG_SERIAL_8250_RSA
 	if (up->port.type == PORT_RSA)
-		serial_outp(up, UART_RSA_FRR, 0);
+		serial_out(up, UART_RSA_FRR, 0);
 #endif
-	serial_outp(up, UART_MCR, save_mcr);
-	serial_outp(up, UART_FCR, (UART_FCR_ENABLE_FIFO |
+	serial_out(up, UART_MCR, save_mcr);
+	serial_out(up, UART_FCR, (UART_FCR_ENABLE_FIFO |
 				     UART_FCR_CLEAR_RCVR |
 				     UART_FCR_CLEAR_XMIT));
-	serial_outp(up, UART_FCR, 0);
+	serial_out(up, UART_FCR, 0);
 	(void)serial_in(up, UART_RX);
-	serial_outp(up, UART_IER, 0);
+	serial_out(up, UART_IER, 0);
 
 out:
 	uart_port_unlock_irqrestore(&up->port, flags);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 23/29] tty: sunsu: remove unused serial_icr_read()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (21 preceding siblings ...)
  2025-02-20 11:15 ` [PATCH 22/29] tty: sunsu: drop serial_{in,out}p() Jiri Slaby (SUSE)
@ 2025-02-20 11:16 ` Jiri Slaby (SUSE)
  2025-02-20 11:16 ` [PATCH 24/29] serial: remove redundant tty_port_link_device() Jiri Slaby (SUSE)
                   ` (6 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:16 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), David S. Miller,
	sparclinux

It is commented and never used.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
---
 drivers/tty/serial/sunsu.c | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c
index 2dc68b3201a4..383141fe7ba0 100644
--- a/drivers/tty/serial/sunsu.c
+++ b/drivers/tty/serial/sunsu.c
@@ -159,20 +159,6 @@ static void serial_icr_write(struct uart_sunsu_port *up, int offset, int value)
 	serial_out(up, UART_ICR, value);
 }
 
-#if 0 /* Unused currently */
-static unsigned int serial_icr_read(struct uart_sunsu_port *up, int offset)
-{
-	unsigned int value;
-
-	serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
-	serial_out(up, UART_SCR, offset);
-	value = serial_in(up, UART_ICR);
-	serial_icr_write(up, UART_ACR, up->acr);
-
-	return value;
-}
-#endif
-
 #ifdef CONFIG_SERIAL_8250_RSA
 /*
  * Attempts to turn on the RSA FIFO.  Returns zero on failure.
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 24/29] serial: remove redundant tty_port_link_device()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (22 preceding siblings ...)
  2025-02-20 11:16 ` [PATCH 23/29] tty: sunsu: remove unused serial_icr_read() Jiri Slaby (SUSE)
@ 2025-02-20 11:16 ` Jiri Slaby (SUSE)
  2025-02-20 11:16 ` [PATCH 25/29] serial: pass struct uart_state to uart_line_info() Jiri Slaby (SUSE)
                   ` (5 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:16 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

The linking is done implicitly by tty_port_register_device_attr_serdev()
few lines below. So drop this explicit tty_port_link_device().

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/serial_core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index f24d8edf1bee..2a6453891801 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3156,7 +3156,6 @@ static int serial_core_add_one_port(struct uart_driver *drv, struct uart_port *u
 	if (uport->cons && uport->dev)
 		of_console_check(uport->dev->of_node, uport->cons->name, uport->line);
 
-	tty_port_link_device(port, drv->tty_driver, uport->line);
 	uart_configure_port(drv, state, uport);
 
 	port->console = uart_console(uport);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 25/29] serial: pass struct uart_state to uart_line_info()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (23 preceding siblings ...)
  2025-02-20 11:16 ` [PATCH 24/29] serial: remove redundant tty_port_link_device() Jiri Slaby (SUSE)
@ 2025-02-20 11:16 ` Jiri Slaby (SUSE)
  2025-02-20 11:16 ` [PATCH 26/29] serial: 8250: use serial_in/out() helpers Jiri Slaby (SUSE)
                   ` (4 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:16 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

uart_line_info() wants to work with struct uart_state. Do not pass a
driver and an index. Pass the precomputed struct directly.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/serial_core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 2a6453891801..04eaa24ed153 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2013,9 +2013,8 @@ static const char *uart_type(struct uart_port *port)
 
 #ifdef CONFIG_PROC_FS
 
-static void uart_line_info(struct seq_file *m, struct uart_driver *drv, int i)
+static void uart_line_info(struct seq_file *m, struct uart_state *state)
 {
-	struct uart_state *state = drv->state + i;
 	struct tty_port *port = &state->port;
 	enum uart_pm_state pm_state;
 	struct uart_port *uport;
@@ -2100,7 +2099,7 @@ static int uart_proc_show(struct seq_file *m, void *v)
 
 	seq_printf(m, "serinfo:1.0 driver%s%s revision:%s\n", "", "", "");
 	for (i = 0; i < drv->nr; i++)
-		uart_line_info(m, drv, i);
+		uart_line_info(m, drv->state + i);
 	return 0;
 }
 #endif
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 26/29] serial: 8250: use serial_in/out() helpers
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (24 preceding siblings ...)
  2025-02-20 11:16 ` [PATCH 25/29] serial: pass struct uart_state to uart_line_info() Jiri Slaby (SUSE)
@ 2025-02-20 11:16 ` Jiri Slaby (SUSE)
  2025-02-20 12:27   ` Andy Shevchenko
  2025-02-20 15:23   ` Andy Shevchenko
  2025-02-20 11:16 ` [PATCH 27/29] serial: 8250_rsa: simplify rsa8250_{request/release}_resource() Jiri Slaby (SUSE)
                   ` (3 subsequent siblings)
  29 siblings, 2 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:16 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Ilpo Järvinen,
	Andy Shevchenko

There are serial_in/out() helpers to be used instead of direct
p->serial_in/out(). Use them in various 8250 drivers.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serial/8250/8250_dw.c   | 17 +++++++++--------
 drivers/tty/serial/8250/8250_fsl.c  |  8 ++++----
 drivers/tty/serial/8250/8250_omap.c |  2 +-
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index af24ec25d976..d0abbdd630ac 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -120,16 +120,17 @@ static void dw8250_force_idle(struct uart_port *p)
 	 * enabled.
 	 */
 	if (up->fcr & UART_FCR_ENABLE_FIFO) {
-		lsr = p->serial_in(p, UART_LSR);
+		lsr = serial_in(up, UART_LSR);
 		if (!(lsr & UART_LSR_DR))
 			return;
 	}
 
-	(void)p->serial_in(p, UART_RX);
+	serial_in(up, UART_RX);
 }
 
 static void dw8250_check_lcr(struct uart_port *p, int offset, int value)
 {
+	struct uart_8250_port *up = up_to_u8250p(p);
 	struct dw8250_data *d = to_dw8250_data(p->private_data);
 	void __iomem *addr = p->membase + (offset << p->regshift);
 	int tries = 1000;
@@ -139,7 +140,7 @@ static void dw8250_check_lcr(struct uart_port *p, int offset, int value)
 
 	/* Make sure LCR write wasn't ignored */
 	while (tries--) {
-		unsigned int lcr = p->serial_in(p, offset);
+		unsigned int lcr = serial_in(up, offset);
 
 		if ((value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR))
 			return;
@@ -260,7 +261,7 @@ static int dw8250_handle_irq(struct uart_port *p)
 {
 	struct uart_8250_port *up = up_to_u8250p(p);
 	struct dw8250_data *d = to_dw8250_data(p->private_data);
-	unsigned int iir = p->serial_in(p, UART_IIR);
+	unsigned int iir = serial_in(up, UART_IIR);
 	bool rx_timeout = (iir & 0x3f) == UART_IIR_RX_TIMEOUT;
 	unsigned int quirks = d->pdata->quirks;
 	unsigned int status;
@@ -281,7 +282,7 @@ static int dw8250_handle_irq(struct uart_port *p)
 		status = serial_lsr_in(up);
 
 		if (!(status & (UART_LSR_DR | UART_LSR_BI)))
-			(void) p->serial_in(p, UART_RX);
+			serial_in(up, UART_RX);
 
 		uart_port_unlock_irqrestore(p, flags);
 	}
@@ -303,7 +304,7 @@ static int dw8250_handle_irq(struct uart_port *p)
 
 	if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
 		/* Clear the USR */
-		(void)p->serial_in(p, d->pdata->usr_reg);
+		serial_in(up, d->pdata->usr_reg);
 
 		return 1;
 	}
@@ -390,7 +391,7 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
 static void dw8250_set_ldisc(struct uart_port *p, struct ktermios *termios)
 {
 	struct uart_8250_port *up = up_to_u8250p(p);
-	unsigned int mcr = p->serial_in(p, UART_MCR);
+	unsigned int mcr = serial_in(up, UART_MCR);
 
 	if (up->capabilities & UART_CAP_IRDA) {
 		if (termios->c_line == N_IRDA)
@@ -398,7 +399,7 @@ static void dw8250_set_ldisc(struct uart_port *p, struct ktermios *termios)
 		else
 			mcr &= ~DW_UART_MCR_SIRE;
 
-		p->serial_out(p, UART_MCR, mcr);
+		serial_out(up, UART_MCR, mcr);
 	}
 	serial8250_do_set_ldisc(p, termios);
 }
diff --git a/drivers/tty/serial/8250/8250_fsl.c b/drivers/tty/serial/8250/8250_fsl.c
index 1b7bd55619c6..df8f846f3d54 100644
--- a/drivers/tty/serial/8250/8250_fsl.c
+++ b/drivers/tty/serial/8250/8250_fsl.c
@@ -32,7 +32,7 @@ int fsl8250_handle_irq(struct uart_port *port)
 
 	uart_port_lock_irqsave(&up->port, &flags);
 
-	iir = port->serial_in(port, UART_IIR);
+	iir = serial_in(up, UART_IIR);
 	if (iir & UART_IIR_NO_INT) {
 		uart_port_unlock_irqrestore(&up->port, flags);
 		return 0;
@@ -54,12 +54,12 @@ int fsl8250_handle_irq(struct uart_port *port)
 	if (unlikely((iir & UART_IIR_ID) == UART_IIR_RLSI &&
 		     (up->lsr_saved_flags & UART_LSR_BI))) {
 		up->lsr_saved_flags &= ~UART_LSR_BI;
-		port->serial_in(port, UART_RX);
+		serial_in(up, UART_RX);
 		uart_port_unlock_irqrestore(&up->port, flags);
 		return 1;
 	}
 
-	lsr = orig_lsr = up->port.serial_in(&up->port, UART_LSR);
+	lsr = orig_lsr = serial_in(up, UART_LSR);
 
 	/* Process incoming characters first */
 	if ((lsr & (UART_LSR_DR | UART_LSR_BI)) &&
@@ -71,7 +71,7 @@ int fsl8250_handle_irq(struct uart_port *port)
 	if ((orig_lsr & UART_LSR_OE) && (up->overrun_backoff_time_ms > 0)) {
 		unsigned long delay;
 
-		up->ier = port->serial_in(port, UART_IER);
+		up->ier = serial_in(up, UART_IER);
 		if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) {
 			port->ops->stop_rx(port);
 		} else {
diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index c2b75e3f106d..16610782258e 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -692,7 +692,7 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id)
 
 		/* Synchronize UART_IER access against the console. */
 		uart_port_lock(port);
-		up->ier = port->serial_in(port, UART_IER);
+		up->ier = serial_in(up, UART_IER);
 		if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) {
 			port->ops->stop_rx(port);
 		} else {
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 27/29] serial: 8250_rsa: simplify rsa8250_{request/release}_resource()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (25 preceding siblings ...)
  2025-02-20 11:16 ` [PATCH 26/29] serial: 8250: use serial_in/out() helpers Jiri Slaby (SUSE)
@ 2025-02-20 11:16 ` Jiri Slaby (SUSE)
  2025-02-20 11:16 ` [PATCH 28/29] serial: 8250_port: do not use goto for UPQ_NO_TXEN_TEST code flow Jiri Slaby (SUSE)
                   ` (2 subsequent siblings)
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:16 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

* Use already defined 'port' for fetching start/offset, and size.
* Return from the switch immediately -- so it is clear what is returned
  and when.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_rsa.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_rsa.c b/drivers/tty/serial/8250/8250_rsa.c
index dfaa613e452d..82f2593b4c59 100644
--- a/drivers/tty/serial/8250/8250_rsa.c
+++ b/drivers/tty/serial/8250/8250_rsa.c
@@ -16,30 +16,27 @@ static unsigned int probe_rsa_count;
 
 static int rsa8250_request_resource(struct uart_8250_port *up)
 {
-	unsigned long start = UART_RSA_BASE << up->port.regshift;
-	unsigned int size = 8 << up->port.regshift;
 	struct uart_port *port = &up->port;
-	int ret = -EINVAL;
+	unsigned long start = UART_RSA_BASE << port->regshift;
+	unsigned int size = 8 << port->regshift;
 
 	switch (port->iotype) {
 	case UPIO_HUB6:
 	case UPIO_PORT:
 		start += port->iobase;
-		if (request_region(start, size, "serial-rsa"))
-			ret = 0;
-		else
-			ret = -EBUSY;
-		break;
+		if (!request_region(start, size, "serial-rsa"))
+			return -EBUSY;
+		return 0;
+	default:
+		return -EINVAL;
 	}
-
-	return ret;
 }
 
 static void rsa8250_release_resource(struct uart_8250_port *up)
 {
-	unsigned long offset = UART_RSA_BASE << up->port.regshift;
-	unsigned int size = 8 << up->port.regshift;
 	struct uart_port *port = &up->port;
+	unsigned long offset = UART_RSA_BASE << port->regshift;
+	unsigned int size = 8 << port->regshift;
 
 	switch (port->iotype) {
 	case UPIO_HUB6:
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 28/29] serial: 8250_port: do not use goto for UPQ_NO_TXEN_TEST code flow
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (26 preceding siblings ...)
  2025-02-20 11:16 ` [PATCH 27/29] serial: 8250_rsa: simplify rsa8250_{request/release}_resource() Jiri Slaby (SUSE)
@ 2025-02-20 11:16 ` Jiri Slaby (SUSE)
  2025-02-20 11:16 ` [PATCH 29/29] serial: 8250_port: simplify serial8250_request_std_resource() Jiri Slaby (SUSE)
  2025-03-17  4:28 ` [PATCH 00/29] tty: cleanup no. 99 Greg KH
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:16 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

This is unnecessary here and makes the code harder to follow. Invert the
condition and drop the goto+label.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 34 ++++++++++++++---------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index c57f44882abb..4ac5f16fc6ba 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2406,28 +2406,26 @@ int serial8250_do_startup(struct uart_port *port)
 	 * test if we receive TX irq.  This way, we'll never enable
 	 * UART_BUG_TXEN.
 	 */
-	if (up->port.quirks & UPQ_NO_TXEN_TEST)
-		goto dont_test_tx_en;
-
-	/*
-	 * Do a quick test to see if we receive an interrupt when we enable
-	 * the TX irq.
-	 */
-	serial_port_out(port, UART_IER, UART_IER_THRI);
-	lsr = serial_port_in(port, UART_LSR);
-	iir = serial_port_in(port, UART_IIR);
-	serial_port_out(port, UART_IER, 0);
+	if (!(up->port.quirks & UPQ_NO_TXEN_TEST)) {
+		/*
+		 * Do a quick test to see if we receive an interrupt when we
+		 * enable the TX irq.
+		 */
+		serial_port_out(port, UART_IER, UART_IER_THRI);
+		lsr = serial_port_in(port, UART_LSR);
+		iir = serial_port_in(port, UART_IIR);
+		serial_port_out(port, UART_IER, 0);
 
-	if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) {
-		if (!(up->bugs & UART_BUG_TXEN)) {
-			up->bugs |= UART_BUG_TXEN;
-			dev_dbg(port->dev, "enabling bad tx status workarounds\n");
+		if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) {
+			if (!(up->bugs & UART_BUG_TXEN)) {
+				up->bugs |= UART_BUG_TXEN;
+				dev_dbg(port->dev, "enabling bad tx status workarounds\n");
+			}
+		} else {
+			up->bugs &= ~UART_BUG_TXEN;
 		}
-	} else {
-		up->bugs &= ~UART_BUG_TXEN;
 	}
 
-dont_test_tx_en:
 	uart_port_unlock_irqrestore(port, flags);
 
 	/*
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [PATCH 29/29] serial: 8250_port: simplify serial8250_request_std_resource()
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (27 preceding siblings ...)
  2025-02-20 11:16 ` [PATCH 28/29] serial: 8250_port: do not use goto for UPQ_NO_TXEN_TEST code flow Jiri Slaby (SUSE)
@ 2025-02-20 11:16 ` Jiri Slaby (SUSE)
  2025-03-17  4:28 ` [PATCH 00/29] tty: cleanup no. 99 Greg KH
  29 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby (SUSE) @ 2025-02-20 11:16 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE)

Return immediately from the error locations or switch-case ends. It is
therefore easier to see the flow.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 4ac5f16fc6ba..caf4e2ec74bd 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2966,7 +2966,6 @@ static int serial8250_request_std_resource(struct uart_8250_port *up)
 {
 	unsigned int size = serial8250_port_size(up);
 	struct uart_port *port = &up->port;
-	int ret = 0;
 
 	switch (port->iotype) {
 	case UPIO_AU:
@@ -2975,32 +2974,28 @@ static int serial8250_request_std_resource(struct uart_8250_port *up)
 	case UPIO_MEM32BE:
 	case UPIO_MEM16:
 	case UPIO_MEM:
-		if (!port->mapbase) {
-			ret = -EINVAL;
-			break;
-		}
+		if (!port->mapbase)
+			return -EINVAL;
 
-		if (!request_mem_region(port->mapbase, size, "serial")) {
-			ret = -EBUSY;
-			break;
-		}
+		if (!request_mem_region(port->mapbase, size, "serial"))
+			return -EBUSY;
 
 		if (port->flags & UPF_IOREMAP) {
 			port->membase = ioremap(port->mapbase, size);
 			if (!port->membase) {
 				release_mem_region(port->mapbase, size);
-				ret = -ENOMEM;
+				return -ENOMEM;
 			}
 		}
-		break;
-
+		return 0;
 	case UPIO_HUB6:
 	case UPIO_PORT:
 		if (!request_region(port->iobase, size, "serial"))
-			ret = -EBUSY;
-		break;
+			return -EBUSY;
+		return 0;
 	}
-	return ret;
+
+	return 0;
 }
 
 static void serial8250_release_std_resource(struct uart_8250_port *up)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 43+ messages in thread

* Re: [PATCH 26/29] serial: 8250: use serial_in/out() helpers
  2025-02-20 11:16 ` [PATCH 26/29] serial: 8250: use serial_in/out() helpers Jiri Slaby (SUSE)
@ 2025-02-20 12:27   ` Andy Shevchenko
  2025-02-20 14:39     ` Greg KH
  2025-02-20 15:23   ` Andy Shevchenko
  1 sibling, 1 reply; 43+ messages in thread
From: Andy Shevchenko @ 2025-02-20 12:27 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel, Ilpo Järvinen

On Thu, Feb 20, 2025 at 12:16:03PM +0100, Jiri Slaby (SUSE) wrote:
> There are serial_in/out() helpers to be used instead of direct
> p->serial_in/out(). Use them in various 8250 drivers.

Is this just a mechanical (compile-only) conversion?
IIRC 8250 DW code is twisted in some cases and it might
be a possibility of dead loops, but I don't remember it
by heart and haven't checked myself before writing this
reply.

TL;DR: this needs a thorough review.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 03/29] tty: caif: do not use N_TTY_BUF_SIZE
  2025-02-20 11:15 ` [PATCH 03/29] tty: caif: " Jiri Slaby (SUSE)
@ 2025-02-20 14:27   ` Jakub Kicinski
  0 siblings, 0 replies; 43+ messages in thread
From: Jakub Kicinski @ 2025-02-20 14:27 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: gregkh, linux-serial, linux-kernel, Andrew Lunn, David S. Miller,
	Eric Dumazet, Paolo Abeni, netdev

On Thu, 20 Feb 2025 12:15:40 +0100 Jiri Slaby (SUSE) wrote:
> N_TTY_BUF_SIZE -- as the name suggests -- is the N_TTY's buffer size.
> There is no reason to couple that to caif's tty->receive_room. Use 4096
> directly -- even though, it should be some sort of "SKB_MAX_ALLOC" or
> alike. But definitely not N_TTY_BUF_SIZE.
> 
> N_TTY_BUF_SIZE is private and will be moved to n_tty.c later.

Acked-by: Jakub Kicinski <kuba@kernel.org>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 26/29] serial: 8250: use serial_in/out() helpers
  2025-02-20 12:27   ` Andy Shevchenko
@ 2025-02-20 14:39     ` Greg KH
  2025-02-20 14:57       ` Andy Shevchenko
  0 siblings, 1 reply; 43+ messages in thread
From: Greg KH @ 2025-02-20 14:39 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jiri Slaby (SUSE), linux-serial, linux-kernel, Ilpo Järvinen

On Thu, Feb 20, 2025 at 02:27:41PM +0200, Andy Shevchenko wrote:
> On Thu, Feb 20, 2025 at 12:16:03PM +0100, Jiri Slaby (SUSE) wrote:
> > There are serial_in/out() helpers to be used instead of direct
> > p->serial_in/out(). Use them in various 8250 drivers.
> 
> Is this just a mechanical (compile-only) conversion?
> IIRC 8250 DW code is twisted in some cases and it might
> be a possibility of dead loops, but I don't remember it
> by heart and haven't checked myself before writing this
> reply.
> 
> TL;DR: this needs a thorough review.

Wonderful, are you going to do it?  :)

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 26/29] serial: 8250: use serial_in/out() helpers
  2025-02-20 14:39     ` Greg KH
@ 2025-02-20 14:57       ` Andy Shevchenko
  2025-02-20 15:27         ` Andy Shevchenko
  0 siblings, 1 reply; 43+ messages in thread
From: Andy Shevchenko @ 2025-02-20 14:57 UTC (permalink / raw)
  To: Greg KH; +Cc: Jiri Slaby (SUSE), linux-serial, linux-kernel, Ilpo Järvinen

On Thu, Feb 20, 2025 at 03:39:40PM +0100, Greg KH wrote:
> On Thu, Feb 20, 2025 at 02:27:41PM +0200, Andy Shevchenko wrote:
> > On Thu, Feb 20, 2025 at 12:16:03PM +0100, Jiri Slaby (SUSE) wrote:
> > > There are serial_in/out() helpers to be used instead of direct
> > > p->serial_in/out(). Use them in various 8250 drivers.
> > 
> > Is this just a mechanical (compile-only) conversion?
> > IIRC 8250 DW code is twisted in some cases and it might
> > be a possibility of dead loops, but I don't remember it
> > by heart and haven't checked myself before writing this
> > reply.
> > 
> > TL;DR: this needs a thorough review.
> 
> Wonderful, are you going to do it?  :)

Why not. Just give me some time.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 26/29] serial: 8250: use serial_in/out() helpers
  2025-02-20 11:16 ` [PATCH 26/29] serial: 8250: use serial_in/out() helpers Jiri Slaby (SUSE)
  2025-02-20 12:27   ` Andy Shevchenko
@ 2025-02-20 15:23   ` Andy Shevchenko
  2025-02-21 10:07     ` Jiri Slaby
  1 sibling, 1 reply; 43+ messages in thread
From: Andy Shevchenko @ 2025-02-20 15:23 UTC (permalink / raw)
  To: Jiri Slaby (SUSE); +Cc: gregkh, linux-serial, linux-kernel, Ilpo Järvinen

On Thu, Feb 20, 2025 at 12:16:03PM +0100, Jiri Slaby (SUSE) wrote:
> There are serial_in/out() helpers to be used instead of direct
> p->serial_in/out(). Use them in various 8250 drivers.

Okay, I have checked all calls, and I think to avoid possible issues
we need to add a few comments here and there, see below.

But first of all, can we actually use serial_port_in()/serial_port_out()
in the cases where we have already a pointer to uart_port?

...

Here we should add a comment like

/*
 * This function is being called as part of the uart_port::serial_out()
 * routine. Hence it must not call serial_out() on itself against
 * the modified registers here, i.e. LCR.
 */

> static void dw8250_force_idle(struct uart_port *p)
> {
> 	struct uart_8250_port *up = up_to_u8250p(p);
> 	unsigned int lsr;

Here we should add a comment like

	/*
	 * The following call currently performs serial_out()
	 * against the FCR register. Because it differs to LCR
	 * there will be no dead loop, but if it ever gets
	 * modified, we might need a new custom version that
	 * avoids infinite recursion.
	 */

> 	serial8250_clear_and_reinit_fifos(up);

...

On top of this function we need to add the same comment as on top of
dw8250_force_idle() above.

>  static void dw8250_check_lcr(struct uart_port *p, int offset, int value)

...

The rest is legit as we shouldn't use those in the ->serial_in()/->serial_out().

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 26/29] serial: 8250: use serial_in/out() helpers
  2025-02-20 14:57       ` Andy Shevchenko
@ 2025-02-20 15:27         ` Andy Shevchenko
  0 siblings, 0 replies; 43+ messages in thread
From: Andy Shevchenko @ 2025-02-20 15:27 UTC (permalink / raw)
  To: Greg KH; +Cc: Jiri Slaby (SUSE), linux-serial, linux-kernel, Ilpo Järvinen

On Thu, Feb 20, 2025 at 04:57:02PM +0200, Andy Shevchenko wrote:
> On Thu, Feb 20, 2025 at 03:39:40PM +0100, Greg KH wrote:
> > On Thu, Feb 20, 2025 at 02:27:41PM +0200, Andy Shevchenko wrote:
> > > On Thu, Feb 20, 2025 at 12:16:03PM +0100, Jiri Slaby (SUSE) wrote:
> > > > There are serial_in/out() helpers to be used instead of direct
> > > > p->serial_in/out(). Use them in various 8250 drivers.
> > > 
> > > Is this just a mechanical (compile-only) conversion?
> > > IIRC 8250 DW code is twisted in some cases and it might
> > > be a possibility of dead loops, but I don't remember it
> > > by heart and haven't checked myself before writing this
> > > reply.
> > > 
> > > TL;DR: this needs a thorough review.
> > 
> > Wonderful, are you going to do it?  :)
> 
> Why not. Just give me some time.

Just done it, I think we need small improvements as I suggested in the separate
reply. Otherwise I like the idea to unify this.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 20/29] tty: srmcons: fix retval from srmcons_init()
  2025-02-20 11:15 ` [PATCH 20/29] tty: srmcons: fix retval from srmcons_init() Jiri Slaby (SUSE)
@ 2025-02-20 21:48   ` Magnus Lindholm
  2025-02-21  7:53     ` Jiri Slaby
  0 siblings, 1 reply; 43+ messages in thread
From: Magnus Lindholm @ 2025-02-20 21:48 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: gregkh, linux-serial, linux-kernel, Richard Henderson,
	Matt Turner, linux-alpha

I've applied and verified this patch on an Alphaserver ES40 with
serial console.

Regarding the future use of label err_free_drv, is the intention to
use it to break out early if tty_alloc_driver() fails?


Tested-by: Magnus Lindholm <linmag7@gmail.com>




On Thu, Feb 20, 2025 at 12:22 PM Jiri Slaby (SUSE) <jirislaby@kernel.org> wrote:
>
> The value returned from srmcons_init() was -ENODEV for over 2 decades.
> But it does not matter, given device_initcall() ignores retvals.
>
> But to be honest, return 0 in case the tty driver was registered
> properly.
>
> To do that, the condition is inverted and a short path taken in case of
> error.
>
> err_free_drv is introduced as it will be used from more places later.
>
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: Richard Henderson <richard.henderson@linaro.org>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: linux-alpha@vger.kernel.org
> ---
>  arch/alpha/kernel/srmcons.c | 62 ++++++++++++++++++++-----------------
>  1 file changed, 33 insertions(+), 29 deletions(-)
>
> diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
> index 3e61073f4b30..b9cd364e814e 100644
> --- a/arch/alpha/kernel/srmcons.c
> +++ b/arch/alpha/kernel/srmcons.c
> @@ -196,40 +196,44 @@ static const struct tty_operations srmcons_ops = {
>  static int __init
>  srmcons_init(void)
>  {
> +       struct tty_driver *driver;
> +       int err;
> +
>         timer_setup(&srmcons_singleton.timer, srmcons_receive_chars, 0);
> -       if (srm_is_registered_console) {
> -               struct tty_driver *driver;
> -               int err;
> -
> -               driver = tty_alloc_driver(MAX_SRM_CONSOLE_DEVICES, 0);
> -               if (IS_ERR(driver))
> -                       return PTR_ERR(driver);
> -
> -               tty_port_init(&srmcons_singleton.port);
> -
> -               driver->driver_name = "srm";
> -               driver->name = "srm";
> -               driver->major = 0;      /* dynamic */
> -               driver->minor_start = 0;
> -               driver->type = TTY_DRIVER_TYPE_SYSTEM;
> -               driver->subtype = SYSTEM_TYPE_SYSCONS;
> -               driver->init_termios = tty_std_termios;
> -               tty_set_operations(driver, &srmcons_ops);
> -               tty_port_link_device(&srmcons_singleton.port, driver, 0);
> -               err = tty_register_driver(driver);
> -               if (err) {
> -                       tty_driver_kref_put(driver);
> -                       tty_port_destroy(&srmcons_singleton.port);
> -                       return err;
> -               }
> -               srmcons_driver = driver;
> -       }
>
> -       return -ENODEV;
> +       if (!srm_is_registered_console)
> +               return -ENODEV;
> +
> +       driver = tty_alloc_driver(MAX_SRM_CONSOLE_DEVICES, 0);
> +       if (IS_ERR(driver))
> +               return PTR_ERR(driver);
> +
> +       tty_port_init(&srmcons_singleton.port);
> +
> +       driver->driver_name = "srm";
> +       driver->name = "srm";
> +       driver->major = 0;      /* dynamic */
> +       driver->minor_start = 0;
> +       driver->type = TTY_DRIVER_TYPE_SYSTEM;
> +       driver->subtype = SYSTEM_TYPE_SYSCONS;
> +       driver->init_termios = tty_std_termios;
> +       tty_set_operations(driver, &srmcons_ops);
> +       tty_port_link_device(&srmcons_singleton.port, driver, 0);
> +       err = tty_register_driver(driver);
> +       if (err)
> +               goto err_free_drv;
> +
> +       srmcons_driver = driver;
> +
> +       return 0;
> +err_free_drv:
> +       tty_driver_kref_put(driver);
> +       tty_port_destroy(&srmcons_singleton.port);
> +
> +       return err;
>  }
>  device_initcall(srmcons_init);
>
> -
>  /*
>   * The console driver
>   */
> --
> 2.48.1
>
>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 20/29] tty: srmcons: fix retval from srmcons_init()
  2025-02-20 21:48   ` Magnus Lindholm
@ 2025-02-21  7:53     ` Jiri Slaby
  0 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby @ 2025-02-21  7:53 UTC (permalink / raw)
  To: Magnus Lindholm
  Cc: gregkh, linux-serial, linux-kernel, Richard Henderson,
	Matt Turner, linux-alpha

On 20. 02. 25, 22:48, Magnus Lindholm wrote:
> I've applied and verified this patch on an Alphaserver ES40 with
> serial console.
> 
> Regarding the future use of label err_free_drv, is the intention to
> use it to break out early if tty_alloc_driver() fails?

...

>> +       if (!srm_is_registered_console)
>> +               return -ENODEV;
>> +
>> +       driver = tty_alloc_driver(MAX_SRM_CONSOLE_DEVICES, 0);
>> +       if (IS_ERR(driver))
>> +               return PTR_ERR(driver);
>> +
>> +       tty_port_init(&srmcons_singleton.port);
>> +
>> +       driver->driver_name = "srm";
>> +       driver->name = "srm";
>> +       driver->major = 0;      /* dynamic */
>> +       driver->minor_start = 0;
>> +       driver->type = TTY_DRIVER_TYPE_SYSTEM;
>> +       driver->subtype = SYSTEM_TYPE_SYSCONS;
>> +       driver->init_termios = tty_std_termios;
>> +       tty_set_operations(driver, &srmcons_ops);
>> +       tty_port_link_device(&srmcons_singleton.port, driver, 0);

I plan on removing tty_port_link_device() as it was a temporary aid. 
Yay, for 13 years! (commit 2cb4ca0208722).

>> +       err = tty_register_driver(driver);
>> +       if (err)
>> +               goto err_free_drv;

Instead, the idea is to properly tty_port_register_device() after 
tty_register_driver() instead. And that can fail. So is fail path reuses 
err_free_drv (and adds tty_unregister_driver() on top).

>> +
>> +       srmcons_driver = driver;
>> +
>> +       return 0;
>> +err_free_drv:
>> +       tty_driver_kref_put(driver);
>> +       tty_port_destroy(&srmcons_singleton.port);
>> +
>> +       return err;

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 26/29] serial: 8250: use serial_in/out() helpers
  2025-02-20 15:23   ` Andy Shevchenko
@ 2025-02-21 10:07     ` Jiri Slaby
  0 siblings, 0 replies; 43+ messages in thread
From: Jiri Slaby @ 2025-02-21 10:07 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: gregkh, linux-serial, linux-kernel, Ilpo Järvinen

On 20. 02. 25, 16:23, Andy Shevchenko wrote:
> On Thu, Feb 20, 2025 at 12:16:03PM +0100, Jiri Slaby (SUSE) wrote:
>> There are serial_in/out() helpers to be used instead of direct
>> p->serial_in/out(). Use them in various 8250 drivers.
> 
> Okay, I have checked all calls, and I think to avoid possible issues
> we need to add a few comments here and there, see below.
> 
> But first of all, can we actually use serial_port_in()/serial_port_out()
> in the cases where we have already a pointer to uart_port?

Yes, this makes sense -- that'd be real 1:1 change.

PS: omap8250_irq() is funny. It uses all serial_port_in(), serial_in(), 
and port->serial_in() :D.

PS2: the naming of serial_in/out() is unfortunate. I'd expect 
serial8250_in/out().

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 21/29] tty: staging/greybus: pass tty_driver flags to tty_alloc_driver()
  2025-02-20 11:15 ` [PATCH 21/29] tty: staging/greybus: pass tty_driver flags to tty_alloc_driver() Jiri Slaby (SUSE)
@ 2025-02-21 12:25   ` Johan Hovold
  0 siblings, 0 replies; 43+ messages in thread
From: Johan Hovold @ 2025-02-21 12:25 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: gregkh, linux-serial, linux-kernel, David Lin, Alex Elder,
	greybus-dev, linux-staging

On Thu, Feb 20, 2025 at 12:15:58PM +0100, Jiri Slaby wrote:
> tty_alloc_driver() is supposed to receive tty driver flags.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>

Acked-by: Johan Hovold <johan@kernel.org>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 00/29] tty: cleanup no. 99
  2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
                   ` (28 preceding siblings ...)
  2025-02-20 11:16 ` [PATCH 29/29] serial: 8250_port: simplify serial8250_request_std_resource() Jiri Slaby (SUSE)
@ 2025-03-17  4:28 ` Greg KH
  2025-03-17  4:59   ` Jiri Slaby
  29 siblings, 1 reply; 43+ messages in thread
From: Greg KH @ 2025-03-17  4:28 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: linux-serial, linux-kernel, Alex Elder, Andrew Lunn,
	Andy Shevchenko, David Lin, David S. Miller, Eric Dumazet,
	greybus-dev, Ilpo Järvinen, Jakub Kicinski, Johan Hovold,
	linux-alpha, linux-staging, Matt Turner, netdev, Paolo Abeni,
	Richard Henderson, Rob Herring, sparclinux

On Thu, Feb 20, 2025 at 12:15:37PM +0100, Jiri Slaby (SUSE) wrote:
> Hi,
> 
> this is (again) a series of cleanup in tty. I am trying to rework
> tty+serial to avoid limitations of devices (so called NR_UART or
> tty_alloc_driver()'s first parameter). And the below popped up while
> crawling through the code. So this is only a prep cleanup.
> 
> * many tty flags are now enums
> * many functions were improved for readability
> * quite a few unused or old code dropped
> 
> In particular, the runtime behaviour of the kernel before and after the
> changes is supposed to be bug to bug compatible (except moxa's ioctl
> and ISA evils dropped). That is, noone should notice.

Were you going to do a new respin of this, or do you want me to take
this as-is and you will send a follow-up ones for the commented-on
changes?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 00/29] tty: cleanup no. 99
  2025-03-17  4:28 ` [PATCH 00/29] tty: cleanup no. 99 Greg KH
@ 2025-03-17  4:59   ` Jiri Slaby
  2025-03-17  7:00     ` Greg KH
  0 siblings, 1 reply; 43+ messages in thread
From: Jiri Slaby @ 2025-03-17  4:59 UTC (permalink / raw)
  To: Greg KH
  Cc: linux-serial, linux-kernel, Alex Elder, Andrew Lunn,
	Andy Shevchenko, David Lin, David S. Miller, Eric Dumazet,
	greybus-dev, Ilpo Järvinen, Jakub Kicinski, Johan Hovold,
	linux-alpha, linux-staging, Matt Turner, netdev, Paolo Abeni,
	Richard Henderson, Rob Herring, sparclinux

On 17. 03. 25, 5:28, Greg KH wrote:
> On Thu, Feb 20, 2025 at 12:15:37PM +0100, Jiri Slaby (SUSE) wrote:
>> Hi,
>>
>> this is (again) a series of cleanup in tty. I am trying to rework
>> tty+serial to avoid limitations of devices (so called NR_UART or
>> tty_alloc_driver()'s first parameter). And the below popped up while
>> crawling through the code. So this is only a prep cleanup.
>>
>> * many tty flags are now enums
>> * many functions were improved for readability
>> * quite a few unused or old code dropped
>>
>> In particular, the runtime behaviour of the kernel before and after the
>> changes is supposed to be bug to bug compatible (except moxa's ioctl
>> and ISA evils dropped). That is, noone should notice.
> 
> Were you going to do a new respin of this, or do you want me to take
> this as-is and you will send a follow-up ones for the commented-on
> changes?

I planned to send a v2 on Fri, but did not make it. I will today.

thanks,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [PATCH 00/29] tty: cleanup no. 99
  2025-03-17  4:59   ` Jiri Slaby
@ 2025-03-17  7:00     ` Greg KH
  0 siblings, 0 replies; 43+ messages in thread
From: Greg KH @ 2025-03-17  7:00 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: linux-serial, linux-kernel, Alex Elder, Andrew Lunn,
	Andy Shevchenko, David Lin, David S. Miller, Eric Dumazet,
	greybus-dev, Ilpo Järvinen, Jakub Kicinski, Johan Hovold,
	linux-alpha, linux-staging, Matt Turner, netdev, Paolo Abeni,
	Richard Henderson, Rob Herring, sparclinux

On Mon, Mar 17, 2025 at 05:59:01AM +0100, Jiri Slaby wrote:
> On 17. 03. 25, 5:28, Greg KH wrote:
> > On Thu, Feb 20, 2025 at 12:15:37PM +0100, Jiri Slaby (SUSE) wrote:
> > > Hi,
> > > 
> > > this is (again) a series of cleanup in tty. I am trying to rework
> > > tty+serial to avoid limitations of devices (so called NR_UART or
> > > tty_alloc_driver()'s first parameter). And the below popped up while
> > > crawling through the code. So this is only a prep cleanup.
> > > 
> > > * many tty flags are now enums
> > > * many functions were improved for readability
> > > * quite a few unused or old code dropped
> > > 
> > > In particular, the runtime behaviour of the kernel before and after the
> > > changes is supposed to be bug to bug compatible (except moxa's ioctl
> > > and ISA evils dropped). That is, noone should notice.
> > 
> > Were you going to do a new respin of this, or do you want me to take
> > this as-is and you will send a follow-up ones for the commented-on
> > changes?
> 
> I planned to send a v2 on Fri, but did not make it. I will today.

Not a problem, just wanted to make sure I didn't drop these on my side
accidentally.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2025-03-17  7:01 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-20 11:15 [PATCH 00/29] tty: cleanup no. 99 Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 01/29] tty: convert "TTY Struct Flags" to an enum Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 02/29] tty: audit: do not use N_TTY_BUF_SIZE Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 03/29] tty: caif: " Jiri Slaby (SUSE)
2025-02-20 14:27   ` Jakub Kicinski
2025-02-20 11:15 ` [PATCH 04/29] tty: move N_TTY_BUF_SIZE to n_tty Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 05/29] tty: n_tty: use uint for space returned by tty_write_room() Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 06/29] tty: n_tty: simplify process_output() Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 07/29] tty: n_tty: clean up process_output_block() Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 08/29] tty: n_tty: drop n_tty_trace() Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 09/29] tty: n_tty: extract n_tty_continue_cookie() from n_tty_read() Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 10/29] tty: n_tty: extract n_tty_wait_for_input() Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 11/29] tty: n_tty: move more_to_be_read to the end of n_tty_read() Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 12/29] tty: tty_driver: move TTY macros to the top Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 13/29] tty: tty_driver: convert "TTY Driver Flags" to an enum Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 14/29] tty: tty_driver: document both {,__}tty_alloc_driver() properly Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 15/29] tty: tty_driver: introduce TTY driver sub/types enums Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 16/29] tty: serdev: drop serdev_controller_ops::write_room() Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 17/29] tty: moxa: drop version dump to logs Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 18/29] tty: moxa: drop ISA support Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 19/29] tty: moxa: carve out special ioctls and extra tty_port Jiri Slaby (SUSE)
2025-02-20 11:15 ` [PATCH 20/29] tty: srmcons: fix retval from srmcons_init() Jiri Slaby (SUSE)
2025-02-20 21:48   ` Magnus Lindholm
2025-02-21  7:53     ` Jiri Slaby
2025-02-20 11:15 ` [PATCH 21/29] tty: staging/greybus: pass tty_driver flags to tty_alloc_driver() Jiri Slaby (SUSE)
2025-02-21 12:25   ` Johan Hovold
2025-02-20 11:15 ` [PATCH 22/29] tty: sunsu: drop serial_{in,out}p() Jiri Slaby (SUSE)
2025-02-20 11:16 ` [PATCH 23/29] tty: sunsu: remove unused serial_icr_read() Jiri Slaby (SUSE)
2025-02-20 11:16 ` [PATCH 24/29] serial: remove redundant tty_port_link_device() Jiri Slaby (SUSE)
2025-02-20 11:16 ` [PATCH 25/29] serial: pass struct uart_state to uart_line_info() Jiri Slaby (SUSE)
2025-02-20 11:16 ` [PATCH 26/29] serial: 8250: use serial_in/out() helpers Jiri Slaby (SUSE)
2025-02-20 12:27   ` Andy Shevchenko
2025-02-20 14:39     ` Greg KH
2025-02-20 14:57       ` Andy Shevchenko
2025-02-20 15:27         ` Andy Shevchenko
2025-02-20 15:23   ` Andy Shevchenko
2025-02-21 10:07     ` Jiri Slaby
2025-02-20 11:16 ` [PATCH 27/29] serial: 8250_rsa: simplify rsa8250_{request/release}_resource() Jiri Slaby (SUSE)
2025-02-20 11:16 ` [PATCH 28/29] serial: 8250_port: do not use goto for UPQ_NO_TXEN_TEST code flow Jiri Slaby (SUSE)
2025-02-20 11:16 ` [PATCH 29/29] serial: 8250_port: simplify serial8250_request_std_resource() Jiri Slaby (SUSE)
2025-03-17  4:28 ` [PATCH 00/29] tty: cleanup no. 99 Greg KH
2025-03-17  4:59   ` Jiri Slaby
2025-03-17  7:00     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).