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: qcom-geni: Dynamically allocate UART ports

Replace the static allocation of UART ports with dynamic allocation
using devm_kzalloc. This change removes the fixed-size array and instead
allocates each UART port structure on demand during probe, improving
memory efficiency and scalability.

Signed-off-by: Zong Jiang <quic_zongjian@quicinc.com>
Link: https://lore.kernel.org/r/20250812054819.3748649-2-quic_zongjian@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Zong Jiang and committed by
Greg Kroah-Hartman
c3e7966c 8672b18c

+12 -32
+12 -32
drivers/tty/serial/qcom_geni_serial.c
··· 164 164 return container_of(uport, struct qcom_geni_serial_port, uport); 165 165 } 166 166 167 - static struct qcom_geni_serial_port qcom_geni_uart_ports[GENI_UART_PORTS] = { 168 - [0] = { 169 - .uport = { 170 - .iotype = UPIO_MEM, 171 - .ops = &qcom_geni_uart_pops, 172 - .flags = UPF_BOOT_AUTOCONF, 173 - .line = 0, 174 - }, 175 - }, 176 - [1] = { 177 - .uport = { 178 - .iotype = UPIO_MEM, 179 - .ops = &qcom_geni_uart_pops, 180 - .flags = UPF_BOOT_AUTOCONF, 181 - .line = 1, 182 - }, 183 - }, 184 - [2] = { 185 - .uport = { 186 - .iotype = UPIO_MEM, 187 - .ops = &qcom_geni_uart_pops, 188 - .flags = UPF_BOOT_AUTOCONF, 189 - .line = 2, 190 - }, 191 - }, 192 - }; 193 - 194 167 static struct qcom_geni_serial_port qcom_geni_console_port = { 195 168 .uport = { 196 169 .iotype = UPIO_MEM, ··· 258 285 return "MSM"; 259 286 } 260 287 261 - static struct qcom_geni_serial_port *get_port_from_line(int line, bool console) 288 + static struct qcom_geni_serial_port *get_port_from_line(int line, bool console, struct device *dev) 262 289 { 263 290 struct qcom_geni_serial_port *port; 264 291 int nr_ports = console ? GENI_UART_CONS_PORTS : GENI_UART_PORTS; ··· 279 306 if (line < 0) 280 307 return ERR_PTR(-ENXIO); 281 308 282 - port = &qcom_geni_uart_ports[line]; 309 + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); 310 + if (!port) 311 + return ERR_PTR(-ENOMEM); 312 + 313 + port->uport.iotype = UPIO_MEM; 314 + port->uport.ops = &qcom_geni_uart_pops; 315 + port->uport.flags = UPF_BOOT_AUTOCONF; 316 + port->uport.line = line; 283 317 } 284 318 return port; 285 319 } ··· 534 554 535 555 WARN_ON(co->index < 0 || co->index >= GENI_UART_CONS_PORTS); 536 556 537 - port = get_port_from_line(co->index, true); 557 + port = get_port_from_line(co->index, true, NULL); 538 558 if (IS_ERR(port)) 539 559 return; 540 560 ··· 1491 1511 if (co->index >= GENI_UART_CONS_PORTS || co->index < 0) 1492 1512 return -ENXIO; 1493 1513 1494 - port = get_port_from_line(co->index, true); 1514 + port = get_port_from_line(co->index, true, NULL); 1495 1515 if (IS_ERR(port)) { 1496 1516 pr_err("Invalid line %d\n", co->index); 1497 1517 return PTR_ERR(port); ··· 1846 1866 line = of_alias_get_id(pdev->dev.of_node, "hsuart"); 1847 1867 } 1848 1868 1849 - port = get_port_from_line(line, data->console); 1869 + port = get_port_from_line(line, data->console, &pdev->dev); 1850 1870 if (IS_ERR(port)) { 1851 1871 dev_err(&pdev->dev, "Invalid line %d\n", line); 1852 1872 return PTR_ERR(port);