mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/2] usb: dwc3-of-simple: Use clk_bulk API
Date: Wed, 23 Sep 2020 11:03:58 +0200	[thread overview]
Message-ID: <20200923090358.26942-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20200923090358.26942-1-s.hauer@pengutronix.de>

Use clk_bulk_get_all() to retrieve all clocks rather than open code
this. Also actually enable the clocks, previously they had been disabled
in the error path, but never enabled before. Also this fixes a memory
corruption: The driver populated an array of clks, but only allocated
space for a single entry.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/dwc3/dwc3-of-simple.c | 58 ++++++-------------------------
 1 file changed, 10 insertions(+), 48 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-of-simple.c b/drivers/usb/dwc3/dwc3-of-simple.c
index a0aab4f114..ac16d22624 100644
--- a/drivers/usb/dwc3/dwc3-of-simple.c
+++ b/drivers/usb/dwc3/dwc3-of-simple.c
@@ -21,50 +21,16 @@
 
 struct dwc3_of_simple {
 	struct device_d		*dev;
-	struct clk		**clks;
+	struct clk_bulk_data	*clks;
 	int			num_clocks;
 };
 
-static int dwc3_of_simple_clk_init(struct dwc3_of_simple *simple, int count)
-{
-	struct device_d		*dev = simple->dev;
-	struct device_node	*np = dev->device_node;
-	int			i;
-
-	simple->num_clocks = count;
-
-	if (!count)
-		return 0;
-
-	simple->clks = xzalloc(sizeof(struct clk *));
-	if (!simple->clks)
-		return -ENOMEM;
-
-	for (i = 0; i < simple->num_clocks; i++) {
-		struct clk	*clk;
-
-		clk = of_clk_get(np, i);
-		if (IS_ERR(clk)) {
-			while (--i >= 0) {
-				clk_disable(simple->clks[i]);
-				clk_put(simple->clks[i]);
-			}
-			return PTR_ERR(clk);
-		}
-
-		simple->clks[i] = clk;
-	}
-
-	return 0;
-}
-
 static int dwc3_of_simple_probe(struct device_d *dev)
 {
 	struct dwc3_of_simple	*simple;
 	struct device_node	*np = dev->device_node;
 
 	int			ret;
-	int			i;
 
 	simple = xzalloc(sizeof(*simple));
 	if (!simple)
@@ -73,17 +39,18 @@ static int dwc3_of_simple_probe(struct device_d *dev)
 	dev->priv = simple;
 	simple->dev = dev;
 
-	ret = dwc3_of_simple_clk_init(simple, of_count_phandle_with_args(np,
-						"clocks", "#clock-cells"));
+	ret = clk_bulk_get_all(simple->dev, &simple->clks);
+	if (ret < 0)
+		return ret;
+
+	simple->num_clocks = ret;
+	ret = clk_bulk_enable(simple->num_clocks, simple->clks);
 	if (ret)
 		return ret;
 
-	ret = of_platform_populate(np, NULL, dev);
+        ret = of_platform_populate(np, NULL, dev);
 	if (ret) {
-		for (i = 0; i < simple->num_clocks; i++) {
-			clk_disable(simple->clks[i]);
-			clk_put(simple->clks[i]);
-		}
+		clk_bulk_disable(simple->num_clocks, simple->clks);
 		return ret;
 	}
 
@@ -93,13 +60,8 @@ static int dwc3_of_simple_probe(struct device_d *dev)
 static void dwc3_of_simple_remove(struct device_d *dev)
 {
 	struct dwc3_of_simple	*simple = dev->priv;
-	int			i;
 
-	for (i = 0; i < simple->num_clocks; i++) {
-		clk_disable(simple->clks[i]);
-		clk_put(simple->clks[i]);
-	}
-	simple->num_clocks = 0;
+	clk_bulk_disable(simple->num_clocks, simple->clks);
 }
 
 static const struct of_device_id of_dwc3_simple_match[] = {
-- 
2.28.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2020-09-23  9:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23  9:03 [PATCH 1/2] clk: Add clk_bulk_[get|put]_all() Sascha Hauer
2020-09-23  9:03 ` Sascha Hauer [this message]

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=20200923090358.26942-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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