Skip to contentSkip to conversation

i2c: designware-platdrv: simplify reset control and fix cleanup on probe failure

PATCH In review Artem Shimko 4 participants 11 messages Jan 30 – Feb 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v6 cover i2c: designware-platdrv: simplify reset control and fix cleanup on probe failure

This series simplifies error handling and reset control management in the DesignWare I2C platform driver.

Patch 1 replaces the manual reset control acquisition and deassertion with the devm_reset_control_get_optional_exclusive_deasserted() function. This simplifies the code by eliminating explicit deassertion calls and associated error handling while maintaining the same functionality through automatic resource management.

Patch 2 removes the unnecessary goto label for cleanup on probe failure. The cleanup operations are straightforward and can be handled directly in the error path, making the control flow more readable without changing the error handling semantics.

Thank you!
--
Regards,
Artem

ChangeLog:
v1:
* https://lore.kernel.org/all/[email protected]/
v2:
* https://lore.kernel.org/all/[email protected]/
v3:
* https://lore.kernel.org/all/[email protected]/T/#u
v4:
* https://lore.kernel.org/all/[email protected]/
v5:
*
* [0/2] https://lore.kernel.org/all/[email protected]/T/#u
* [1/2] https://lore.kernel.org/all/[email protected]/T/#u
* [2/2] https://lore.kernel.org/all/[email protected]/T/#u
v6:
* All reset related changes have been carried over to Patch 1

Artem Shimko (2):
i2c: designware-platdrv: simplify reset control
i2c: designware-platdrv: fix cleanup on probe failure

 drivers/i2c/busses/i2c-designware-platdrv.c | 41 +++++++--------------
 1 file changed, 13 insertions(+), 28 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v6 1/2 i2c: designware-platdrv: simplify reset control

The current implementation uses separate calls to acquire and deassert reset control, requiring manual error handling for the deassertion operation. This can be simplified using the dedicated devm function that combines both operations.

Replace devm_reset_control_get_optional_exclusive() with devm_reset_control_get_optional_exclusive_deasserted(), which handles both reset acquisition and deassertion in a single call as well as reset_control_put() which is called automatically on driver detach. This eliminates the need for explicit deassertion and its associated error checking while maintaining the same functional behavior through automatic resource management.

---
 drivers/i2c/busses/i2c-designware-platdrv.c | 30 +++++++--------------
 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/i2c/busses/i2c-designware-platdrv.c +9 -21
index 7be99656a67d..88e70970c72c 100644
@@ -227,40 +227,32 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	dev->rst = devm_reset_control_get_optional_exclusive(device, NULL);
+	dev->rst = devm_reset_control_get_optional_exclusive_deasserted(device, NULL);
 	if (IS_ERR(dev->rst))
 		return dev_err_probe(device, PTR_ERR(dev->rst), "failed to acquire reset\n");
 
-	reset_control_deassert(dev->rst);
-
 	ret = i2c_dw_fw_parse_and_configure(dev);
 	if (ret)
-		goto exit_reset;
+		return ret;
 
 	ret = i2c_dw_probe_lock_support(dev);
-	if (ret) {
-		dev_err_probe(device, ret, "failed to probe lock support\n");
-		goto exit_reset;
-	}
+	if (ret)
+		return dev_err_probe(device, ret, "failed to probe lock support\n");
 
 	i2c_dw_configure(dev);
 
 	/* Optional interface clock */
 	dev->pclk = devm_clk_get_optional(device, "pclk");
-	if (IS_ERR(dev->pclk)) {
-		ret = dev_err_probe(device, PTR_ERR(dev->pclk), "failed to acquire pclk\n");
-		goto exit_reset;
-	}
+	if (IS_ERR(dev->pclk))
+		return dev_err_probe(device, PTR_ERR(dev->pclk), "failed to acquire pclk\n");
 
 	dev->clk = devm_clk_get_optional(device, NULL);
-	if (IS_ERR(dev->clk)) {
-		ret = dev_err_probe(device, PTR_ERR(dev->clk), "failed to acquire clock\n");
-		goto exit_reset;
-	}
+	if (IS_ERR(dev->clk))
+		return dev_err_probe(device, PTR_ERR(dev->clk), "failed to acquire clock\n");
 
 	ret = i2c_dw_prepare_clk(dev, true);
 	if (ret)
-		goto exit_reset;
+		return ret;
 
 	if (dev->clk) {
 		struct i2c_timings *t = &dev->timings;
@@ -308,8 +300,6 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
 exit_probe:
 	dw_i2c_plat_pm_cleanup(dev);
 	i2c_dw_prepare_clk(dev, false);
-exit_reset:
-	reset_control_assert(dev->rst);
 	return ret;
 }
 
@@ -329,8 +319,6 @@ static void dw_i2c_plat_remove(struct platform_device *pdev)
 	dw_i2c_plat_pm_cleanup(dev);
 
 	i2c_dw_prepare_clk(dev, false);
-
-	reset_control_assert(dev->rst);
 }
 
 static const struct of_device_id dw_i2c_of_match[] = {
Signature · 1 line
2.43.0
maintainer Acked-by on v6 1/2
#2 lore raw

Re: [PATCH v6 1/2] i2c: designware-platdrv: simplify reset control

Quoted 13 lines · Artem Shimko

The current implementation uses separate calls to acquire and deassert reset control, requiring manual error handling for the deassertion operation. This can be simplified using the dedicated devm function that combines both operations.

Replace devm_reset_control_get_optional_exclusive() with devm_reset_control_get_optional_exclusive_deasserted(), which handles both reset acquisition and deassertion in a single call as well as reset_control_put() which is called automatically on driver detach. This eliminates the need for explicit deassertion and its associated error checking while maintaining the same functional behavior through automatic resource management.

Quoted 1 line

This is nice cleanup!

maintainer
#3 lore raw

Re: [PATCH v6 1/2] i2c: designware-platdrv: simplify reset control

In reply to Artem Shimko

Hi Artem,

Quoted 35 lines · Artem Shimko

The current implementation uses separate calls to acquire and deassert reset control, requiring manual error handling for the deassertion operation. This can be simplified using the dedicated devm function that combines both operations.

Replace devm_reset_control_get_optional_exclusive() with devm_reset_control_get_optional_exclusive_deasserted(), which handles both reset acquisition and deassertion in a single call as well as reset_control_put() which is called automatically on driver detach. This eliminates the need for explicit deassertion and its associated error checking while maintaining the same functional behavior through automatic resource management.

---
 drivers/i2c/busses/i2c-designware-platdrv.c | 30 +++++++--------------
 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/i2c/busses/i2c-designware-platdrv.c +1 -3
index 7be99656a67d..88e70970c72c 100644
@@ -227,40 +227,32 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	dev->rst = devm_reset_control_get_optional_exclusive(device, NULL);
+	dev->rst = devm_reset_control_get_optional_exclusive_deasserted(device, NULL);
 	if (IS_ERR(dev->rst))
 		return dev_err_probe(device, PTR_ERR(dev->rst), "failed to acquire reset\n");
 
-	reset_control_deassert(dev->rst);
-
 	ret = i2c_dw_fw_parse_and_configure(dev);
 	if (ret)

drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct platform_device *pdev) · line 240

Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c +3 -5
-		goto exit_reset;
+		return ret;
 
 	ret = i2c_dw_probe_lock_support(dev);
-	if (ret) {
-		dev_err_probe(device, ret, "failed to probe lock support\n");
-		goto exit_reset;
-	}
+	if (ret)
+		return dev_err_probe(device, ret, "failed to probe lock support\n");

the dev_err_probe() changes are not mentioned in the commit log. Can you please split this patch in two, one for the devm_reset_control and one for the dev_err_probe?

Thanks,
Andi

#4 lore raw

Re: [PATCH v6 1/2] i2c: designware-platdrv: simplify reset control

Quoted 13 lines · Andi Shyti
Quoted 12 lines · Artem Shimko

The current implementation uses separate calls to acquire and deassert reset control, requiring manual error handling for the deassertion operation. This can be simplified using the dedicated devm function that combines both operations.

Replace devm_reset_control_get_optional_exclusive() with devm_reset_control_get_optional_exclusive_deasserted(), which handles both reset acquisition and deassertion in a single call as well as reset_control_put() which is called automatically on driver detach. This eliminates the need for explicit deassertion and its associated error checking while maintaining the same functional behavior through automatic resource management.

...

Quoted 10 lines

drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct platform_device *pdev) · line 240

Quoted 6 lines
drivers/i2c/busses/i2c-designware-platdrv.c +2 -4
-	if (ret) {
-		dev_err_probe(device, ret, "failed to probe lock support\n");
-		goto exit_reset;
-	}
+	if (ret)
+		return dev_err_probe(device, ret, "failed to probe lock support\n");

the dev_err_probe() changes are not mentioned in the commit log. Can you please split this patch in two, one for the devm_reset_control and one for the dev_err_probe?

I believe they can go together.

But can be split as well, first we replace goto by return ret followed by the joining the dev_err_probe(). In any case the commit message might be improved, yes.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH v6 1/2] i2c: designware-platdrv: simplify reset control

Hi Andy,

Quoted 2 lines · Andy Shevchenko

In any case the commit message might be
improved, yes.

Got it.

Thanks for the review!

Regards,
Artem

#6 lore raw

Re: [PATCH v6 1/2] i2c: designware-platdrv: simplify reset control

In reply to Andi Shyti

Hi Andi,

Thank you for your review!

Quoted 3 lines · Andi Shyti

the dev_err_probe() changes are not mentioned in the commit log. Can you please split this patch in two, one for the devm_reset_control and one for the dev_err_probe?

May I suggest to keep the commit as it is? From my point of view this dev_err_probe() relates to changes of the reset. Otherwise, I'll have to return the reset_control_assert() to the first commit, that's unnecessary when we use the devm_reset_control_get_optional_exclusive_deasserted().

It'll look like:
1. devm_reset_control_get_optional_exclusive() + reset_control_deassert() to devm_reset_control_get_optional_exclusive_deasserted() keeping at the same time unnecessary reset_control_assert()
2. removing reset_control_assert()
3. cleanup of exit_probe

My suggestion:
1. change devm_reset_control_get_optional_exclusive() + reset_control_deassert() to devm_reset_control_get_optional_exclusive_deasserted() as well as remove unneeded reset_control_assert()
2. cleanup of exit_probe

Regards,
Artem

maintainer
#7 lore raw

Re: [PATCH v6 1/2] i2c: designware-platdrv: simplify reset control

Quoted 9 lines · Artem Shimko

Hi Andi,

Thank you for your review!

Quoted 3 lines · Andi Shyti

the dev_err_probe() changes are not mentioned in the commit log. Can you please split this patch in two, one for the devm_reset_control and one for the dev_err_probe?

Quoted 5 lines

May I suggest to keep the commit as it is? From my point of view this dev_err_probe() relates to changes of the reset. Otherwise, I'll have to return the reset_control_assert() to the first commit, that's unnecessary when we use the devm_reset_control_get_optional_exclusive_deasserted().

I'm sorry, it looked to me in a second look like there was one dev_err_probe() replacement independent from the patch. The patch is fine and I'm going to apply it in i2c/i2c-host-2 (it will be sent as a pull request next week).

Thanks,
Andi

#8 lore raw

Re: [PATCH v6 1/2] i2c: designware-platdrv: simplify reset control

Quoted 3 lines · Andi Shyti

The patch
is fine and I'm going to apply it in i2c/i2c-host-2 (it will be sent as a pull request next week).

Great, thank you!

--
Regards,
Artem

#9 lore raw

PATCH v6 2/2 i2c: designware-platdrv: fix cleanup on probe failure

In reply to Artem Shimko

Simplify the error handling in dw_i2c_plat_probe() by consolidating cleanup operations directly in the error path instead of using a goto label.

This eliminates the goto statement, makes the error handling more transparent, and reduces code indirection while maintaining identical cleanup behavior on probe failure.

---
 drivers/i2c/busses/i2c-designware-platdrv.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-designware-platdrv.c +4 -7
index 88e70970c72c..74246fcd5138 100644
@@ -292,14 +292,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
 	pm_runtime_enable(device);
 
 	ret = i2c_dw_probe(dev);
-	if (ret)
-		goto exit_probe;
-
-	return ret;
+	if (ret) {
+		dw_i2c_plat_pm_cleanup(dev);
+		i2c_dw_prepare_clk(dev, false);
+	}
 
-exit_probe:
-	dw_i2c_plat_pm_cleanup(dev);
-	i2c_dw_prepare_clk(dev, false);
 	return ret;
 }
 
Signature · 1 line
2.43.0
maintainer Acked-by on v6 2/2
#10 lore raw

Re: [PATCH v6 2/2] i2c: designware-platdrv: fix cleanup on probe failure

Quoted 9 lines · Artem Shimko

Simplify the error handling in dw_i2c_plat_probe() by consolidating cleanup operations directly in the error path instead of using a goto label.

This eliminates the goto statement, makes the error handling more transparent, and reduces code indirection while maintaining identical cleanup behavior on probe failure.