[PATCH v5 3/6] i2c: xiic: switch to devres managed APIs

Abdurrahman Hussain via B4 Relay posted 6 patches 2 weeks ago
There is a newer version of this series
[PATCH v5 3/6] i2c: xiic: switch to devres managed APIs
Posted by Abdurrahman Hussain via B4 Relay 2 weeks ago
From: Abdurrahman Hussain <abdurrahman@nexthop.ai>

Simplify the error code paths by switching to devres managed helper
functions.

Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
---
 drivers/i2c/busses/i2c-xiic.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 16202fb89271..a4a8087c1407 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -1462,7 +1462,10 @@ static int xiic_i2c_probe(struct platform_device *pdev)
 	snprintf(i2c->adap.name, sizeof(i2c->adap.name),
 		 DRIVER_NAME " %s", pdev->name);
 
-	mutex_init(&i2c->lock);
+	ret = devm_mutex_init(dev, &i2c->lock);
+	if (ret < 0)
+		return ret;
+
 	spin_lock_init(&i2c->atomic_lock);
 
 	i2c->clk = devm_clk_get_optional_enabled(dev, NULL);
@@ -1473,8 +1476,9 @@ static int xiic_i2c_probe(struct platform_device *pdev)
 	i2c->dev = &pdev->dev;
 	pm_runtime_set_autosuspend_delay(i2c->dev, XIIC_PM_TIMEOUT);
 	pm_runtime_use_autosuspend(i2c->dev);
-	pm_runtime_set_active(i2c->dev);
-	pm_runtime_enable(i2c->dev);
+	ret = devm_pm_runtime_set_active_enabled(dev);
+	if (ret < 0)
+		return ret;
 
 	/* SCL frequency configuration */
 	i2c->input_clk = clk_get_rate(i2c->clk);
@@ -1490,7 +1494,7 @@ static int xiic_i2c_probe(struct platform_device *pdev)
 
 	if (ret < 0) {
 		dev_err_probe(&pdev->dev, ret, "Cannot claim IRQ\n");
-		goto err_pm_disable;
+		return ret;
 	}
 
 	i2c->singlemaster =
@@ -1511,14 +1515,14 @@ static int xiic_i2c_probe(struct platform_device *pdev)
 	ret = xiic_reinit(i2c);
 	if (ret < 0) {
 		dev_err_probe(&pdev->dev, ret, "Cannot xiic_reinit\n");
-		goto err_pm_disable;
+		return ret;
 	}
 
 	/* add i2c adapter to i2c tree */
 	ret = i2c_add_adapter(&i2c->adap);
 	if (ret) {
 		xiic_deinit(i2c);
-		goto err_pm_disable;
+		return ret;
 	}
 
 	if (pdata) {
@@ -1530,12 +1534,6 @@ static int xiic_i2c_probe(struct platform_device *pdev)
 	dev_dbg(&pdev->dev, "mmio %08lx irq %d scl clock frequency %d\n",
 		(unsigned long)res->start, irq, i2c->i2c_clk);
 
-	return 0;
-
-err_pm_disable:
-	pm_runtime_disable(&pdev->dev);
-	pm_runtime_set_suspended(&pdev->dev);
-
 	return ret;
 }
 
@@ -1556,8 +1554,6 @@ static void xiic_i2c_remove(struct platform_device *pdev)
 		xiic_deinit(i2c);
 
 	pm_runtime_put_sync(i2c->dev);
-	pm_runtime_disable(&pdev->dev);
-	pm_runtime_set_suspended(&pdev->dev);
 	pm_runtime_dont_use_autosuspend(&pdev->dev);
 }
 

-- 
2.52.0
Re: [PATCH v5 3/6] i2c: xiic: switch to devres managed APIs
Posted by Andy Shevchenko 1 week, 6 days ago
On Mon, Jan 26, 2026 at 05:08:18PM +0000, Abdurrahman Hussain via B4 Relay wrote:

> Simplify the error code paths by switching to devres managed helper
> functions.

Thanks for the update, my comments below.

...

> +	ret = devm_mutex_init(dev, &i2c->lock);
> +	if (ret < 0)

Why ' < 0'?

> +		return ret;

...

> +	ret = devm_pm_runtime_set_active_enabled(dev);
> +	if (ret < 0)

Ditto.

> +		return ret;

...

>  	if (ret < 0) {
>  		dev_err_probe(&pdev->dev, ret, "Cannot claim IRQ\n");
> -		goto err_pm_disable;
> +		return ret;

		return dev_err_probe(...);

>  	}

...

>  	ret = xiic_reinit(i2c);
>  	if (ret < 0) {
>  		dev_err_probe(&pdev->dev, ret, "Cannot xiic_reinit\n");

Ditto.

> -		goto err_pm_disable;
> +		return ret;
>  	}

...

>  	dev_dbg(&pdev->dev, "mmio %08lx irq %d scl clock frequency %d\n",
>  		(unsigned long)res->start, irq, i2c->i2c_clk);

Side note, consider using %pR instead of ugly casting for resources.
(separate change).

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v5 3/6] i2c: xiic: switch to devres managed APIs
Posted by Andy Shevchenko 1 week, 6 days ago
On Tue, Jan 27, 2026 at 11:35:38AM +0200, Andy Shevchenko wrote:
> On Mon, Jan 26, 2026 at 05:08:18PM +0000, Abdurrahman Hussain via B4 Relay wrote:

...

> >  	if (ret < 0) {
> >  		dev_err_probe(&pdev->dev, ret, "Cannot claim IRQ\n");
> > -		goto err_pm_disable;
> > +		return ret;
> 
> 		return dev_err_probe(...);

Actually you are right as here we remove the message in the next patch,
so discard my previous comment.

> >  	}

...

> >  	ret = xiic_reinit(i2c);
> >  	if (ret < 0) {
> >  		dev_err_probe(&pdev->dev, ret, "Cannot xiic_reinit\n");
> 
> Ditto.
> 
> > -		goto err_pm_disable;
> > +		return ret;

But here it will stay, so

		return dev_err_probe(dev, ret, "Cannot xiic_reinit\n");

> >  	}

-- 
With Best Regards,
Andy Shevchenko