Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

serial: 8250_platform: Reduce stack usage in serial8250_probe_acpi()

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>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20250806215134.4921-2-abinashsinghlalotra@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Abinash Singh and committed by
Greg Kroah-Hartman
d9b76796 672a37ba

+15 -11
+15 -11
drivers/tty/serial/8250/8250_platform.c
··· 10 10 */ 11 11 #include <linux/acpi.h> 12 12 #include <linux/array_size.h> 13 + #include <linux/cleanup.h> 13 14 #include <linux/io.h> 14 15 #include <linux/module.h> 15 16 #include <linux/moduleparam.h> ··· 111 110 static int serial8250_probe_acpi(struct platform_device *pdev) 112 111 { 113 112 struct device *dev = &pdev->dev; 114 - struct uart_8250_port uart = { }; 115 113 struct resource *regs; 116 114 int ret, line; 115 + 116 + struct uart_8250_port *uart __free(kfree) = kzalloc(sizeof(*uart), GFP_KERNEL); 117 + if (!uart) 118 + return -ENOMEM; 117 119 118 120 regs = platform_get_mem_or_io(pdev, 0); 119 121 if (!regs) ··· 124 120 125 121 switch (resource_type(regs)) { 126 122 case IORESOURCE_IO: 127 - uart.port.iobase = regs->start; 123 + uart->port.iobase = regs->start; 128 124 break; 129 125 case IORESOURCE_MEM: 130 - uart.port.mapbase = regs->start; 131 - uart.port.mapsize = resource_size(regs); 132 - uart.port.flags = UPF_IOREMAP; 126 + uart->port.mapbase = regs->start; 127 + uart->port.mapsize = resource_size(regs); 128 + uart->port.flags = UPF_IOREMAP; 133 129 break; 134 130 default: 135 131 return -EINVAL; 136 132 } 137 133 138 134 /* default clock frequency */ 139 - uart.port.uartclk = 1843200; 140 - uart.port.type = PORT_16550A; 141 - uart.port.dev = &pdev->dev; 142 - uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; 135 + uart->port.uartclk = 1843200; 136 + uart->port.type = PORT_16550A; 137 + uart->port.dev = &pdev->dev; 138 + uart->port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; 143 139 144 - ret = uart_read_and_validate_port_properties(&uart.port); 140 + ret = uart_read_and_validate_port_properties(&uart->port); 145 141 /* no interrupt -> fall back to polling */ 146 142 if (ret == -ENXIO) 147 143 ret = 0; 148 144 if (ret) 149 145 return ret; 150 146 151 - line = serial8250_register_8250_port(&uart); 147 + line = serial8250_register_8250_port(uart); 152 148 if (line < 0) 153 149 return line; 154 150