drivers/tty/serial/8250/8250_platform.c | 87 +++++++++++++------------ 1 file changed, 46 insertions(+), 41 deletions(-)
Hello, I’m very happy and grateful to receive such valuable feedback and support from you all.I’ve carefully reviewed the comments and have applied the suggested changes in this v2 series. Please let me know if there is anything else I can improve or correct further. I truly appreciate your time and guidance. Changes in v2: - Use kzalloc() instead of kmalloc() + memset() - Removed unnecessary NULL initialization - Fixed include ordering - Improved subject line clarity Thank you very much ! Best regards, Abinash Abinash Singh (2): serial: 8250_platform: Reduce stack usage in serial8250_probe_acpi() serial: 8250_platform: Reduce stack usage in serial8250_probe_platform() drivers/tty/serial/8250/8250_platform.c | 87 +++++++++++++------------ 1 file changed, 46 insertions(+), 41 deletions(-) -- 2.50.1
On Thu, Aug 07, 2025 at 01:40:45AM +0530, Abinash Singh wrote: > Hello, > > I’m very happy and grateful to receive such valuable feedback and > support from you all.I’ve carefully reviewed the comments and > have applied the suggested changes in this v2 series. > Please let me know if there is anything else I can > improve or correct further. I truly appreciate your > time and guidance. Have you had a chance to see Arnd's comments? -- With Best Regards, Andy Shevchenko
On Wed, 6 Aug 2025 23:39 Andy Shevchenko wrote: > Have you had a chance to see Arnd's comments? > Yeah ,I have made comments on that. Please check that and provide feedback. Hi, Apologies for not reviewing the patch carefully before submitting it. It's 3 A.M. here, and I’m still up, so I missed it Changes in v3: - fix missing __free(kfree) - mixed defination with code for cleanup attribute And I will remember the rule of thumb to mix the code and defination in such cases. Thank you very much ! Best regards, Abinash Abinash Singh (2): serial: 8250_platform: Reduce stack usage in serial8250_probe_acpi() serial: 8250_platform: Reduce stack usage in serial8250_probe_platform() drivers/tty/serial/8250/8250_platform.c | 87 +++++++++++++------------ 1 file changed, 46 insertions(+), 41 deletions(-) -- 2.50.1
On Thu, Aug 07, 2025 at 03:21:32AM +0530, Abinash Singh wrote: > On Wed, 6 Aug 2025 23:39 Andy Shevchenko wrote: > > Have you had a chance to see Arnd's comments? > > > Yeah ,I have made comments on that. > Please check that and provide feedback. > > Hi, > Apologies for not reviewing the patch carefully before submitting it. > It's 3 A.M. here, and I’m still up, so I missed it If others are okay with this intermediate step, Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> -- With Best Regards, Andy Shevchenko
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 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 | 26 ++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_platform.c b/drivers/tty/serial/8250/8250_platform.c
index c0343bfb8064..9938aeb917d8 100644
--- a/drivers/tty/serial/8250/8250_platform.c
+++ b/drivers/tty/serial/8250/8250_platform.c
@@ -10,6 +10,7 @@
*/
#include <linux/acpi.h>
#include <linux/array_size.h>
+#include <linux/cleanup.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
@@ -110,41 +111,44 @@ 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 resource *regs;
int ret, line;
+ struct uart_8250_port *uart __free(kfree) = kzalloc(sizeof(*uart), GFP_KERNEL);
+ if (!uart)
+ return -ENOMEM;
+
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
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
© 2016 - 2025 Red Hat, Inc.