From 297cb3f0b94bfedd781426814f1798a5c5658050 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 23 Jan 2023 21:17:41 +0200 Subject: [PATCH] serial: liteuart: Don't mix devm_*() with non-devm_*() calls In the probe we need to call all devm_*() first followed by non-devm_*() calls. This is due to reversed clean up that may happen in a wrong order otherwise. The driver currently allocates xarray before calling devm_platform_get_and_ioremap_resource(). While it's not an issue in this certain case, it's still better to be pedantic. Signed-off-by: Andy Shevchenko Reviewed-by: Gabriel Somlo Link: https://lore.kernel.org/r/20230123191741.79751-1-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/liteuart.c | 36 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/tty/serial/liteuart.c b/drivers/tty/serial/liteuart.c index 192ad681de35..562892395570 100644 --- a/drivers/tty/serial/liteuart.c +++ b/drivers/tty/serial/liteuart.c @@ -286,6 +286,23 @@ static int liteuart_probe(struct platform_device *pdev) struct xa_limit limit; int dev_id, ret; + uart = devm_kzalloc(&pdev->dev, sizeof(struct liteuart_port), GFP_KERNEL); + if (!uart) + return -ENOMEM; + + port = &uart->port; + + /* get membase */ + port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); + if (IS_ERR(port->membase)) + return PTR_ERR(port->membase); + + ret = platform_get_irq_optional(pdev, 0); + if (ret < 0 && ret != -ENXIO) + return ret; + if (ret > 0) + port->irq = ret; + /* look for aliases; auto-enumerate for free index if not found */ dev_id = of_alias_get_id(pdev->dev.of_node, "serial"); if (dev_id < 0) @@ -293,30 +310,11 @@ static int liteuart_probe(struct platform_device *pdev) else limit = XA_LIMIT(dev_id, dev_id); - uart = devm_kzalloc(&pdev->dev, sizeof(struct liteuart_port), GFP_KERNEL); - if (!uart) - return -ENOMEM; - ret = xa_alloc(&liteuart_array, &dev_id, uart, limit, GFP_KERNEL); if (ret) return ret; uart->id = dev_id; - port = &uart->port; - - /* get membase */ - port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); - if (IS_ERR(port->membase)) { - ret = PTR_ERR(port->membase); - goto err_erase_id; - } - - ret = platform_get_irq_optional(pdev, 0); - if (ret < 0 && ret != -ENXIO) - goto err_erase_id; - if (ret > 0) - port->irq = ret; - /* values not from device tree */ port->dev = &pdev->dev; port->iotype = UPIO_MEM;