Commit 99c05e42 authored by Ramona Bolboaca's avatar Ramona Bolboaca Committed by Jonathan Cameron

iio: adis: add '__adis_enable_irq()' implementation

Add '__adis_enable_irq()' implementation which is the unlocked
version of 'adis_enable_irq()'.
Call '__adis_enable_irq()' instead of 'adis_enable_irq()' from
'__adis_intial_startup()' to keep the expected unlocked functionality.

This fix is needed to remove a deadlock for all devices which are
using 'adis_initial_startup()'. The deadlock occurs because the
same mutex is acquired twice, without releasing it.
The mutex is acquired once inside 'adis_initial_startup()', before
calling '__adis_initial_startup()', and once inside
'adis_enable_irq()', which is called by '__adis_initial_startup()'.
The deadlock is removed by calling '__adis_enable_irq()', instead of
'adis_enable_irq()' from within '__adis_initial_startup()'.

Fixes: b600bd7e ("iio: adis: do not disabe IRQs in 'adis_init()'")
Signed-off-by: default avatarRamona Bolboaca <ramona.bolboaca@analog.com>
Reviewed-by: default avatarNuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20221122082757.449452-2-ramona.bolboaca@analog.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 99b43a15
...@@ -270,23 +270,19 @@ EXPORT_SYMBOL_NS(adis_debugfs_reg_access, IIO_ADISLIB); ...@@ -270,23 +270,19 @@ EXPORT_SYMBOL_NS(adis_debugfs_reg_access, IIO_ADISLIB);
#endif #endif
/** /**
* adis_enable_irq() - Enable or disable data ready IRQ * __adis_enable_irq() - Enable or disable data ready IRQ (unlocked)
* @adis: The adis device * @adis: The adis device
* @enable: Whether to enable the IRQ * @enable: Whether to enable the IRQ
* *
* Returns 0 on success, negative error code otherwise * Returns 0 on success, negative error code otherwise
*/ */
int adis_enable_irq(struct adis *adis, bool enable) int __adis_enable_irq(struct adis *adis, bool enable)
{ {
int ret = 0; int ret;
u16 msc; u16 msc;
mutex_lock(&adis->state_lock); if (adis->data->enable_irq)
return adis->data->enable_irq(adis, enable);
if (adis->data->enable_irq) {
ret = adis->data->enable_irq(adis, enable);
goto out_unlock;
}
if (adis->data->unmasked_drdy) { if (adis->data->unmasked_drdy) {
if (enable) if (enable)
...@@ -294,12 +290,12 @@ int adis_enable_irq(struct adis *adis, bool enable) ...@@ -294,12 +290,12 @@ int adis_enable_irq(struct adis *adis, bool enable)
else else
disable_irq(adis->spi->irq); disable_irq(adis->spi->irq);
goto out_unlock; return 0;
} }
ret = __adis_read_reg_16(adis, adis->data->msc_ctrl_reg, &msc); ret = __adis_read_reg_16(adis, adis->data->msc_ctrl_reg, &msc);
if (ret) if (ret)
goto out_unlock; return ret;
msc |= ADIS_MSC_CTRL_DATA_RDY_POL_HIGH; msc |= ADIS_MSC_CTRL_DATA_RDY_POL_HIGH;
msc &= ~ADIS_MSC_CTRL_DATA_RDY_DIO2; msc &= ~ADIS_MSC_CTRL_DATA_RDY_DIO2;
...@@ -308,13 +304,9 @@ int adis_enable_irq(struct adis *adis, bool enable) ...@@ -308,13 +304,9 @@ int adis_enable_irq(struct adis *adis, bool enable)
else else
msc &= ~ADIS_MSC_CTRL_DATA_RDY_EN; msc &= ~ADIS_MSC_CTRL_DATA_RDY_EN;
ret = __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc); return __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc);
out_unlock:
mutex_unlock(&adis->state_lock);
return ret;
} }
EXPORT_SYMBOL_NS(adis_enable_irq, IIO_ADISLIB); EXPORT_SYMBOL_NS(__adis_enable_irq, IIO_ADISLIB);
/** /**
* __adis_check_status() - Check the device for error conditions (unlocked) * __adis_check_status() - Check the device for error conditions (unlocked)
...@@ -445,7 +437,7 @@ int __adis_initial_startup(struct adis *adis) ...@@ -445,7 +437,7 @@ int __adis_initial_startup(struct adis *adis)
* with 'IRQF_NO_AUTOEN' anyways. * with 'IRQF_NO_AUTOEN' anyways.
*/ */
if (!adis->data->unmasked_drdy) if (!adis->data->unmasked_drdy)
adis_enable_irq(adis, false); __adis_enable_irq(adis, false);
if (!adis->data->prod_id_reg) if (!adis->data->prod_id_reg)
return 0; return 0;
......
...@@ -402,9 +402,20 @@ static inline int adis_update_bits_base(struct adis *adis, unsigned int reg, ...@@ -402,9 +402,20 @@ static inline int adis_update_bits_base(struct adis *adis, unsigned int reg,
__adis_update_bits_base(adis, reg, mask, val, sizeof(val)); \ __adis_update_bits_base(adis, reg, mask, val, sizeof(val)); \
}) })
int adis_enable_irq(struct adis *adis, bool enable);
int __adis_check_status(struct adis *adis); int __adis_check_status(struct adis *adis);
int __adis_initial_startup(struct adis *adis); int __adis_initial_startup(struct adis *adis);
int __adis_enable_irq(struct adis *adis, bool enable);
static inline int adis_enable_irq(struct adis *adis, bool enable)
{
int ret;
mutex_lock(&adis->state_lock);
ret = __adis_enable_irq(adis, enable);
mutex_unlock(&adis->state_lock);
return ret;
}
static inline int adis_check_status(struct adis *adis) static inline int adis_check_status(struct adis *adis)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment