[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250805195155.742004-2-abinashsinghlalotra@gmail.com>
Date: Wed, 6 Aug 2025 01:21:55 +0530
From: Abinash Singh <abinashsinghlalotra@...il.com>
To: gregkh@...uxfoundation.org
Cc: jirislaby@...nel.org,
andriy.shevchenko@...ux.intel.com,
sunilvl@...tanamicro.com,
arnd@...db.de,
u.kleine-koenig@...libre.com,
linux-kernel@...r.kernel.org,
linux-serial@...r.kernel.org,
abinashsinghlalotra@...il.com
Subject: [RFC PATCH 2/2] tty: serial/8250: Fix build warning in serial8250_probe_platform()
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 kmalloc(), rather than placing it on
the stack. This eliminates the overflow warning and improves kernel
robustness.
Signed-off-by: Abinash Singh <abinashsinghlalotra@...il.com>
---
The stack usage was further confirmed by using -fstack-usage flag.
it was usiing 1248 bytes:
..............................
drivers/tty/serial/8250/8250_platform.c:154:12:serial8250_probe_platform.isra 1248 dynamic,bounded
drivers/tty/serial/8250/8250_platform.c:208:12:serial8250_probe 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 | 63 +++++++++++++------------
1 file changed, 33 insertions(+), 30 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_platform.c b/drivers/tty/serial/8250/8250_platform.c
index f7f9c5036d39..86816d9b32ce 100644
--- a/drivers/tty/serial/8250/8250_platform.c
+++ b/drivers/tty/serial/8250/8250_platform.c
@@ -158,43 +158,46 @@ 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;
+ struct uart_8250_port *uart __free(kfree) = NULL;
int ret, i, irqflag = 0;
- memset(&uart, 0, sizeof(uart));
+ uart = kmalloc(sizeof(*uart), GFP_KERNEL);
+ if (!uart)
+ return -ENOMEM;
+ memset(uart, 0, sizeof(*uart));
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
Powered by blists - more mailing lists