linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ruediger Willenberg <r.willenberg@hs-mannheim.de>
To: linux-serial@vger.kernel.org
Cc: gregkh@linuxfoundation.org, git@xilinx.com,
	shubhrajyoti.datta@xilinx.com, michal.simek@xilinx.com,
	Ruediger Willenberg <r.willenberg@hs-mannheim.de>
Subject: [PATCH v2] serial: uartlite: Move out-of-range port-numbers into ULITE_NR_UARTS range
Date: Thu, 18 Nov 2021 22:17:45 +0100	[thread overview]
Message-ID: <20211118211745.133778-1-r.willenberg@hs-mannheim.de> (raw)

Find free uart_port struct in range 0 <= id < ULITE_NR_UARTS when
the device tree port-number property is outside that range. This
happens when there are other UART types in the system because the
Xilinx device tree generator numbers all UARTs consecutively;
as a result, not as many Uartlites as specified by the
SERIAL_UARTLITE_NR_UARTS parameter could be successfully added.

Signed-off-by: Ruediger Willenberg <r.willenberg@hs-mannheim.de>
---
Changes in v2:
 - give KERN_NOTICE when changing the id,
   with reference to the requested port-number 

 drivers/tty/serial/uartlite.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index d3d9566e5dbd..27c513c7350e 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -631,15 +631,17 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,
 {
 	struct uart_port *port;
 	int rc;
+	int oor_id = -1;
 
-	/* if id = -1; then scan for a free id and use that */
-	if (id < 0) {
+	/* if id -1 or out of range; then scan for a free id and use that */
+	if (id < 0 || id >= ULITE_NR_UARTS) {
+		oor_id = id;
 		for (id = 0; id < ULITE_NR_UARTS; id++)
 			if (ulite_ports[id].mapbase == 0)
 				break;
 	}
-	if (id < 0 || id >= ULITE_NR_UARTS) {
-		dev_err(dev, "%s%i too large\n", ULITE_NAME, id);
+	if (id == ULITE_NR_UARTS) {
+		dev_err(dev, "maximum number of %s assigned\n", ULITE_NAME);
 		return -EINVAL;
 	}
 
@@ -676,7 +678,11 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,
 		dev_set_drvdata(dev, NULL);
 		return rc;
 	}
-
+	if (oor_id >= 0)
+		dev_notice(dev,
+			"assigned uartlite with device tree port-number=<%i> to %s%i\n",
+			oor_id, ULITE_NAME, id);
+
 	return 0;
 }
 
-- 
2.25.1


             reply	other threads:[~2021-11-18 21:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 21:17 Ruediger Willenberg [this message]
2021-11-19 12:21 ` [PATCH v2] serial: uartlite: Move out-of-range port-numbers into ULITE_NR_UARTS range Michal Simek
2021-11-22 22:08   ` Ruediger Willenberg
2021-11-23 12:19     ` Michal Simek
2021-11-23 14:59       ` Rüdiger Willenberg
2021-11-23 15:05         ` Michal Simek
2021-11-26 15:35       ` Maarten Brock
2021-12-15 12:02         ` Michal Simek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211118211745.133778-1-r.willenberg@hs-mannheim.de \
    --to=r.willenberg@hs-mannheim.de \
    --cc=git@xilinx.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=shubhrajyoti.datta@xilinx.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).