From: Wang Zhang <silver_code@hust.edu.cn>
To: Peter Korsgaard <peter@korsgaard.com>,
Andrew Lunn <andrew@lunn.ch>, Wolfram Sang <wsa@kernel.org>,
Andreas Larsson <andreas@gaisler.com>
Cc: hust-os-kernel-patches@googlegroups.com,
Wang Zhang <silver_code@hust.edu.cn>,
Peter Korsgaard <jacmet@sunsite.dk>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v4] i2c: ocores: use devm_ managed clks
Date: Fri, 26 May 2023 15:05:33 +0800 [thread overview]
Message-ID: <20230526070534.76112-1-silver_code@hust.edu.cn> (raw)
In-Reply-To: <b5c00122-0fe0-4020-9036-e4cc37d1b51a@lunn.ch>
Smatch complains that:
drivers/i2c/busses/i2c-ocores.c:704 ocores_i2c_probe()
warn: missing unwind goto?
If any wrong occurs in ocores_i2c_of_probe, the i2c->clk needs to be
released. But the function returns directly without freeing the clock.
Fix this by updating the code to use devm_clk_get_optional_enabled()
instead. Use dev_err_probe() where appropriate as well since we are
changing those statements.
Fixes: f5f35a92e44a ("i2c: ocores: Add irq support for sparc")
Signed-off-by: Wang Zhang <silver_code@hust.edu.cn>
---
v3->v4: use `dev_err_probe` to compact the code and add a fixes tag
v2->v3: use `devm_clk_get_optional_enabled()` to manage clks
v1->v2: change `ocores_i2c_of_probe` to use `devm_clk_get_enabled()`
---
drivers/i2c/busses/i2c-ocores.c | 64 +++++++++++----------------------
1 file changed, 21 insertions(+), 43 deletions(-)
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 2e575856c5cd..e30df2b78fdf 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -552,28 +552,20 @@ static int ocores_i2c_of_probe(struct platform_device *pdev,
&clock_frequency);
i2c->bus_clock_khz = 100;
- i2c->clk = devm_clk_get(&pdev->dev, NULL);
-
- if (!IS_ERR(i2c->clk)) {
- int ret = clk_prepare_enable(i2c->clk);
-
- if (ret) {
- dev_err(&pdev->dev,
- "clk_prepare_enable failed: %d\n", ret);
- return ret;
- }
- i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000;
- if (clock_frequency_present)
- i2c->bus_clock_khz = clock_frequency / 1000;
- }
-
+ i2c->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
+ if (IS_ERR(i2c->clk))
+ return dev_err_probe(&pdev->dev, PTR_ERR(i2c->clk),
+ "devm_clk_get_optional_enabled failed\n");
+
+ i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000;
+ if (clock_frequency_present)
+ i2c->bus_clock_khz = clock_frequency / 1000;
if (i2c->ip_clock_khz == 0) {
if (of_property_read_u32(np, "opencores,ip-clock-frequency",
&val)) {
if (!clock_frequency_present) {
dev_err(&pdev->dev,
"Missing required parameter 'opencores,ip-clock-frequency'\n");
- clk_disable_unprepare(i2c->clk);
return -ENODEV;
}
i2c->ip_clock_khz = clock_frequency / 1000;
@@ -678,8 +670,7 @@ static int ocores_i2c_probe(struct platform_device *pdev)
default:
dev_err(&pdev->dev, "Unsupported I/O width (%d)\n",
i2c->reg_io_width);
- ret = -EINVAL;
- goto err_clk;
+ return -EINVAL;
}
}
@@ -710,13 +701,13 @@ static int ocores_i2c_probe(struct platform_device *pdev)
pdev->name, i2c);
if (ret) {
dev_err(&pdev->dev, "Cannot claim IRQ\n");
- goto err_clk;
+ return ret;
}
}
ret = ocores_init(&pdev->dev, i2c);
if (ret)
- goto err_clk;
+ return ret;
/* hook up driver to tree */
platform_set_drvdata(pdev, i2c);
@@ -728,7 +719,7 @@ static int ocores_i2c_probe(struct platform_device *pdev)
/* add i2c adapter to i2c tree */
ret = i2c_add_adapter(&i2c->adap);
if (ret)
- goto err_clk;
+ return ret;
/* add in known devices to the bus */
if (pdata) {
@@ -737,10 +728,6 @@ static int ocores_i2c_probe(struct platform_device *pdev)
}
return 0;
-
-err_clk:
- clk_disable_unprepare(i2c->clk);
- return ret;
}
static int ocores_i2c_remove(struct platform_device *pdev)
@@ -755,9 +742,6 @@ static int ocores_i2c_remove(struct platform_device *pdev)
/* remove adapter & data */
i2c_del_adapter(&i2c->adap);
- if (!IS_ERR(i2c->clk))
- clk_disable_unprepare(i2c->clk);
-
return 0;
}
@@ -771,28 +755,22 @@ static int ocores_i2c_suspend(struct device *dev)
ctrl &= ~(OCI2C_CTRL_EN | OCI2C_CTRL_IEN);
oc_setreg(i2c, OCI2C_CONTROL, ctrl);
- if (!IS_ERR(i2c->clk))
- clk_disable_unprepare(i2c->clk);
+ clk_disable_unprepare(i2c->clk);
return 0;
}
static int ocores_i2c_resume(struct device *dev)
{
struct ocores_i2c *i2c = dev_get_drvdata(dev);
+ unsigned long rate;
+ int ret;
- if (!IS_ERR(i2c->clk)) {
- unsigned long rate;
- int ret = clk_prepare_enable(i2c->clk);
-
- if (ret) {
- dev_err(dev,
- "clk_prepare_enable failed: %d\n", ret);
- return ret;
- }
- rate = clk_get_rate(i2c->clk) / 1000;
- if (rate)
- i2c->ip_clock_khz = rate;
- }
+ ret = clk_prepare_enable(i2c->clk);
+ if (ret)
+ return dev_err_probe(dev, ret, "clk_prepare_enable failed\n");
+ rate = clk_get_rate(i2c->clk) / 1000;
+ if (rate)
+ i2c->ip_clock_khz = rate;
return ocores_init(dev, i2c);
}
--
2.34.1
next prev parent reply other threads:[~2023-05-26 7:07 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-16 7:20 [PATCH] i2c: ocores: add missing unwind goto in `ocores_i2c_probe` Wang Zhang
2023-04-16 15:33 ` Andrew Lunn
2023-04-17 13:27 ` [PATCH v2] i2c: ocores: use devm_ managed clks Wang Zhang
2023-04-17 14:05 ` Wang Zhang
2023-04-17 14:29 ` Peter Rosin
2023-04-17 15:50 ` Andrew Lunn
2023-04-22 12:32 ` [PATCH v3] " Wang Zhang
2023-04-25 9:58 ` 张网
2023-04-25 11:57 ` Andrew Lunn
2023-04-25 14:47 ` 张网
2023-04-25 15:06 ` Andrew Lunn
2023-05-26 7:05 ` Wang Zhang [this message]
2023-06-13 23:54 ` [PATCH v4] " Andi Shyti
2023-06-23 8:22 ` Wolfram Sang
2023-06-23 8:26 ` Wolfram Sang
2023-05-23 4:49 ` Re: [PATCH v3] " 张网
2023-05-23 12:10 ` Andrew Lunn
2023-05-23 14:33 ` Wang Zhang
2023-05-24 15:35 ` Wang Zhang
2023-05-24 15:43 ` Wang Zhang
2023-05-24 18:45 ` Dan Carpenter
2023-05-24 19:21 ` Christophe JAILLET
2023-05-25 3:33 ` 张网
2023-05-25 19:16 ` Christophe JAILLET
2023-05-25 5:05 ` Dan Carpenter
2023-05-25 5:02 ` Dan Carpenter
2023-05-25 9:28 ` Dan Carpenter
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=20230526070534.76112-1-silver_code@hust.edu.cn \
--to=silver_code@hust.edu.cn \
--cc=andreas@gaisler.com \
--cc=andrew@lunn.ch \
--cc=hust-os-kernel-patches@googlegroups.com \
--cc=jacmet@sunsite.dk \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peter@korsgaard.com \
--cc=wsa@kernel.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