linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe()
@ 2024-01-06 12:48 Christophe JAILLET
  2024-01-06 12:48 ` [PATCH 2/2] i2c: synquacer: Remove a clk reference from struct synquacer_i2c Christophe JAILLET
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Christophe JAILLET @ 2024-01-06 12:48 UTC (permalink / raw)
  To: Ard Biesheuvel, Andi Shyti, Andy Shevchenko, Wolfram Sang
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-i2c

If an error occurs after the clk_prepare_enable() call, it should be undone
by a corresponding clk_disable_unprepare() call, as already done in the
remove() function.

As devm_clk_get() is used, we can switch to devm_clk_get_enabled() to
handle it automatically and fix the probe.

Update the remove() function accordingly and remove the now useless
clk_disable_unprepare() call.

Fixes: 0d676a6c4390 ("i2c: add support for Socionext SynQuacer I2C controller")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/i2c/busses/i2c-synquacer.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
index bbea521b05dd..a73f5bb9a164 100644
--- a/drivers/i2c/busses/i2c-synquacer.c
+++ b/drivers/i2c/busses/i2c-synquacer.c
@@ -550,17 +550,13 @@ static int synquacer_i2c_probe(struct platform_device *pdev)
 	device_property_read_u32(&pdev->dev, "socionext,pclk-rate",
 				 &i2c->pclkrate);
 
-	i2c->pclk = devm_clk_get(&pdev->dev, "pclk");
-	if (PTR_ERR(i2c->pclk) == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
-	if (!IS_ERR_OR_NULL(i2c->pclk)) {
-		dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
-
-		ret = clk_prepare_enable(i2c->pclk);
-		if (ret)
-			return dev_err_probe(&pdev->dev, ret, "failed to enable clock\n");
-		i2c->pclkrate = clk_get_rate(i2c->pclk);
-	}
+	i2c->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
+	if (IS_ERR(i2c->pclk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(i2c->pclk),
+				     "failed to get and enable clock\n");
+
+	dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
+	i2c->pclkrate = clk_get_rate(i2c->pclk);
 
 	if (i2c->pclkrate < SYNQUACER_I2C_MIN_CLK_RATE ||
 	    i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE)
@@ -615,8 +611,6 @@ static void synquacer_i2c_remove(struct platform_device *pdev)
 	struct synquacer_i2c *i2c = platform_get_drvdata(pdev);
 
 	i2c_del_adapter(&i2c->adapter);
-	if (!IS_ERR(i2c->pclk))
-		clk_disable_unprepare(i2c->pclk);
 };
 
 static const struct of_device_id synquacer_i2c_dt_ids[] __maybe_unused = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] i2c: synquacer: Remove a clk reference from struct synquacer_i2c
  2024-01-06 12:48 [PATCH 1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe() Christophe JAILLET
@ 2024-01-06 12:48 ` Christophe JAILLET
  2024-01-12 17:50   ` Ard Biesheuvel
  2024-05-06  9:04   ` Andi Shyti
  2024-01-12 17:50 ` [PATCH 1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe() Ard Biesheuvel
  2024-05-06  9:03 ` Andi Shyti
  2 siblings, 2 replies; 6+ messages in thread
From: Christophe JAILLET @ 2024-01-06 12:48 UTC (permalink / raw)
  To: Ard Biesheuvel, Andi Shyti
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-i2c

'pclk' is only used locally in the probe. Remove it from the
'synquacer_i2c' structure.

Also remove a useless debug message.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/i2c/busses/i2c-synquacer.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
index a73f5bb9a164..e774b9f499b6 100644
--- a/drivers/i2c/busses/i2c-synquacer.c
+++ b/drivers/i2c/busses/i2c-synquacer.c
@@ -138,7 +138,6 @@ struct synquacer_i2c {
 	int			irq;
 	struct device		*dev;
 	void __iomem		*base;
-	struct clk		*pclk;
 	u32			pclkrate;
 	u32			speed_khz;
 	u32			timeout_ms;
@@ -535,6 +534,7 @@ static const struct i2c_adapter synquacer_i2c_ops = {
 static int synquacer_i2c_probe(struct platform_device *pdev)
 {
 	struct synquacer_i2c *i2c;
+	struct clk *pclk;
 	u32 bus_speed;
 	int ret;
 
@@ -550,13 +550,12 @@ static int synquacer_i2c_probe(struct platform_device *pdev)
 	device_property_read_u32(&pdev->dev, "socionext,pclk-rate",
 				 &i2c->pclkrate);
 
-	i2c->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
-	if (IS_ERR(i2c->pclk))
-		return dev_err_probe(&pdev->dev, PTR_ERR(i2c->pclk),
+	pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
+	if (IS_ERR(pclk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(pclk),
 				     "failed to get and enable clock\n");
 
-	dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
-	i2c->pclkrate = clk_get_rate(i2c->pclk);
+	i2c->pclkrate = clk_get_rate(pclk);
 
 	if (i2c->pclkrate < SYNQUACER_I2C_MIN_CLK_RATE ||
 	    i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe()
  2024-01-06 12:48 [PATCH 1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe() Christophe JAILLET
  2024-01-06 12:48 ` [PATCH 2/2] i2c: synquacer: Remove a clk reference from struct synquacer_i2c Christophe JAILLET
@ 2024-01-12 17:50 ` Ard Biesheuvel
  2024-05-06  9:03 ` Andi Shyti
  2 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2024-01-12 17:50 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Andi Shyti, Andy Shevchenko, Wolfram Sang, linux-kernel,
	kernel-janitors, linux-i2c

On Sat, 6 Jan 2024 at 13:48, Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> If an error occurs after the clk_prepare_enable() call, it should be undone
> by a corresponding clk_disable_unprepare() call, as already done in the
> remove() function.
>
> As devm_clk_get() is used, we can switch to devm_clk_get_enabled() to
> handle it automatically and fix the probe.
>
> Update the remove() function accordingly and remove the now useless
> clk_disable_unprepare() call.
>
> Fixes: 0d676a6c4390 ("i2c: add support for Socionext SynQuacer I2C controller")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  drivers/i2c/busses/i2c-synquacer.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
> index bbea521b05dd..a73f5bb9a164 100644
> --- a/drivers/i2c/busses/i2c-synquacer.c
> +++ b/drivers/i2c/busses/i2c-synquacer.c
> @@ -550,17 +550,13 @@ static int synquacer_i2c_probe(struct platform_device *pdev)
>         device_property_read_u32(&pdev->dev, "socionext,pclk-rate",
>                                  &i2c->pclkrate);
>
> -       i2c->pclk = devm_clk_get(&pdev->dev, "pclk");
> -       if (PTR_ERR(i2c->pclk) == -EPROBE_DEFER)
> -               return -EPROBE_DEFER;
> -       if (!IS_ERR_OR_NULL(i2c->pclk)) {
> -               dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
> -
> -               ret = clk_prepare_enable(i2c->pclk);
> -               if (ret)
> -                       return dev_err_probe(&pdev->dev, ret, "failed to enable clock\n");
> -               i2c->pclkrate = clk_get_rate(i2c->pclk);
> -       }
> +       i2c->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
> +       if (IS_ERR(i2c->pclk))
> +               return dev_err_probe(&pdev->dev, PTR_ERR(i2c->pclk),
> +                                    "failed to get and enable clock\n");
> +
> +       dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
> +       i2c->pclkrate = clk_get_rate(i2c->pclk);
>
>         if (i2c->pclkrate < SYNQUACER_I2C_MIN_CLK_RATE ||
>             i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE)
> @@ -615,8 +611,6 @@ static void synquacer_i2c_remove(struct platform_device *pdev)
>         struct synquacer_i2c *i2c = platform_get_drvdata(pdev);
>
>         i2c_del_adapter(&i2c->adapter);
> -       if (!IS_ERR(i2c->pclk))
> -               clk_disable_unprepare(i2c->pclk);
>  };
>
>  static const struct of_device_id synquacer_i2c_dt_ids[] __maybe_unused = {
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] i2c: synquacer: Remove a clk reference from struct synquacer_i2c
  2024-01-06 12:48 ` [PATCH 2/2] i2c: synquacer: Remove a clk reference from struct synquacer_i2c Christophe JAILLET
@ 2024-01-12 17:50   ` Ard Biesheuvel
  2024-05-06  9:04   ` Andi Shyti
  1 sibling, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2024-01-12 17:50 UTC (permalink / raw)
  To: Christophe JAILLET; +Cc: Andi Shyti, linux-kernel, kernel-janitors, linux-i2c

On Sat, 6 Jan 2024 at 13:48, Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> 'pclk' is only used locally in the probe. Remove it from the
> 'synquacer_i2c' structure.
>
> Also remove a useless debug message.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  drivers/i2c/busses/i2c-synquacer.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
> index a73f5bb9a164..e774b9f499b6 100644
> --- a/drivers/i2c/busses/i2c-synquacer.c
> +++ b/drivers/i2c/busses/i2c-synquacer.c
> @@ -138,7 +138,6 @@ struct synquacer_i2c {
>         int                     irq;
>         struct device           *dev;
>         void __iomem            *base;
> -       struct clk              *pclk;
>         u32                     pclkrate;
>         u32                     speed_khz;
>         u32                     timeout_ms;
> @@ -535,6 +534,7 @@ static const struct i2c_adapter synquacer_i2c_ops = {
>  static int synquacer_i2c_probe(struct platform_device *pdev)
>  {
>         struct synquacer_i2c *i2c;
> +       struct clk *pclk;
>         u32 bus_speed;
>         int ret;
>
> @@ -550,13 +550,12 @@ static int synquacer_i2c_probe(struct platform_device *pdev)
>         device_property_read_u32(&pdev->dev, "socionext,pclk-rate",
>                                  &i2c->pclkrate);
>
> -       i2c->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
> -       if (IS_ERR(i2c->pclk))
> -               return dev_err_probe(&pdev->dev, PTR_ERR(i2c->pclk),
> +       pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
> +       if (IS_ERR(pclk))
> +               return dev_err_probe(&pdev->dev, PTR_ERR(pclk),
>                                      "failed to get and enable clock\n");
>
> -       dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
> -       i2c->pclkrate = clk_get_rate(i2c->pclk);
> +       i2c->pclkrate = clk_get_rate(pclk);
>
>         if (i2c->pclkrate < SYNQUACER_I2C_MIN_CLK_RATE ||
>             i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE)
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe()
  2024-01-06 12:48 [PATCH 1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe() Christophe JAILLET
  2024-01-06 12:48 ` [PATCH 2/2] i2c: synquacer: Remove a clk reference from struct synquacer_i2c Christophe JAILLET
  2024-01-12 17:50 ` [PATCH 1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe() Ard Biesheuvel
@ 2024-05-06  9:03 ` Andi Shyti
  2 siblings, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2024-05-06  9:03 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Ard Biesheuvel, Andy Shevchenko, Wolfram Sang, linux-kernel,
	kernel-janitors, linux-i2c

Hi Christophe,

On Sat, Jan 06, 2024 at 01:48:24PM +0100, Christophe JAILLET wrote:
> If an error occurs after the clk_prepare_enable() call, it should be undone
> by a corresponding clk_disable_unprepare() call, as already done in the
> remove() function.
> 
> As devm_clk_get() is used, we can switch to devm_clk_get_enabled() to
> handle it automatically and fix the probe.
> 
> Update the remove() function accordingly and remove the now useless
> clk_disable_unprepare() call.
> 
> Fixes: 0d676a6c4390 ("i2c: add support for Socionext SynQuacer I2C controller")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Applied to i2c/i2c-host-fixes.

Thanks,
Andi

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] i2c: synquacer: Remove a clk reference from struct synquacer_i2c
  2024-01-06 12:48 ` [PATCH 2/2] i2c: synquacer: Remove a clk reference from struct synquacer_i2c Christophe JAILLET
  2024-01-12 17:50   ` Ard Biesheuvel
@ 2024-05-06  9:04   ` Andi Shyti
  1 sibling, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2024-05-06  9:04 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Ard Biesheuvel, linux-kernel, kernel-janitors, linux-i2c

Hi Christophe,

On Sat, Jan 06, 2024 at 01:48:25PM +0100, Christophe JAILLET wrote:
> 'pclk' is only used locally in the probe. Remove it from the
> 'synquacer_i2c' structure.
> 
> Also remove a useless debug message.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Applied to i2c/i2c-host-next.

Thanks,
Andi

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-06  9:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-06 12:48 [PATCH 1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe() Christophe JAILLET
2024-01-06 12:48 ` [PATCH 2/2] i2c: synquacer: Remove a clk reference from struct synquacer_i2c Christophe JAILLET
2024-01-12 17:50   ` Ard Biesheuvel
2024-05-06  9:04   ` Andi Shyti
2024-01-12 17:50 ` [PATCH 1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe() Ard Biesheuvel
2024-05-06  9:03 ` Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).