[PATCH v3 2/5] i2c: xiic: switch to managed version of mutex_init

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

Simplify the error path by switching to a managed version of mutex_init.

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

diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 603a246a1445..79643c27e75d 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -1461,7 +1461,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(&pdev->dev, &i2c->lock);
+	if (ret < 0)
+		return ret;
+
 	spin_lock_init(&i2c->atomic_lock);
 
 	i2c->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);

-- 
2.52.0
Re: [PATCH v3 2/5] i2c: xiic: switch to managed version of mutex_init
Posted by Andrew Lunn 2 weeks, 2 days ago
On Fri, Jan 23, 2026 at 08:02:45AM +0000, Abdurrahman Hussain via B4 Relay wrote:
> From: Abdurrahman Hussain <abdurrahman@nexthop.ai>
> 
> Simplify the error path by switching to a managed version of mutex_init.

How does this simplify the error path? You don't remove anything from
the error path.

    Andrew
Re: [PATCH v3 2/5] i2c: xiic: switch to managed version of mutex_init
Posted by Abdurrahman Hussain 2 weeks, 2 days ago
On Fri Jan 23, 2026 at 7:22 PM UTC, Andrew Lunn wrote:
> On Fri, Jan 23, 2026 at 08:02:45AM +0000, Abdurrahman Hussain via B4 Relay wrote:
>> From: Abdurrahman Hussain <abdurrahman@nexthop.ai>
>>
>> Simplify the error path by switching to a managed version of mutex_init.
>
> How does this simplify the error path? You don't remove anything from
> the error path.
>
>     Andrew


Thank you for the feedback. In v4, as suggested by Andy, I introduced managed
versions of the pm_runtime_ functions which do simplify the error handling.
I apologize for submitting v4 prematurely before allowing sufficient time for
review of v3.
Re: [PATCH v3 2/5] i2c: xiic: switch to managed version of mutex_init
Posted by Andrew Lunn 2 weeks, 2 days ago
On Fri, Jan 23, 2026 at 12:20:54PM -0800, Abdurrahman Hussain wrote:
> On Fri Jan 23, 2026 at 7:22 PM UTC, Andrew Lunn wrote:
> > On Fri, Jan 23, 2026 at 08:02:45AM +0000, Abdurrahman Hussain via B4 Relay wrote:
> >> From: Abdurrahman Hussain <abdurrahman@nexthop.ai>
> >>
> >> Simplify the error path by switching to a managed version of mutex_init.
> >
> > How does this simplify the error path? You don't remove anything from
> > the error path.
> >
> >     Andrew
> 
> 
> Thank you for the feedback. In v4, as suggested by Andy, I introduced managed
> versions of the pm_runtime_ functions which do simplify the error handling.

But this patch is not about pm_runtime_, it is about a mutex. How does
this patch make the error path simpler? Please make sure your commit
messages are accurate.

     Andrew
Re: [PATCH v3 2/5] i2c: xiic: switch to managed version of mutex_init
Posted by Abdurrahman Hussain 2 weeks, 2 days ago
On Fri Jan 23, 2026 at 9:36 PM UTC, Andrew Lunn wrote:
> On Fri, Jan 23, 2026 at 12:20:54PM -0800, Abdurrahman Hussain wrote:
>> On Fri Jan 23, 2026 at 7:22 PM UTC, Andrew Lunn wrote:
>> > On Fri, Jan 23, 2026 at 08:02:45AM +0000, Abdurrahman Hussain via B4 Relay wrote:
>> >> From: Abdurrahman Hussain <abdurrahman@nexthop.ai>
>> >>
>> >> Simplify the error path by switching to a managed version of mutex_init.
>> >
>> > How does this simplify the error path? You don't remove anything from
>> > the error path.
>> >
>> >     Andrew
>>
>>
>> Thank you for the feedback. In v4, as suggested by Andy, I introduced managed
>> versions of the pm_runtime_ functions which do simplify the error handling.
>
> But this patch is not about pm_runtime_, it is about a mutex. How does
> this patch make the error path simpler? Please make sure your commit
> messages are accurate.
>

You are right. In the case of mutex there was no error path. I should have
worded it differently. In v4 pm_runtime changes were added to the same
patch, so the wording might actually be correct now.
Re: [PATCH v3 2/5] i2c: xiic: switch to managed version of mutex_init
Posted by Andy Shevchenko 2 weeks, 3 days ago
On Fri, Jan 23, 2026 at 08:02:45AM +0000, Abdurrahman Hussain via B4 Relay wrote:

> Simplify the error path by switching to a managed version of mutex_init.

...

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

Should use 'dev' instead (see comment on the patches 1 and 5).

-- 
With Best Regards,
Andy Shevchenko