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_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 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-3-abinashsinghlalotra@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Abinash Singh and committed by
Greg Kroah-Hartman
bd673d2b d9b76796

+31 -30
+31 -30
drivers/tty/serial/8250/8250_platform.c
··· 157 157 158 158 static int serial8250_probe_platform(struct platform_device *dev, struct plat_serial8250_port *p) 159 159 { 160 - struct uart_8250_port uart; 161 160 int ret, i, irqflag = 0; 162 161 163 - memset(&uart, 0, sizeof(uart)); 162 + struct uart_8250_port *uart __free(kfree) = kzalloc(sizeof(*uart), GFP_KERNEL); 163 + if (!uart) 164 + return -ENOMEM; 164 165 165 166 if (share_irqs) 166 167 irqflag = IRQF_SHARED; 167 168 168 169 for (i = 0; p && p->flags != 0; p++, i++) { 169 - uart.port.iobase = p->iobase; 170 - uart.port.membase = p->membase; 171 - uart.port.irq = p->irq; 172 - uart.port.irqflags = p->irqflags; 173 - uart.port.uartclk = p->uartclk; 174 - uart.port.regshift = p->regshift; 175 - uart.port.iotype = p->iotype; 176 - uart.port.flags = p->flags; 177 - uart.port.mapbase = p->mapbase; 178 - uart.port.mapsize = p->mapsize; 179 - uart.port.hub6 = p->hub6; 180 - uart.port.has_sysrq = p->has_sysrq; 181 - uart.port.private_data = p->private_data; 182 - uart.port.type = p->type; 183 - uart.bugs = p->bugs; 184 - uart.port.serial_in = p->serial_in; 185 - uart.port.serial_out = p->serial_out; 186 - uart.dl_read = p->dl_read; 187 - uart.dl_write = p->dl_write; 188 - uart.port.handle_irq = p->handle_irq; 189 - uart.port.handle_break = p->handle_break; 190 - uart.port.set_termios = p->set_termios; 191 - uart.port.set_ldisc = p->set_ldisc; 192 - uart.port.get_mctrl = p->get_mctrl; 193 - uart.port.pm = p->pm; 194 - uart.port.dev = &dev->dev; 195 - uart.port.irqflags |= irqflag; 196 - ret = serial8250_register_8250_port(&uart); 170 + uart->port.iobase = p->iobase; 171 + uart->port.membase = p->membase; 172 + uart->port.irq = p->irq; 173 + uart->port.irqflags = p->irqflags; 174 + uart->port.uartclk = p->uartclk; 175 + uart->port.regshift = p->regshift; 176 + uart->port.iotype = p->iotype; 177 + uart->port.flags = p->flags; 178 + uart->port.mapbase = p->mapbase; 179 + uart->port.mapsize = p->mapsize; 180 + uart->port.hub6 = p->hub6; 181 + uart->port.has_sysrq = p->has_sysrq; 182 + uart->port.private_data = p->private_data; 183 + uart->port.type = p->type; 184 + uart->bugs = p->bugs; 185 + uart->port.serial_in = p->serial_in; 186 + uart->port.serial_out = p->serial_out; 187 + uart->dl_read = p->dl_read; 188 + uart->dl_write = p->dl_write; 189 + uart->port.handle_irq = p->handle_irq; 190 + uart->port.handle_break = p->handle_break; 191 + uart->port.set_termios = p->set_termios; 192 + uart->port.set_ldisc = p->set_ldisc; 193 + uart->port.get_mctrl = p->get_mctrl; 194 + uart->port.pm = p->pm; 195 + uart->port.dev = &dev->dev; 196 + uart->port.irqflags |= irqflag; 197 + ret = serial8250_register_8250_port(uart); 197 198 if (ret < 0) { 198 199 dev_err(&dev->dev, "unable to register port at index %d " 199 200 "(IO%lx MEM%llx IRQ%d): %d\n", i,