* [PATCH v1 1/1] serial: liteuart: Don't mix devm_*() with non-devm_*() calls
@ 2023-01-23 19:17 Andy Shevchenko
2023-01-23 20:05 ` Gabriel L. Somlo
0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2023-01-23 19:17 UTC (permalink / raw)
To: Greg Kroah-Hartman, Gabriel Somlo, Jiri Slaby, Ilpo Järvinen,
linux-serial, linux-kernel
Cc: Karol Gugala, Mateusz Holenko, Joel Stanley, Andy Shevchenko
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 <andriy.shevchenko@linux.intel.com>
---
drivers/tty/serial/liteuart.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 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,37 +286,35 @@ static int liteuart_probe(struct platform_device *pdev)
struct xa_limit limit;
int dev_id, 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)
- limit = XA_LIMIT(0, CONFIG_SERIAL_LITEUART_MAX_PORTS);
- 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;
- }
+ if (IS_ERR(port->membase))
+ return PTR_ERR(port->membase);
ret = platform_get_irq_optional(pdev, 0);
if (ret < 0 && ret != -ENXIO)
- goto err_erase_id;
+ 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)
+ limit = XA_LIMIT(0, CONFIG_SERIAL_LITEUART_MAX_PORTS);
+ else
+ limit = XA_LIMIT(dev_id, dev_id);
+
+ ret = xa_alloc(&liteuart_array, &dev_id, uart, limit, GFP_KERNEL);
+ if (ret)
+ return ret;
+
+ uart->id = dev_id;
/* values not from device tree */
port->dev = &pdev->dev;
port->iotype = UPIO_MEM;
--
2.39.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1 1/1] serial: liteuart: Don't mix devm_*() with non-devm_*() calls
2023-01-23 19:17 [PATCH v1 1/1] serial: liteuart: Don't mix devm_*() with non-devm_*() calls Andy Shevchenko
@ 2023-01-23 20:05 ` Gabriel L. Somlo
0 siblings, 0 replies; 2+ messages in thread
From: Gabriel L. Somlo @ 2023-01-23 20:05 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Greg Kroah-Hartman, Jiri Slaby, Ilpo Järvinen, linux-serial,
linux-kernel, Karol Gugala, Mateusz Holenko, Joel Stanley
On Mon, Jan 23, 2023 at 09:17:41PM +0200, Andy Shevchenko wrote:
> 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 <andriy.shevchenko@linux.intel.com>
> ---
> drivers/tty/serial/liteuart.c | 32 +++++++++++++++-----------------
> 1 file changed, 15 insertions(+), 17 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,37 +286,35 @@ static int liteuart_probe(struct platform_device *pdev)
> struct xa_limit limit;
> int dev_id, 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)
> - limit = XA_LIMIT(0, CONFIG_SERIAL_LITEUART_MAX_PORTS);
> - 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;
> - }
> + if (IS_ERR(port->membase))
> + return PTR_ERR(port->membase);
>
> ret = platform_get_irq_optional(pdev, 0);
> if (ret < 0 && ret != -ENXIO)
> - goto err_erase_id;
> + 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)
> + limit = XA_LIMIT(0, CONFIG_SERIAL_LITEUART_MAX_PORTS);
> + else
> + limit = XA_LIMIT(dev_id, dev_id);
> +
> + ret = xa_alloc(&liteuart_array, &dev_id, uart, limit, GFP_KERNEL);
> + if (ret)
> + return ret;
> +
> + uart->id = dev_id;
> /* values not from device tree */
> port->dev = &pdev->dev;
> port->iotype = UPIO_MEM;
Reviewed-by: Gabriel Somlo <somlo@cmu.edu>
Thanks,
--Gabriel
> --
> 2.39.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-23 20:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-23 19:17 [PATCH v1 1/1] serial: liteuart: Don't mix devm_*() with non-devm_*() calls Andy Shevchenko
2023-01-23 20:05 ` Gabriel L. Somlo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox