Skip to content

Commit 50c6349

Browse files
abdurrahman-nexthopAndi Shyti
authored andcommitted
i2c: xiic: switch to devres managed APIs
Simplify the error code paths by switching to devres managed helper functions. Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Link: https://lore.kernel.org/r/20260223-i2c-xiic-v12-1-b6c9ce4e4f3c@nexthop.ai
1 parent 40890b5 commit 50c6349

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

drivers/i2c/busses/i2c-xiic.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,7 @@ MODULE_DEVICE_TABLE(of, xiic_of_match);
14231423

14241424
static int xiic_i2c_probe(struct platform_device *pdev)
14251425
{
1426+
struct device *dev = &pdev->dev;
14261427
struct xiic_i2c *i2c;
14271428
struct xiic_i2c_platform_data *pdata;
14281429
const struct of_device_id *match;
@@ -1461,7 +1462,10 @@ static int xiic_i2c_probe(struct platform_device *pdev)
14611462
snprintf(i2c->adap.name, sizeof(i2c->adap.name),
14621463
DRIVER_NAME " %s", pdev->name);
14631464

1464-
mutex_init(&i2c->lock);
1465+
ret = devm_mutex_init(dev, &i2c->lock);
1466+
if (ret)
1467+
return ret;
1468+
14651469
spin_lock_init(&i2c->atomic_lock);
14661470

14671471
i2c->clk = devm_clk_get_enabled(&pdev->dev, NULL);
@@ -1472,8 +1476,9 @@ static int xiic_i2c_probe(struct platform_device *pdev)
14721476
i2c->dev = &pdev->dev;
14731477
pm_runtime_set_autosuspend_delay(i2c->dev, XIIC_PM_TIMEOUT);
14741478
pm_runtime_use_autosuspend(i2c->dev);
1475-
pm_runtime_set_active(i2c->dev);
1476-
pm_runtime_enable(i2c->dev);
1479+
ret = devm_pm_runtime_set_active_enabled(dev);
1480+
if (ret)
1481+
return ret;
14771482

14781483
/* SCL frequency configuration */
14791484
i2c->input_clk = clk_get_rate(i2c->clk);
@@ -1489,7 +1494,7 @@ static int xiic_i2c_probe(struct platform_device *pdev)
14891494

14901495
if (ret < 0) {
14911496
dev_err_probe(&pdev->dev, ret, "Cannot claim IRQ\n");
1492-
goto err_pm_disable;
1497+
return ret;
14931498
}
14941499

14951500
i2c->singlemaster =
@@ -1508,16 +1513,14 @@ static int xiic_i2c_probe(struct platform_device *pdev)
15081513
i2c->endianness = BIG;
15091514

15101515
ret = xiic_reinit(i2c);
1511-
if (ret < 0) {
1512-
dev_err_probe(&pdev->dev, ret, "Cannot xiic_reinit\n");
1513-
goto err_pm_disable;
1514-
}
1516+
if (ret)
1517+
return dev_err_probe(dev, ret, "Cannot xiic_reinit\n");
15151518

15161519
/* add i2c adapter to i2c tree */
15171520
ret = i2c_add_adapter(&i2c->adap);
15181521
if (ret) {
15191522
xiic_deinit(i2c);
1520-
goto err_pm_disable;
1523+
return ret;
15211524
}
15221525

15231526
if (pdata) {
@@ -1530,12 +1533,6 @@ static int xiic_i2c_probe(struct platform_device *pdev)
15301533
(unsigned long)res->start, irq, i2c->i2c_clk);
15311534

15321535
return 0;
1533-
1534-
err_pm_disable:
1535-
pm_runtime_disable(&pdev->dev);
1536-
pm_runtime_set_suspended(&pdev->dev);
1537-
1538-
return ret;
15391536
}
15401537

15411538
static void xiic_i2c_remove(struct platform_device *pdev)
@@ -1555,9 +1552,6 @@ static void xiic_i2c_remove(struct platform_device *pdev)
15551552
xiic_deinit(i2c);
15561553

15571554
pm_runtime_put_sync(i2c->dev);
1558-
pm_runtime_disable(&pdev->dev);
1559-
pm_runtime_set_suspended(&pdev->dev);
1560-
pm_runtime_dont_use_autosuspend(&pdev->dev);
15611555
}
15621556

15631557
static const struct dev_pm_ops xiic_dev_pm_ops = {

0 commit comments

Comments
 (0)