public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 1/2] tty: serial/8250: Fix build warning in serial8250_probe_acpi()
@ 2025-08-05 19:51 Abinash Singh
  2025-08-05 19:51 ` [RFC PATCH 2/2] tty: serial/8250: Fix build warning in serial8250_probe_platform() Abinash Singh
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Abinash Singh @ 2025-08-05 19:51 UTC (permalink / raw)
  To: gregkh
  Cc: jirislaby, andriy.shevchenko, sunilvl, arnd, u.kleine-koenig,
	linux-kernel, linux-serial, abinashsinghlalotra

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

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

Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com>
---
The stack usage was further confirmed by using -fstack-usage flag.
it was using 1200 bytes:
..............................
drivers/tty/serial/8250/8250_platform.c:110:12:serial8250_probe_acpi	1200	static
drivers/tty/serial/8250/8250_platform.c:351:20:serial8250_exit	16	static
......................................
After applying the patch it becomes :
.........
It doesn't show up in stack usage  and warning is fixed.
.......
This function is used for probing . So dynamic allocation will not create
any issues.

Thank You
---
 drivers/tty/serial/8250/8250_platform.c | 29 +++++++++++++++----------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_platform.c b/drivers/tty/serial/8250/8250_platform.c
index c0343bfb8064..f7f9c5036d39 100644
--- a/drivers/tty/serial/8250/8250_platform.c
+++ b/drivers/tty/serial/8250/8250_platform.c
@@ -15,7 +15,7 @@
 #include <linux/moduleparam.h>
 #include <linux/once.h>
 #include <linux/platform_device.h>
-
+#include <linux/cleanup.h>
 #include <linux/serial_8250.h>
 
 #ifdef CONFIG_SPARC
@@ -110,41 +110,46 @@ void __init serial8250_isa_init_ports(void)
 static int serial8250_probe_acpi(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct uart_8250_port uart = { };
+	struct uart_8250_port *uart __free(kfree) = NULL;
 	struct resource *regs;
 	int ret, line;
 
+	uart = kmalloc(sizeof(*uart), GFP_KERNEL);
+	if (!uart)
+		return -ENOMEM;
+	memset(uart, 0, sizeof(*uart));
+
 	regs = platform_get_mem_or_io(pdev, 0);
 	if (!regs)
 		return dev_err_probe(dev, -EINVAL, "no registers defined\n");
 
 	switch (resource_type(regs)) {
 	case IORESOURCE_IO:
-		uart.port.iobase = regs->start;
+		uart->port.iobase = regs->start;
 		break;
 	case IORESOURCE_MEM:
-		uart.port.mapbase = regs->start;
-		uart.port.mapsize = resource_size(regs);
-		uart.port.flags = UPF_IOREMAP;
+		uart->port.mapbase = regs->start;
+		uart->port.mapsize = resource_size(regs);
+		uart->port.flags = UPF_IOREMAP;
 		break;
 	default:
 		return -EINVAL;
 	}
 
 	/* default clock frequency */
-	uart.port.uartclk = 1843200;
-	uart.port.type = PORT_16550A;
-	uart.port.dev = &pdev->dev;
-	uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
+	uart->port.uartclk = 1843200;
+	uart->port.type = PORT_16550A;
+	uart->port.dev = &pdev->dev;
+	uart->port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
 
-	ret = uart_read_and_validate_port_properties(&uart.port);
+	ret = uart_read_and_validate_port_properties(&uart->port);
 	/* no interrupt -> fall back to polling */
 	if (ret == -ENXIO)
 		ret = 0;
 	if (ret)
 		return ret;
 
-	line = serial8250_register_8250_port(&uart);
+	line = serial8250_register_8250_port(uart);
 	if (line < 0)
 		return line;
 
-- 
2.50.1


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

end of thread, other threads:[~2025-08-09  9:47 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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           ` [PATCH v3 2/2] serial: 8250_platform: Reduce stack usage in serial8250_probe_platform() Abinash Singh
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox