public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Gabriel Somlo" <gsomlo@gmail.com>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Karol Gugala <kgugala@antmicro.com>,
	Mateusz Holenko <mholenko@antmicro.com>,
	Joel Stanley <joel@jms.id.au>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 1/1] serial: liteuart: Don't mix devm_*() with non-devm_*() calls
Date: Mon, 23 Jan 2023 21:17:41 +0200	[thread overview]
Message-ID: <20230123191741.79751-1-andriy.shevchenko@linux.intel.com> (raw)

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


             reply	other threads:[~2023-01-23 19:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23 19:17 Andy Shevchenko [this message]
2023-01-23 20:05 ` [PATCH v1 1/1] serial: liteuart: Don't mix devm_*() with non-devm_*() calls Gabriel L. Somlo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230123191741.79751-1-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gsomlo@gmail.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=joel@jms.id.au \
    --cc=kgugala@antmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mholenko@antmicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox