mfd: qcom-pm8xxx: Fix potential deadlock on &chip->pm_irq_lock
authorChengfeng Ye <dg573847474@gmail.com>
Thu, 20 Jul 2023 07:13:30 +0000 (07:13 +0000)
committerLee Jones <lee@kernel.org>
Fri, 18 Aug 2023 20:48:03 +0000 (21:48 +0100)
commitf1a63db65e456263fa10d8a52aed652f392f22ce
treef7bc240617320e27057cebd61492c2df68ec672e
parent506fbc6b37805c95617777ff7aa05476bbf9313d
mfd: qcom-pm8xxx: Fix potential deadlock on &chip->pm_irq_lock

As &chip->pm_irq_lock is acquired by pm8xxx_irq_handler() under irq
context, other process context code should disable irq before acquiring
the lock.

Since .irq_set_type and .irq_get_irqchip_state callbacks are generally
executed from process context without irq disabled by default, the same
lock acquision should disable irq.

Possible deadlock scenario
pm8xxx_irq_set_type()
    -> pm8xxx_config_irq()
    -> spin_lock(&chip->pm_irq_lock)
        <irq interrupt>
        -> pm8xxx_irq_handler()
        -> pm8xxx_irq_master_handler()
        -> pm8xxx_irq_block_handler()
        -> pm8xxx_read_block_irq()
        -> spin_lock(&chip->pm_irq_lock) (deadlock here)

This flaw was found using an experimental static analysis tool we are
developing for irq-related deadlock.

Fix the potential deadlock by spin_lock_irqsave().

Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
Reviewed-by: Bjorn Andersson <quic_bjorande@quicinc.com>
Link: https://lore.kernel.org/r/20230720071330.50382-1-dg573847474@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/mfd/qcom-pm8xxx.c