]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
serial: qcom-geni: Dynamically allocate UART ports
authorZong Jiang <quic_zongjian@quicinc.com>
Tue, 12 Aug 2025 05:48:18 +0000 (13:48 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 14 Aug 2025 09:59:29 +0000 (11:59 +0200)
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>
drivers/tty/serial/qcom_geni_serial.c

index 32ec632fd0807fd0a41afe3713ec2145d05ba2a9..080c18ddbdde16deca484a49d1d4da93f958dfc8 100644 (file)
@@ -164,33 +164,6 @@ static inline struct qcom_geni_serial_port *to_dev_port(struct uart_port *uport)
        return container_of(uport, struct qcom_geni_serial_port, uport);
 }
 
-static struct qcom_geni_serial_port qcom_geni_uart_ports[GENI_UART_PORTS] = {
-       [0] = {
-               .uport = {
-                       .iotype = UPIO_MEM,
-                       .ops = &qcom_geni_uart_pops,
-                       .flags = UPF_BOOT_AUTOCONF,
-                       .line = 0,
-               },
-       },
-       [1] = {
-               .uport = {
-                       .iotype = UPIO_MEM,
-                       .ops = &qcom_geni_uart_pops,
-                       .flags = UPF_BOOT_AUTOCONF,
-                       .line = 1,
-               },
-       },
-       [2] = {
-               .uport = {
-                       .iotype = UPIO_MEM,
-                       .ops = &qcom_geni_uart_pops,
-                       .flags = UPF_BOOT_AUTOCONF,
-                       .line = 2,
-               },
-       },
-};
-
 static struct qcom_geni_serial_port qcom_geni_console_port = {
        .uport = {
                .iotype = UPIO_MEM,
@@ -285,7 +258,7 @@ static const char *qcom_geni_serial_get_type(struct uart_port *uport)
        return "MSM";
 }
 
-static struct qcom_geni_serial_port *get_port_from_line(int line, bool console)
+static struct qcom_geni_serial_port *get_port_from_line(int line, bool console, struct device *dev)
 {
        struct qcom_geni_serial_port *port;
        int nr_ports = console ? GENI_UART_CONS_PORTS : GENI_UART_PORTS;
@@ -306,7 +279,14 @@ static struct qcom_geni_serial_port *get_port_from_line(int line, bool console)
                if (line < 0)
                        return ERR_PTR(-ENXIO);
 
-               port = &qcom_geni_uart_ports[line];
+               port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
+               if (!port)
+                       return ERR_PTR(-ENOMEM);
+
+               port->uport.iotype = UPIO_MEM;
+               port->uport.ops = &qcom_geni_uart_pops;
+               port->uport.flags = UPF_BOOT_AUTOCONF;
+               port->uport.line = line;
        }
        return port;
 }
@@ -554,7 +534,7 @@ static void qcom_geni_serial_console_write(struct console *co, const char *s,
 
        WARN_ON(co->index < 0 || co->index >= GENI_UART_CONS_PORTS);
 
-       port = get_port_from_line(co->index, true);
+       port = get_port_from_line(co->index, true, NULL);
        if (IS_ERR(port))
                return;
 
@@ -1511,7 +1491,7 @@ static int qcom_geni_console_setup(struct console *co, char *options)
        if (co->index >= GENI_UART_CONS_PORTS  || co->index < 0)
                return -ENXIO;
 
-       port = get_port_from_line(co->index, true);
+       port = get_port_from_line(co->index, true, NULL);
        if (IS_ERR(port)) {
                pr_err("Invalid line %d\n", co->index);
                return PTR_ERR(port);
@@ -1866,7 +1846,7 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
                        line = of_alias_get_id(pdev->dev.of_node, "hsuart");
        }
 
-       port = get_port_from_line(line, data->console);
+       port = get_port_from_line(line, data->console, &pdev->dev);
        if (IS_ERR(port)) {
                dev_err(&pdev->dev, "Invalid line %d\n", line);
                return PTR_ERR(port);