[PATCH v2 3/3] i2c: designware-platdrv: streamline error handling

From: Artem Shimko

Date: Tue Nov 11 2025 - 06:57:46 EST


The probe function uses unnecessary goto statements and error variable
reassignments that complicate the code flow. The goto exit_probe pattern
adds indirection for simple error cleanup, while redundant error assignment
in lock support probe clutters the error handling.

Simplify the error paths by removing the goto exit_probe label and handling
PM runtime cleanup directly after i2c_dw_probe() failure. Additionally,
replace the error variable reassignment in i2c_dw_probe_lock_support() with
direct dev_err_probe() return. These changes make the error handling more
linear and readable while maintaining identical functionality.

Signed-off-by: Artem Shimko <a.shimko.dev@xxxxxxxxx>
---
drivers/i2c/busses/i2c-designware-platdrv.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index d334af1d7c6f..ab15a924dad5 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -256,10 +256,8 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
return ret;

ret = i2c_dw_probe_lock_support(dev);
- if (ret) {
- ret = dev_err_probe(device, ret, "failed to probe lock support\n");
- return ret;
- }
+ if (ret)
+ return dev_err_probe(device, ret, "failed to probe lock support\n");

i2c_dw_configure(dev);

@@ -314,14 +312,10 @@ 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;
-
-exit_probe:
- dw_i2c_plat_pm_cleanup(dev);
- i2c_dw_prepare_clk(dev, false);
+ if (ret) {
+ dw_i2c_plat_pm_cleanup(dev);
+ i2c_dw_prepare_clk(dev, false);
+ }

return ret;
}
--
2.43.0