summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-08-27 09:31:04 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-09-24 11:42:01 +0200
commit8fb0a2bf6efb67084a5d7a7f3822b4d480fca685 (patch)
treefb2dbd855df5b9889eb5bb1e1babeba9a0db3669
parenta16f065ae6c17704afe4ed6a4fd3772285a86e6e (diff)
downloadbarebox-8fb0a2bf6efb67084a5d7a7f3822b4d480fca685.tar.gz
barebox-8fb0a2bf6efb67084a5d7a7f3822b4d480fca685.tar.xz
usb: dwc3-of-simple: Use clk_bulk API
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>
-rw-r--r--drivers/usb/dwc3/dwc3-of-simple.c58
1 files 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[] = {