public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Abinash Singh <abinashsinghlalotra@gmail.com>
To: andriy.shevchenko@linux.intel.com
Cc: abinashsinghlalotra@gmail.com, arnd@arndb.de,
	gregkh@linuxfoundation.org, jirislaby@kernel.org,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	sunilvl@ventanamicro.com, u.kleine-koenig@baylibre.com
Subject: [PATCH v3 2/2] serial: 8250_platform: Reduce stack usage in serial8250_probe_platform()
Date: Thu,  7 Aug 2025 03:21:34 +0530	[thread overview]
Message-ID: <20250806215134.4921-3-abinashsinghlalotra@gmail.com> (raw)
In-Reply-To: <20250806215134.4921-1-abinashsinghlalotra@gmail.com>

 The function serial8250_probe_platform() in 8250_platform.c triggered a
        frame size warning:
drivers/tty/serial/8250/8250_platform.c: In function ‘serial8250_probe_platform.isra’:
drivers/tty/serial/8250/8250_platform.c:201:1: warning: the frame size of 1184 bytes is larger than 1024 bytes [-Wframe-larger-than=]

This patch reduces the stack usage by dynamically allocating the
`uart` structure using kzalloc(), rather than placing it on
the stack. This eliminates the overflow warning and improves kernel
robustness.

Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com>
---
 drivers/tty/serial/8250/8250_platform.c | 61 +++++++++++++------------
 1 file changed, 31 insertions(+), 30 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_platform.c b/drivers/tty/serial/8250/8250_platform.c
index 9938aeb917d8..b27981340e76 100644
--- a/drivers/tty/serial/8250/8250_platform.c
+++ b/drivers/tty/serial/8250/8250_platform.c
@@ -157,43 +157,44 @@ static int serial8250_probe_acpi(struct platform_device *pdev)
 
 static int serial8250_probe_platform(struct platform_device *dev, struct plat_serial8250_port *p)
 {
-	struct uart_8250_port uart;
 	int ret, i, irqflag = 0;
 
-	memset(&uart, 0, sizeof(uart));
+	struct uart_8250_port *uart __free(kfree) = kzalloc(sizeof(*uart), GFP_KERNEL);
+	if (!uart)
+		return -ENOMEM;
 
 	if (share_irqs)
 		irqflag = IRQF_SHARED;
 
 	for (i = 0; p && p->flags != 0; p++, i++) {
-		uart.port.iobase	= p->iobase;
-		uart.port.membase	= p->membase;
-		uart.port.irq		= p->irq;
-		uart.port.irqflags	= p->irqflags;
-		uart.port.uartclk	= p->uartclk;
-		uart.port.regshift	= p->regshift;
-		uart.port.iotype	= p->iotype;
-		uart.port.flags		= p->flags;
-		uart.port.mapbase	= p->mapbase;
-		uart.port.mapsize	= p->mapsize;
-		uart.port.hub6		= p->hub6;
-		uart.port.has_sysrq	= p->has_sysrq;
-		uart.port.private_data	= p->private_data;
-		uart.port.type		= p->type;
-		uart.bugs		= p->bugs;
-		uart.port.serial_in	= p->serial_in;
-		uart.port.serial_out	= p->serial_out;
-		uart.dl_read		= p->dl_read;
-		uart.dl_write		= p->dl_write;
-		uart.port.handle_irq	= p->handle_irq;
-		uart.port.handle_break	= p->handle_break;
-		uart.port.set_termios	= p->set_termios;
-		uart.port.set_ldisc	= p->set_ldisc;
-		uart.port.get_mctrl	= p->get_mctrl;
-		uart.port.pm		= p->pm;
-		uart.port.dev		= &dev->dev;
-		uart.port.irqflags	|= irqflag;
-		ret = serial8250_register_8250_port(&uart);
+		uart->port.iobase	= p->iobase;
+		uart->port.membase	= p->membase;
+		uart->port.irq		= p->irq;
+		uart->port.irqflags	= p->irqflags;
+		uart->port.uartclk	= p->uartclk;
+		uart->port.regshift	= p->regshift;
+		uart->port.iotype	= p->iotype;
+		uart->port.flags		= p->flags;
+		uart->port.mapbase	= p->mapbase;
+		uart->port.mapsize	= p->mapsize;
+		uart->port.hub6		= p->hub6;
+		uart->port.has_sysrq	= p->has_sysrq;
+		uart->port.private_data	= p->private_data;
+		uart->port.type		= p->type;
+		uart->bugs		= p->bugs;
+		uart->port.serial_in	= p->serial_in;
+		uart->port.serial_out	= p->serial_out;
+		uart->dl_read		= p->dl_read;
+		uart->dl_write		= p->dl_write;
+		uart->port.handle_irq	= p->handle_irq;
+		uart->port.handle_break	= p->handle_break;
+		uart->port.set_termios	= p->set_termios;
+		uart->port.set_ldisc	= p->set_ldisc;
+		uart->port.get_mctrl	= p->get_mctrl;
+		uart->port.pm		= p->pm;
+		uart->port.dev		= &dev->dev;
+		uart->port.irqflags	|= irqflag;
+		ret = serial8250_register_8250_port(uart);
 		if (ret < 0) {
 			dev_err(&dev->dev, "unable to register port at index %d "
 				"(IO%lx MEM%llx IRQ%d): %d\n", i,
-- 
2.50.1


  parent reply	other threads:[~2025-08-06 21:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-05 19:51 [RFC PATCH 1/2] tty: serial/8250: Fix build warning in serial8250_probe_acpi() Abinash Singh
2025-08-05 19:51 ` [RFC PATCH 2/2] tty: serial/8250: Fix build warning in serial8250_probe_platform() Abinash Singh
2025-08-05 22:20   ` Andy Shevchenko
2025-08-06 20:10     ` [PATCH v2 0/2] serial: 8250_platform: Reduce stack usage in probe functions Abinash Singh
2025-08-06 20:10       ` [PATCH v2 1/2] serial: 8250_platform: Reduce stack usage in serial8250_probe_acpi() Abinash Singh
2025-08-06 20:41         ` Andy Shevchenko
2025-08-06 20:10       ` [PATCH v2 2/2] serial: 8250_platform: Reduce stack usage in serial8250_probe_platform() Abinash Singh
2025-08-06 20:43         ` Andy Shevchenko
2025-08-06 20:39       ` [PATCH v2 0/2] serial: 8250_platform: Reduce stack usage in probe functions Andy Shevchenko
2025-08-06 21:51         ` [PATCH v3 " Abinash Singh
2025-08-06 21:51           ` [PATCH v3 1/2] serial: 8250_platform: Reduce stack usage in serial8250_probe_acpi() Abinash Singh
2025-08-06 21:51           ` Abinash Singh [this message]
2025-08-09  9:47           ` [PATCH v3 0/2] serial: 8250_platform: Reduce stack usage in probe functions Andy Shevchenko
2025-08-05 22:17 ` [RFC PATCH 1/2] tty: serial/8250: Fix build warning in serial8250_probe_acpi() Andy Shevchenko
2025-08-06  7:01 ` Arnd Bergmann
2025-08-06 21:06   ` Abinash Singh
2025-08-07  5:25   ` Jiri Slaby
2025-08-07  6:43     ` Jiri Slaby
2025-08-07  7:37       ` Jiri Slaby
2025-08-07 11:52       ` Arnd Bergmann

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=20250806215134.4921-3-abinashsinghlalotra@gmail.com \
    --to=abinashsinghlalotra@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=sunilvl@ventanamicro.com \
    --cc=u.kleine-koenig@baylibre.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