2018-03-16 22:22:49

by Alexey Khoroshilov

[permalink] [raw]
Subject: [PATCH] spi: jcore: disable clock on remove

The driver does not disable ref_clk on remove.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <[email protected]>
---
drivers/spi/spi-jcore.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-jcore.c b/drivers/spi/spi-jcore.c
index dafed6280df3..68cac15ff54a 100644
--- a/drivers/spi/spi-jcore.c
+++ b/drivers/spi/spi-jcore.c
@@ -38,6 +38,7 @@ struct jcore_spi {
unsigned int speed_reg;
unsigned int speed_hz;
unsigned int clock_freq;
+ struct clk *clk;
};

static int jcore_spi_wait(void __iomem *ctrl_reg)
@@ -143,7 +144,6 @@ static int jcore_spi_probe(struct platform_device *pdev)
struct spi_master *master;
struct resource *res;
u32 clock_freq;
- struct clk *clk;
int err = -ENODEV;

master = spi_alloc_master(&pdev->dev, sizeof(struct jcore_spi));
@@ -183,10 +183,10 @@ static int jcore_spi_probe(struct platform_device *pdev)
* requested rate. If the clock is omitted, 50 MHz is assumed.
*/
clock_freq = 50000000;
- clk = devm_clk_get(&pdev->dev, "ref_clk");
- if (!IS_ERR_OR_NULL(clk)) {
- if (clk_enable(clk) == 0)
- clock_freq = clk_get_rate(clk);
+ hw->clk = devm_clk_get(&pdev->dev, "ref_clk");
+ if (!IS_ERR_OR_NULL(hw->clk)) {
+ if (clk_enable(hw->clk) == 0)
+ clock_freq = clk_get_rate(hw->clk);
else
dev_warn(&pdev->dev, "could not enable ref_clk\n");
}
@@ -199,7 +199,7 @@ static int jcore_spi_probe(struct platform_device *pdev)
/* Register our spi controller */
err = devm_spi_register_master(&pdev->dev, master);
if (err) {
- clk_disable(clk);
+ clk_disable(hw->clk);
goto exit;
}

@@ -212,6 +212,19 @@ static int jcore_spi_probe(struct platform_device *pdev)
return err;
}

+static int jcore_spi_remove(struct platform_device *pdev)
+{
+ struct spi_master *master;
+ struct jcore_spi *hw;
+
+ master = platform_get_drvdata(pdev);
+ hw = spi_master_get_devdata(master);
+
+ clk_disable(hw->clk);
+
+ return 0;
+}
+
static const struct of_device_id jcore_spi_of_match[] = {
{ .compatible = "jcore,spi2" },
{},
@@ -220,6 +233,7 @@ MODULE_DEVICE_TABLE(of, jcore_spi_of_match);

static struct platform_driver jcore_spi_driver = {
.probe = jcore_spi_probe,
+ .remove = jcore_spi_remove,
.driver = {
.name = DRV_NAME,
.of_match_table = jcore_spi_of_match,
--
2.7.4



2018-03-17 10:07:06

by Alexey Khoroshilov

[permalink] [raw]
Subject: [PATCH v2] spi: jcore: disable ref_clk after getting its rate

The driver does not disable ref_clk on remove.
According to the comment, the only reason to enable the clock is to get
its rate. So, it should be safe to disable clk just after that.

By the way, clk_prepare_enable() looks to be more appropriate
than clk_enable() here.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <[email protected]>
---
v2: There is no reason to wait for remove to disable ref_clk.

drivers/spi/spi-jcore.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-jcore.c b/drivers/spi/spi-jcore.c
index dafed6280df3..702fe573a47b 100644
--- a/drivers/spi/spi-jcore.c
+++ b/drivers/spi/spi-jcore.c
@@ -184,10 +184,11 @@ static int jcore_spi_probe(struct platform_device *pdev)
*/
clock_freq = 50000000;
clk = devm_clk_get(&pdev->dev, "ref_clk");
- if (!IS_ERR_OR_NULL(clk)) {
- if (clk_enable(clk) == 0)
+ if (!IS_ERR(clk)) {
+ if (clk_prepare_enable(clk) == 0) {
clock_freq = clk_get_rate(clk);
- else
+ clk_disable_unprepare(clk);
+ } else
dev_warn(&pdev->dev, "could not enable ref_clk\n");
}
hw->clock_freq = clock_freq;
@@ -198,10 +199,8 @@ static int jcore_spi_probe(struct platform_device *pdev)

/* Register our spi controller */
err = devm_spi_register_master(&pdev->dev, master);
- if (err) {
- clk_disable(clk);
+ if (err)
goto exit;
- }

return 0;

--
2.7.4


2018-03-19 01:16:20

by Mark Brown

[permalink] [raw]
Subject: Applied "spi: jcore: disable ref_clk after getting its rate" to the spi tree

The patch

spi: jcore: disable ref_clk after getting its rate

has been applied to the spi tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 7c2861a6fb2c502d7b7aa85415e178f3c527a468 Mon Sep 17 00:00:00 2001
From: Alexey Khoroshilov <[email protected]>
Date: Sat, 17 Mar 2018 13:05:44 +0300
Subject: [PATCH] spi: jcore: disable ref_clk after getting its rate

The driver does not disable ref_clk on remove.
According to the comment, the only reason to enable the clock is to get
its rate. So, it should be safe to disable clk just after that.

By the way, clk_prepare_enable() looks to be more appropriate
than clk_enable() here.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
---
drivers/spi/spi-jcore.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-jcore.c b/drivers/spi/spi-jcore.c
index dafed6280df3..702fe573a47b 100644
--- a/drivers/spi/spi-jcore.c
+++ b/drivers/spi/spi-jcore.c
@@ -184,10 +184,11 @@ static int jcore_spi_probe(struct platform_device *pdev)
*/
clock_freq = 50000000;
clk = devm_clk_get(&pdev->dev, "ref_clk");
- if (!IS_ERR_OR_NULL(clk)) {
- if (clk_enable(clk) == 0)
+ if (!IS_ERR(clk)) {
+ if (clk_prepare_enable(clk) == 0) {
clock_freq = clk_get_rate(clk);
- else
+ clk_disable_unprepare(clk);
+ } else
dev_warn(&pdev->dev, "could not enable ref_clk\n");
}
hw->clock_freq = clock_freq;
@@ -198,10 +199,8 @@ static int jcore_spi_probe(struct platform_device *pdev)

/* Register our spi controller */
err = devm_spi_register_master(&pdev->dev, master);
- if (err) {
- clk_disable(clk);
+ if (err)
goto exit;
- }

return 0;

--
2.16.2