From: Greg Ungerer <gerg@linux-m68k.org>
To: linux-m68k@lists.linux-m68k.org, linux-serial@vger.kernel.org
Cc: Greg Ungerer <gerg@linux-m68k.org>
Subject: [PATCH 3/5] serial: mcf: dynamically allocate memory
Date: Tue, 13 Oct 2026 22:07:01 +1000 [thread overview]
Message-ID: <20261013120831.1046590-4-gerg@linux-m68k.org> (raw)
In-Reply-To: <20261013120831.1046590-1-gerg@linux-m68k.org>
Modify the ColdFire serial driver to dynamically allocate the local uart
port structures as required at init time. Currently it uses a fixed
size array - a little wasteful of memory on most parts with only a
couple of UARTs.
Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
---
drivers/tty/serial/mcf.c | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/drivers/tty/serial/mcf.c b/drivers/tty/serial/mcf.c
index 3651910dff99..7cbe43cbe3a0 100644
--- a/drivers/tty/serial/mcf.c
+++ b/drivers/tty/serial/mcf.c
@@ -55,6 +55,14 @@ struct mcf_uart {
unsigned char imr; /* Local IMR mirror */
};
+/*
+ * Define maximum number of UARTs this driver will support.
+ * This is set to maximum number on any known ColdFire SoC.
+ */
+#define MCF_MAXPORTS 10
+
+static struct mcf_uart *mcf_ports[MCF_MAXPORTS];
+
/****************************************************************************/
static unsigned int mcf_tx_empty(struct uart_port *port)
@@ -462,19 +470,19 @@ static const struct uart_ops mcf_uart_ops = {
.verify_port = mcf_verify_port,
};
-static struct mcf_uart mcf_ports[10];
-
-#define MCF_MAXPORTS ARRAY_SIZE(mcf_ports)
-
/****************************************************************************/
#if defined(CONFIG_SERIAL_MCF_CONSOLE)
/****************************************************************************/
static void mcf_console_putc(struct console *co, const char c)
{
- struct uart_port *port = &(mcf_ports + co->index)->port;
+ struct uart_port *port;
int i;
+ if ((co->index < 0) || (co->index >= MCF_MAXPORTS))
+ co->index = 0;
+ port = &mcf_ports[co->index]->port;
+
for (i = 0; (i < 0x10000); i++) {
if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)
break;
@@ -509,9 +517,9 @@ static int __init mcf_console_setup(struct console *co, char *options)
if ((co->index < 0) || (co->index >= MCF_MAXPORTS))
co->index = 0;
- port = &mcf_ports[co->index].port;
- if (port->membase == 0)
+ if (mcf_ports[co->index] == NULL)
return -ENODEV;
+ port = &mcf_ports[co->index]->port;
if (options)
uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -572,10 +580,16 @@ static int mcf_probe(struct platform_device *pdev)
{
struct uart_port *port;
struct resource *res;
+ struct mcf_uart *mp;
if (pdev->id >= MCF_MAXPORTS)
return -ENODEV;
- port = &mcf_ports[pdev->id].port;
+
+ mp = devm_kzalloc(&pdev->dev, sizeof(*mp), GFP_KERNEL);
+ if (mp == NULL)
+ return -ENOMEM;
+ mcf_ports[pdev->id] = mp;
+ port = &mp->port;
port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(port->membase))
@@ -605,13 +619,11 @@ static int mcf_probe(struct platform_device *pdev)
static void mcf_remove(struct platform_device *pdev)
{
- struct uart_port *port;
int i;
for (i = 0; (i < MCF_MAXPORTS); i++) {
- port = &mcf_ports[i].port;
- if (port)
- uart_remove_one_port(&mcf_driver, port);
+ if (mcf_ports[i])
+ uart_remove_one_port(&mcf_driver, &mcf_ports[i]->port);
}
}
--
2.55.0
next prev parent reply other threads:[~2026-10-13 12:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 12:06 [PATCH 0/5] serial: mcf: add devicetree support Greg Ungerer
2026-10-13 12:06 ` [PATCH 1/5] serial: mcf: update author email address Greg Ungerer
2026-10-13 12:14 ` sashiko-bot
2026-10-13 12:07 ` [PATCH 2/5] serial: mcf: convert to use proper platform resources Greg Ungerer
2026-10-13 12:24 ` sashiko-bot
2026-10-13 12:07 ` Greg Ungerer [this message]
2026-10-13 12:07 ` [PATCH 4/5] dt-bindings: serial: create binding for mcf-uart Greg Ungerer
2026-10-13 12:07 ` [PATCH 5/5] serial: mcf: add devicetree support Greg Ungerer
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=20261013120831.1046590-4-gerg@linux-m68k.org \
--to=gerg@linux-m68k.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox