Skip to contentSkip to conversation

serial: uartps:

PATCH In review Michal Simek 2 participants 9 messages Jun 12, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover serial: uartps:

Hi,

This patchset is fixing several issues reported by checkpatch but also major number handling for multiple allocated ports. For more information please look at the first patch which describes more details.

When this patchset is applied driver only reports one checkpatch warning which should be fixed via console.h first.
include/linux/console.h:147: void (*write)(struct console *, const char *, unsigned);

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
+ unsigned n)

Thanks,
Michal

v1
https://lkml.org/lkml/2019/6/10/186
https://lkml.org/lkml/2019/6/10/187

Changes in v2:
- Fix typo in subject line
- Swap patches compare to previous series
- Add Fixes tag
- Split patch from v1
- Fixes second S_IRUGO usage
- Add Fixes tag
- Split patch from v1
- Add Fixes tag
- Split patch from v1
- Add Fixes tag
- Split patch from v1
- Add Fixes tag
- Split patch from v1
- Add Fixes tag

Nava kishore Manne (5):
serial: uartps: Use octal permission for module_param()
serial: uartps: Fix multiple line dereference
serial: uartps: Fix long line over 80 chars
serial: uartps: Do not add a trailing semicolon to macro
serial: uartps: Remove useless return from cdns_uart_poll_put_char

Shubhrajyoti Datta (1):
serial: uartps: Use the same dynamic major number for all ports

 drivers/tty/serial/xilinx_uartps.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/6 serial: uartps: Use the same dynamic major number for all ports

From: Shubhrajyoti Datta <[email protected]>

Let kernel to find out major number dynamically for the first device and then reuse it for other instances.
This fixes the issue that each uart is registered with a different major number.

After the patch:

crw-------    1 root     root      253,   0 Jun 10 08:31 /dev/ttyPS0
crw--w----    1 root     root      253,   1 Jan  1  1970 /dev/ttyPS1
Fixes 024ca329bfb9 ("serial: uartps: Register own uart console and driver structures")

---

Changes in v2:
- Fix typo in subject line
- Swap patches compare to previous series
- Add Fixes tag

 drivers/tty/serial/xilinx_uartps.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/tty/serial/xilinx_uartps.c +3 -2
index 605354fd60b1..9dcc4d855ddd 100644
@@ -29,12 +29,12 @@
 
 #define CDNS_UART_TTY_NAME	"ttyPS"
 #define CDNS_UART_NAME		"xuartps"
-#define CDNS_UART_MAJOR		0	/* use dynamic node allocation */
 #define CDNS_UART_FIFO_SIZE	64	/* FIFO size */
 #define CDNS_UART_REGISTER_SPACE	0x1000
 
 /* Rx Trigger level */
 static int rx_trigger_level = 56;
+static int uartps_major;
 module_param(rx_trigger_level, uint, S_IRUGO);
 MODULE_PARM_DESC(rx_trigger_level, "Rx trigger level, 1-63 bytes");
 
@@ -1517,7 +1517,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
 	cdns_uart_uart_driver->owner = THIS_MODULE;
 	cdns_uart_uart_driver->driver_name = driver_name;
 	cdns_uart_uart_driver->dev_name	= CDNS_UART_TTY_NAME;
-	cdns_uart_uart_driver->major = CDNS_UART_MAJOR;
+	cdns_uart_uart_driver->major = uartps_major;
 	cdns_uart_uart_driver->minor = cdns_uart_data->id;
 	cdns_uart_uart_driver->nr = 1;
 
@@ -1546,6 +1546,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
 		goto err_out_id;
 	}
 
+	uartps_major = cdns_uart_uart_driver->tty_driver->major;
 	cdns_uart_data->cdns_uart_driver = cdns_uart_uart_driver;
 
 	/*
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/6 serial: uartps: Use octal permission for module_param()

In reply to Michal Simek

From: Nava kishore Manne <[email protected]>

Octal permission is preffered compare to symbolic one.

This patch fixes checkpatch warnings:
Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.

Fixes 85baf542d54e ("tty: xuartps: support 64 byte FIFO size")

---

Changes in v2:
- Split patch from v1
- Fixes second S_IRUGO usage
- Add Fixes tag

 drivers/tty/serial/xilinx_uartps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/xilinx_uartps.c +2 -2
index 9dcc4d855ddd..c84db82bdaab 100644
@@ -35,12 +35,12 @@
 /* Rx Trigger level */
 static int rx_trigger_level = 56;
 static int uartps_major;
-module_param(rx_trigger_level, uint, S_IRUGO);
+module_param(rx_trigger_level, uint, 0444);
 MODULE_PARM_DESC(rx_trigger_level, "Rx trigger level, 1-63 bytes");
 
 /* Rx Timeout */
 static int rx_timeout = 10;
-module_param(rx_timeout, uint, S_IRUGO);
+module_param(rx_timeout, uint, 0444);
 MODULE_PARM_DESC(rx_timeout, "Rx timeout, 1-255");
 
 /* Register offsets for the UART. */
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 3/6 serial: uartps: Fix multiple line dereference

In reply to Michal Simek

From: Nava kishore Manne <[email protected]>

Trivial patch which fixes this checkpatch warning:
WARNING: Avoid multiple line dereference - prefer 'port->state->xmit.tail'
+ port->state->xmit.buf[port->state->xmit.
+ tail], port->membase + CDNS_UART_FIFO);

Fixes c8dbdc842d30 ("serial: xuartps: Rewrite the interrupt handling logic")

---

Changes in v2:
- Split patch from v1
- Add Fixes tag

 drivers/tty/serial/xilinx_uartps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/xilinx_uartps.c +2 -2
index c84db82bdaab..4cd20c036750 100644
@@ -319,8 +319,8 @@ static void cdns_uart_handle_tx(void *dev_id)
 			 * register.
 			 */
 			writel(
-				port->state->xmit.buf[port->state->xmit.
-				tail], port->membase + CDNS_UART_FIFO);
+				port->state->xmit.buf[port->state->xmit.tail],
+					port->membase + CDNS_UART_FIFO);
 
 			port->icount.tx++;
 
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH v2 3/6] serial: uartps: Fix multiple line dereference

Quoted 24 lines · Michal Simek

From: Nava kishore Manne <[email protected]>

Trivial patch which fixes this checkpatch warning:
WARNING: Avoid multiple line dereference - prefer 'port->state->xmit.tail'

(quoted diff) +2 -0
+				port->state->xmit.buf[port->state->xmit.
+				tail], port->membase + CDNS_UART_FIFO);
Fixes c8dbdc842d30 ("serial: xuartps: Rewrite the interrupt handling logic")

---

Changes in v2:
- Split patch from v1
- Add Fixes tag

 drivers/tty/serial/xilinx_uartps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/xilinx_uartps.c +0 -0
index c84db82bdaab..4cd20c036750 100644

drivers/tty/serial/xilinx_uartps.c static void cdns_uart_handle_tx(void *dev_id) · line 325

Quoted 9 lines
drivers/tty/serial/xilinx_uartps.c +2 -2
@@ -319,8 +319,8 @@ static void cdns_uart_handle_tx(void *dev_id)
 			 * register.
 			 */
 			writel(
-				port->state->xmit.buf[port->state->xmit.
-				tail], port->membase + CDNS_UART_FIFO);
+				port->state->xmit.buf[port->state->xmit.tail],
+					port->membase + CDNS_UART_FIFO);
 
 			port->icount.tx++;

Another way to rewrite this is to use a temporary for port->state->xmit and also return early on empty to avoid unnecessary indentation.

Using a temporary can also reduce object size a bit by removing unnecessary dereferences: (defconfig x86-64)

$ size drivers/tty/serial/xilinx_uartps.o*
   text	   data	    bss	    dec	    hex	filename
  26578	   4632	    320	  31530	   7b2a	drivers/tty/serial/xilinx_uartps.o.new
  26642	   4632	    320	  31594	   7b6a	drivers/tty/serial/xilinx_uartps.o.old

i.e.:

---
 drivers/tty/serial/xilinx_uartps.c | 54 ++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 29 deletions(-)
drivers/tty/serial/xilinx_uartps.c +25 -29
index 605354fd60b1..09b586aeeca3 100644
@@ -305,40 +305,36 @@ static void cdns_uart_handle_rx(void *dev_id, unsigned int isrstatus)
 static void cdns_uart_handle_tx(void *dev_id)
 {
 	struct uart_port *port = (struct uart_port *)dev_id;
+	struct circ_buf *xmit = &port->state->xmit;
 	unsigned int numbytes;
 
-	if (uart_circ_empty(&port->state->xmit)) {
+	if (uart_circ_empty(xmit)) {
 		writel(CDNS_UART_IXR_TXEMPTY, port->membase + CDNS_UART_IDR);
-	} else {
-		numbytes = port->fifosize;
-		while (numbytes && !uart_circ_empty(&port->state->xmit) &&
-		       !(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXFULL)) {
-			/*
-			 * Get the data from the UART circular buffer
-			 * and write it to the cdns_uart's TX_FIFO
-			 * register.
-			 */
-			writel(
-				port->state->xmit.buf[port->state->xmit.
-				tail], port->membase + CDNS_UART_FIFO);
-
-			port->icount.tx++;
-
-			/*
-			 * Adjust the tail of the UART buffer and wrap
-			 * the buffer if it reaches limit.
-			 */
-			port->state->xmit.tail =
-				(port->state->xmit.tail + 1) &
-					(UART_XMIT_SIZE - 1);
-
-			numbytes--;
-		}
+		return;
+	}
+
+	numbytes = port->fifosize;
+	while (numbytes && !uart_circ_empty(xmit) &&
+	       !(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXFULL)) {
+		/*
+		 * Get the data from the UART circular buffer and write it
+		 * to the cdns_uart's TX_FIFO register.
+		 */
+		writel(xmit->buf[xmit->tail], port->membase + CDNS_UART_FIFO);
+
+		port->icount.tx++;
+
+		/*
+		 * Adjust the tail of the UART buffer and wrap the buffer
+		 * if it reaches limit.
+		 */
+		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
 
-		if (uart_circ_chars_pending(
-				&port->state->xmit) < WAKEUP_CHARS)
-			uart_write_wakeup(port);
+		numbytes--;
 	}
+
+	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+		uart_write_wakeup(port);
 }
 
 /**
#5 lore raw

PATCH v2 4/6 serial: uartps: Fix long line over 80 chars

In reply to Michal Simek

From: Nava kishore Manne <[email protected]>

Trivial patch which fixes one checkpatch warning:
WARNING: line over 80 characters
+ !(readl(port->membase + CDNS_UART_SR)

			& CDNS_UART_SR_TXFULL)) {
Fixes c8dbdc842d30 ("serial: xuartps: Rewrite the interrupt handling logic")

---

Changes in v2:
- Split patch from v1
- Add Fixes tag

 drivers/tty/serial/xilinx_uartps.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/xilinx_uartps.c +2 -1
index 4cd20c036750..c3949a323815 100644
@@ -312,7 +312,8 @@ static void cdns_uart_handle_tx(void *dev_id)
 	} else {
 		numbytes = port->fifosize;
 		while (numbytes && !uart_circ_empty(&port->state->xmit) &&
-		       !(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXFULL)) {
+		       !(readl(port->membase + CDNS_UART_SR) &
+						CDNS_UART_SR_TXFULL)) {
 			/*
 			 * Get the data from the UART circular buffer
 			 * and write it to the cdns_uart's TX_FIFO
Signature · 1 line
2.17.1
#6 lore raw

PATCH v2 5/6 serial: uartps: Do not add a trailing semicolon to macro

In reply to Michal Simek

From: Nava kishore Manne <[email protected]>

This patch fixes this checkpatch warning:
WARNING: macros should not use a trailing semicolon +#define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, \
+ clk_rate_change_nb);

Fixes d9bb3fb12685 ("tty: xuartps: Rebrand driver as Cadence UART")

---

Changes in v2:
- Split patch from v1
- Add Fixes tag

Origin patch which introduce this semicolon was c4b0510cc1571ff44e1 ("tty: xuartps: Dynamically adjust to input frequency changes")

---
 drivers/tty/serial/xilinx_uartps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/xilinx_uartps.c +1 -1
index c3949a323815..d4c1ae2ffca6 100644
@@ -199,7 +199,7 @@ struct cdns_platform_data {
 	u32 quirks;
 };
 #define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, \
-		clk_rate_change_nb);
+		clk_rate_change_nb)
 
 /**
  * cdns_uart_handle_rx - Handle the received bytes along with Rx errors.
Signature · 1 line
2.17.1
#7 lore raw

Re: [PATCH v2 5/6] serial: uartps: Do not add a trailing semicolon to macro

drivers/tty/serial/xilinx_uartps.c

Quoted 7 lines · Michal Simek

From: Nava kishore Manne <[email protected]>

This patch fixes this checkpatch warning:
WARNING: macros should not use a trailing semicolon

(quoted diff) +2 -0
+#define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, \
+		clk_rate_change_nb);
drivers/tty/serial/xilinx_uartps.c +0 -0

[]

drivers/tty/serial/xilinx_uartps.c struct cdns_platform_data { · line 205

Quoted 9 lines
drivers/tty/serial/xilinx_uartps.c +1 -1
@@ -199,7 +199,7 @@ struct cdns_platform_data {
 	u32 quirks;
 };
 #define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, \
-		clk_rate_change_nb);
+		clk_rate_change_nb)
 
 /**
  * cdns_uart_handle_rx - Handle the received bytes along with Rx errors.

trivia:

Perhaps this is easier for humans to read with the macro on two lines like:

#define to_cdns_uart(_nb) \
container_of(_nb, struct cdns_uart, clk_rate_change_nb)

or just ignore the 80 column limit

#define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, clk_rate_change_nb)

or because the macro is only used in one place,
just get rid of it and use container_of directly.

---
 drivers/tty/serial/xilinx_uartps.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/tty/serial/xilinx_uartps.c +3 -3
index 605354fd60b1..ca5cec2b83ce 100644
@@ -195,11 +195,10 @@ struct cdns_uart {
 	u32			quirks;
 	bool cts_override;
 };
+
 struct cdns_platform_data {
 	u32 quirks;
 };
-#define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, \
-		clk_rate_change_nb);
 
 /**
  * cdns_uart_handle_rx - Handle the received bytes along with Rx errors.
@@ -489,8 +488,9 @@ static int cdns_uart_clk_notifier_cb(struct notifier_block *nb,
 	int locked = 0;
 	struct clk_notifier_data *ndata = data;
 	unsigned long flags = 0;
-	struct cdns_uart *cdns_uart = to_cdns_uart(nb);
+	struct cdns_uart *cdns_uart;
 
+	cdns_uart = container_of(nb, struct cdns_uart, clk_rate_change_nb);
 	port = cdns_uart->port;
 	if (port->suspended)
 		return NOTIFY_OK;
#8 lore raw

PATCH v2 6/6 serial: uartps: Remove useless return from cdns_uart_poll_put_char

In reply to Michal Simek

From: Nava kishore Manne <[email protected]>

There is no reason to call return at the end of function which should return void.

The patch is also remove one checkpatch warning:
WARNING: void function return statements are not generally useful
+ return;
+}

Fixes 6ee04c6c5488 ("tty: xuartps: Add polled mode support for xuartps")

---

Changes in v2:
- Split patch from v1
- Add Fixes tag

 drivers/tty/serial/xilinx_uartps.c | 2 --
 1 file changed, 2 deletions(-)
drivers/tty/serial/xilinx_uartps.c +0 -2
index d4c1ae2ffca6..bcef254fa03c 100644
@@ -1074,8 +1074,6 @@ static void cdns_uart_poll_put_char(struct uart_port *port, unsigned char c)
 		cpu_relax();
 
 	spin_unlock_irqrestore(&port->lock, flags);
-
-	return;
 }
 #endif
 
Signature · 1 line
2.17.1