Commit

d33373c565af9c8a28776af02bd20ba6e5724211

i2c: xiic: restore non-managed runtime PM to fix clk WARN flood

The devres conversion replaced manual pm_runtime_enable()/disable() with
devm_pm_runtime_set_active_enabled() and dropped the remove-time runtime
PM teardown. The managed release tears runtime PM down in the wrong
order: it calls pm_runtime_dont_use_autosuspend() before
pm_runtime_disable(), i.e. while runtime PM is still enabled, and devres
is LIFO so the devm_clk_get_enabled() release runs afterwards.

At remove(), pm_runtime_put_sync() leaves the device active with the
autosuspend timer armed. Clearing use_autosuspend then makes rpm_idle()
suspend immediately, and xiic_i2c_runtime_suspend() clk_disable()s the
clock. The later devm_clk_get_enabled() release clk_disable_unprepare()s
the already-disabled clock, so clk_core_disable() WARNs ("clkN already
disabled") on every teardown.

Drop the managed helper and restore the non-managed runtime PM setup and
teardown, so runtime PM is enabled once in probe and disabled once in
remove and the clock enable count stays balanced.

Order the remove teardown so runtime PM is disabled before the usage
count is dropped: pm_runtime_disable() followed by pm_runtime_put_noidle()
instead of pm_runtime_put_sync(). Dropping the count first with autosuspend
still enabled arms the autosuspend timer, and a preemption before
pm_runtime_disable() lets it expire, suspend the device and clk_disable()
the clock, which the devm release then disables again - the same WARN.

Restore the non-managed IRQ request as well. The probe error paths now
unwind runtime PM by hand via goto, and a devm-registered handler is only
freed later during devres unwind, so it would stay live across the manual
teardown (and across any future failing step added after it). Request the
IRQ with request_threaded_irq() and free it explicitly in the probe error
path and in remove. The probe error path also clears use_autosuspend, to
match the teardown in remove().

Fixes: 50c63491ff26 ("i2c: xiic: switch to devres managed APIs")
Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
Cc: <stable@vger.kernel.org> # v7.1+
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://patch.msgid.link/20261014-i2c-xiic-restore-runtime-pm-teardown-v8-1-40668c270069@nexthop.ai

Abdurrahman Hussain <abdurrahman@nexthop.ai> · 2026-10-14 23:56 UTC · committed by Andi Shyti

Browse files
1 file changed, +40 −9
modified drivers/i2c/busses/i2c-xiic.c
@@ -67,6 +67,7 @@ enum i2c_scl_freq {
67 67 * @rx_pos: Position within current RX message
68 68 * @endianness: big/little-endian byte order
69 69 * @clk: Pointer to AXI4-lite input clock
70 + * @irq: Interrupt number
70 71 * @state: See STATE_
71 72 * @singlemaster: Indicates bus is single master
72 73 * @dynamic: Mode of controller
@@ -95,6 +96,7 @@ struct xiic_i2c {
95 96 int rx_pos;
96 97 enum xiic_endian endianness;
97 98 struct clk *clk;
99 + int irq;
98 100 enum xilinx_i2c_state state;
99 101 bool singlemaster;
100 102 bool dynamic;
@@ -1506,9 +1508,17 @@ static int xiic_i2c_probe(struct platform_device *pdev)
1506 1508
1507 1509 pm_runtime_set_autosuspend_delay(dev, XIIC_PM_TIMEOUT);
1508 1510 pm_runtime_use_autosuspend(dev);
1509 - ret = devm_pm_runtime_set_active_enabled(dev);
1510 - if (ret)
1511 + /*
1512 + * Enable runtime PM by hand: devm_pm_runtime_set_active_enabled()
1513 + * tears down in an order that races the devm-enabled clock release and
1514 + * makes clk_core_disable() WARN (see xiic_i2c_remove()).
1515 + */
1516 + ret = pm_runtime_set_active(dev);
1517 + if (ret) {
1518 + pm_runtime_dont_use_autosuspend(dev);
1511 1519 return ret;
1520 + }
1521 + pm_runtime_enable(dev);
1512 1522
1513 1523 /* SCL frequency configuration */
1514 1524 i2c->input_clk = clk_get_rate(i2c->clk);
@@ -1517,10 +1527,15 @@ static int xiic_i2c_probe(struct platform_device *pdev)
1517 1527 if (ret || i2c->i2c_clk > I2C_MAX_FAST_MODE_PLUS_FREQ)
1518 1528 i2c->i2c_clk = 0;
1519 1529
1520 - ret = devm_request_threaded_irq(dev, irq, NULL, xiic_process,
1521 - IRQF_ONESHOT, pdev->name, i2c);
1530 + /*
1531 + * Request the IRQ non-managed: later probe steps unwind manually via
1532 + * goto, so a devm handler could still be live after that teardown runs.
1533 + */
1534 + i2c->irq = irq;
1535 + ret = request_threaded_irq(irq, NULL, xiic_process, IRQF_ONESHOT,
1536 + pdev->name, i2c);
1522 1537 if (ret)
1523 - return ret;
1538 + goto err_pm_disable;
1524 1539
1525 1540 i2c->singlemaster = device_property_read_bool(dev, "single-master");
1526 1541
@@ -1537,14 +1552,16 @@ static int xiic_i2c_probe(struct platform_device *pdev)
1537 1552 i2c->endianness = BIG;
1538 1553
1539 1554 ret = xiic_reinit(i2c);
1540 - if (ret)
1541 - return dev_err_probe(dev, ret, "Cannot xiic_reinit\n");
1555 + if (ret) {
1556 + dev_err_probe(dev, ret, "Cannot xiic_reinit\n");
1557 + goto err_free_irq;
1558 + }
1542 1559
1543 1560 /* add i2c adapter to i2c tree */
1544 1561 ret = i2c_add_numbered_adapter(&i2c->adap);
1545 1562 if (ret) {
1546 1563 xiic_deinit(i2c);
1547 - return ret;
1564 + goto err_free_irq;
1548 1565 }
1549 1566
1550 1567 if (pdata) {
@@ -1557,6 +1574,15 @@ static int xiic_i2c_probe(struct platform_device *pdev)
1557 1574 res, irq, i2c->i2c_clk);
1558 1575
1559 1576 return 0;
1577 +
1578 + err_free_irq:
1579 + free_irq(irq, i2c);
1580 + err_pm_disable:
1581 + pm_runtime_disable(dev);
1582 + pm_runtime_set_suspended(dev);
1583 + pm_runtime_dont_use_autosuspend(dev);
1584 +
1585 + return ret;
1560 1586 }
1561 1587
1562 1588 static void xiic_i2c_remove(struct platform_device *pdev)
@@ -1568,6 +1594,8 @@ static void xiic_i2c_remove(struct platform_device *pdev)
1568 1594 /* remove adapter & data */
1569 1595 i2c_del_adapter(&i2c->adap);
1570 1596
1597 + free_irq(i2c->irq, i2c);
1598 +
1571 1599 ret = pm_runtime_get_sync(dev);
1572 1600 if (ret < 0)
1573 1601 dev_warn(dev, "Failed to activate device for removal (%pe)\n",
@@ -1575,7 +1603,10 @@ static void xiic_i2c_remove(struct platform_device *pdev)
1575 1603 else
1576 1604 xiic_deinit(i2c);
1577 1605
1578 - pm_runtime_put_sync(dev);
1606 + pm_runtime_disable(dev);
1607 + pm_runtime_put_noidle(dev);
1608 + pm_runtime_set_suspended(dev);
1609 + pm_runtime_dont_use_autosuspend(dev);
1579 1610 }
1580 1611
1581 1612 static const struct dev_pm_ops xiic_dev_pm_ops = {