2022-11-22 08:43:18

by Ramona Bolboaca

[permalink] [raw]
Subject: [PATCH v6 0/9] Add '__adis_enable_irq()'

Added implementation for '__adis_enable_irq()' and called it instead of
'adis_enable_irq()' inside '__adis_initial_startup()'.
Replaced 'adis_initial_startup()' calls in probe, with its unlocked
variant.

changes in v3:
new patches: 1,2
changed commit message for patches 2-9

changes in v4:
squashed patches 1 & 2 from v3

changes in v5:
fix compilation error

changes in v6:
changed commit message of patch 1: added more information related to the fix

Ramona Bolboaca (9):
iio: adis: add '__adis_enable_irq()' implementation
iio: accel: adis16201: Call '__adis_initial_startup()' in probe
iio: accel: adis16209: Call '__adis_initial_startup()' in probe
iio: gyro: adis16136: Call '__adis_initial_startup()' in probe
iio: gyro: adis16260: Call '__adis_initial_startup()' in probe
iio: imu: adis16400: Call '__adis_initial_startup()' in probe
staging: iio: accel: adis16203: Call '__adis_initial_startup()'
staging: iio: accel: adis16240: Call '__adis_initial_startup()'
iio: imu: adis: Remove adis_initial_startup function

drivers/iio/accel/adis16201.c | 2 +-
drivers/iio/accel/adis16209.c | 2 +-
drivers/iio/gyro/adis16136.c | 2 +-
drivers/iio/gyro/adis16260.c | 2 +-
drivers/iio/imu/adis.c | 28 ++++++++++-----------------
drivers/iio/imu/adis16400.c | 2 +-
drivers/staging/iio/accel/adis16203.c | 2 +-
drivers/staging/iio/accel/adis16240.c | 2 +-
include/linux/iio/imu/adis.h | 17 ++++++++--------
9 files changed, 25 insertions(+), 34 deletions(-)

--
2.25.1


2022-11-22 08:55:15

by Ramona Bolboaca

[permalink] [raw]
Subject: [PATCH v6 2/9] iio: accel: adis16201: Call '__adis_initial_startup()' in probe

Call '__adis_initial_startup()' instead of its locked variant in
'adis16201_probe()'.
The locks are not needed at this point.

Signed-off-by: Ramona Bolboaca <[email protected]>
Reviewed-by: Nuno Sá <[email protected]>
---
drivers/iio/accel/adis16201.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/accel/adis16201.c b/drivers/iio/accel/adis16201.c
index dfb8e2e5bdf5..d054721859b3 100644
--- a/drivers/iio/accel/adis16201.c
+++ b/drivers/iio/accel/adis16201.c
@@ -281,7 +281,7 @@ static int adis16201_probe(struct spi_device *spi)
if (ret)
return ret;

- ret = adis_initial_startup(st);
+ ret = __adis_initial_startup(st);
if (ret)
return ret;

--
2.25.1

2022-11-22 08:55:53

by Ramona Bolboaca

[permalink] [raw]
Subject: [PATCH v6 3/9] iio: accel: adis16209: Call '__adis_initial_startup()' in probe

Call '__adis_initial_startup()' instead of its locked variant in
'adis16209_probe()'.
The locks are not needed at this point.

Signed-off-by: Ramona Bolboaca <[email protected]>
Reviewed-by: Nuno Sá <[email protected]>
---
drivers/iio/accel/adis16209.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/accel/adis16209.c b/drivers/iio/accel/adis16209.c
index 5a9c6e2296f1..0035e4f4db63 100644
--- a/drivers/iio/accel/adis16209.c
+++ b/drivers/iio/accel/adis16209.c
@@ -291,7 +291,7 @@ static int adis16209_probe(struct spi_device *spi)
if (ret)
return ret;

- ret = adis_initial_startup(st);
+ ret = __adis_initial_startup(st);
if (ret)
return ret;

--
2.25.1

2022-11-22 09:18:20

by Ramona Bolboaca

[permalink] [raw]
Subject: [PATCH v6 9/9] iio: imu: adis: Remove adis_initial_startup function

Remove adis_initial_startup function since it is not used
anymore.

Signed-off-by: Ramona Bolboaca <[email protected]>
Reviewed-by: Nuno Sá <[email protected]>
---
include/linux/iio/imu/adis.h | 12 ------------
1 file changed, 12 deletions(-)

diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
index d789ecf8d0c8..0ace8738552b 100644
--- a/include/linux/iio/imu/adis.h
+++ b/include/linux/iio/imu/adis.h
@@ -428,18 +428,6 @@ static inline int adis_check_status(struct adis *adis)
return ret;
}

-/* locked version of __adis_initial_startup() */
-static inline int adis_initial_startup(struct adis *adis)
-{
- int ret;
-
- mutex_lock(&adis->state_lock);
- ret = __adis_initial_startup(adis);
- mutex_unlock(&adis->state_lock);
-
- return ret;
-}
-
static inline void adis_dev_lock(struct adis *adis)
{
mutex_lock(&adis->state_lock);
--
2.25.1

2022-11-22 10:12:57

by Ramona Bolboaca

[permalink] [raw]
Subject: [PATCH v6 4/9] iio: gyro: adis16136: Call '__adis_initial_startup()' in probe

Call '__adis_initial_startup()' instead of its locked variant in
'adis16136_probe()'.
The locks are not needed at this point.

Signed-off-by: Ramona Bolboaca <[email protected]>
Reviewed-by: Nuno Sá <[email protected]>
---
drivers/iio/gyro/adis16136.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/gyro/adis16136.c b/drivers/iio/gyro/adis16136.c
index 71295709f2b9..c95cf41be34b 100644
--- a/drivers/iio/gyro/adis16136.c
+++ b/drivers/iio/gyro/adis16136.c
@@ -429,7 +429,7 @@ static int adis16136_initial_setup(struct iio_dev *indio_dev)
uint16_t prod_id;
int ret;

- ret = adis_initial_startup(&adis16136->adis);
+ ret = __adis_initial_startup(&adis16136->adis);
if (ret)
return ret;

--
2.25.1

2022-11-22 10:13:15

by Ramona Bolboaca

[permalink] [raw]
Subject: [PATCH v6 6/9] iio: imu: adis16400: Call '__adis_initial_startup()' in probe

Call '__adis_initial_startup()' instead of its locked variant in
'adis16400_probe()'.
The locks are not needed at this point.

Signed-off-by: Ramona Bolboaca <[email protected]>
Reviewed-by: Nuno Sá <[email protected]>
---
drivers/iio/imu/adis16400.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/imu/adis16400.c b/drivers/iio/imu/adis16400.c
index 17bb0c40a149..c02fc35dceb4 100644
--- a/drivers/iio/imu/adis16400.c
+++ b/drivers/iio/imu/adis16400.c
@@ -445,7 +445,7 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev)
st->adis.spi->mode = SPI_MODE_3;
spi_setup(st->adis.spi);

- ret = adis_initial_startup(&st->adis);
+ ret = __adis_initial_startup(&st->adis);
if (ret)
return ret;

--
2.25.1

2022-11-22 10:13:17

by Ramona Bolboaca

[permalink] [raw]
Subject: [PATCH v6 8/9] staging: iio: accel: adis16240: Call '__adis_initial_startup()'

Call '__adis_initial_startup()' instead of its locked variant in
'adis16240_probe()'.
The locks are not needed at this point.

Signed-off-by: Ramona Bolboaca <[email protected]>
Reviewed-by: Nuno Sá <[email protected]>
---
drivers/staging/iio/accel/adis16240.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c
index bca857eef92e..337492785f04 100644
--- a/drivers/staging/iio/accel/adis16240.c
+++ b/drivers/staging/iio/accel/adis16240.c
@@ -414,7 +414,7 @@ static int adis16240_probe(struct spi_device *spi)
return ret;

/* Get the device into a sane initial state */
- ret = adis_initial_startup(st);
+ ret = __adis_initial_startup(st);
if (ret)
return ret;

--
2.25.1

2022-11-22 10:13:48

by Ramona Bolboaca

[permalink] [raw]
Subject: [PATCH v6 7/9] staging: iio: accel: adis16203: Call '__adis_initial_startup()'

Call '__adis_initial_startup()' instead of its locked variant in
'adis16203_probe()'.
The locks are not needed at this point.

Signed-off-by: Ramona Bolboaca <[email protected]>
Reviewed-by: Nuno Sá <[email protected]>
---
drivers/staging/iio/accel/adis16203.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/accel/adis16203.c b/drivers/staging/iio/accel/adis16203.c
index 62d5397ff1f9..c0e4c9266b5f 100644
--- a/drivers/staging/iio/accel/adis16203.c
+++ b/drivers/staging/iio/accel/adis16203.c
@@ -285,7 +285,7 @@ static int adis16203_probe(struct spi_device *spi)
return ret;

/* Get the device into a sane initial state */
- ret = adis_initial_startup(st);
+ ret = __adis_initial_startup(st);
if (ret)
return ret;

--
2.25.1

2022-11-22 10:15:31

by Ramona Bolboaca

[permalink] [raw]
Subject: [PATCH v6 1/9] 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: b600bd7eb3335 ("iio: adis: do not disabe IRQs in 'adis_init()'")
Signed-off-by: Ramona Bolboaca <[email protected]>
Reviewed-by: Nuno Sá <[email protected]>
---
drivers/iio/imu/adis.c | 28 ++++++++++------------------
include/linux/iio/imu/adis.h | 13 ++++++++++++-
2 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c
index f7fcfd04f659..bc40240b29e2 100644
--- a/drivers/iio/imu/adis.c
+++ b/drivers/iio/imu/adis.c
@@ -270,23 +270,19 @@ EXPORT_SYMBOL_NS(adis_debugfs_reg_access, IIO_ADISLIB);
#endif

/**
- * adis_enable_irq() - Enable or disable data ready IRQ
+ * __adis_enable_irq() - Enable or disable data ready IRQ (unlocked)
* @adis: The adis device
* @enable: Whether to enable the IRQ
*
* 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;

- mutex_lock(&adis->state_lock);
-
- if (adis->data->enable_irq) {
- ret = adis->data->enable_irq(adis, enable);
- goto out_unlock;
- }
+ if (adis->data->enable_irq)
+ return adis->data->enable_irq(adis, enable);

if (adis->data->unmasked_drdy) {
if (enable)
@@ -294,12 +290,12 @@ int adis_enable_irq(struct adis *adis, bool enable)
else
disable_irq(adis->spi->irq);

- goto out_unlock;
+ return 0;
}

ret = __adis_read_reg_16(adis, adis->data->msc_ctrl_reg, &msc);
if (ret)
- goto out_unlock;
+ return ret;

msc |= ADIS_MSC_CTRL_DATA_RDY_POL_HIGH;
msc &= ~ADIS_MSC_CTRL_DATA_RDY_DIO2;
@@ -308,13 +304,9 @@ int adis_enable_irq(struct adis *adis, bool enable)
else
msc &= ~ADIS_MSC_CTRL_DATA_RDY_EN;

- ret = __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc);
-
-out_unlock:
- mutex_unlock(&adis->state_lock);
- return ret;
+ return __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc);
}
-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)
@@ -445,7 +437,7 @@ int __adis_initial_startup(struct adis *adis)
* with 'IRQF_NO_AUTOEN' anyways.
*/
if (!adis->data->unmasked_drdy)
- adis_enable_irq(adis, false);
+ __adis_enable_irq(adis, false);

if (!adis->data->prod_id_reg)
return 0;
diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
index 515ca09764fe..d789ecf8d0c8 100644
--- a/include/linux/iio/imu/adis.h
+++ b/include/linux/iio/imu/adis.h
@@ -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)); \
})

-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;
+}
+
int __adis_check_status(struct adis *adis);
int __adis_initial_startup(struct adis *adis);
+int __adis_enable_irq(struct adis *adis, bool enable);

static inline int adis_check_status(struct adis *adis)
{
--
2.25.1

2022-11-23 20:36:51

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v6 0/9] Add '__adis_enable_irq()'

On Tue, 22 Nov 2022 10:27:48 +0200
Ramona Bolboaca <[email protected]> wrote:

> Added implementation for '__adis_enable_irq()' and called it instead of
> 'adis_enable_irq()' inside '__adis_initial_startup()'.
> Replaced 'adis_initial_startup()' calls in probe, with its unlocked
> variant.

Given how near we are to the merge window I've queued this up on the
togreg branch and marked the first patch for stable.

Thanks,

Jonathan

>
> changes in v3:
> new patches: 1,2
> changed commit message for patches 2-9
>
> changes in v4:
> squashed patches 1 & 2 from v3
>
> changes in v5:
> fix compilation error
>
> changes in v6:
> changed commit message of patch 1: added more information related to the fix
>
> Ramona Bolboaca (9):
> iio: adis: add '__adis_enable_irq()' implementation
> iio: accel: adis16201: Call '__adis_initial_startup()' in probe
> iio: accel: adis16209: Call '__adis_initial_startup()' in probe
> iio: gyro: adis16136: Call '__adis_initial_startup()' in probe
> iio: gyro: adis16260: Call '__adis_initial_startup()' in probe
> iio: imu: adis16400: Call '__adis_initial_startup()' in probe
> staging: iio: accel: adis16203: Call '__adis_initial_startup()'
> staging: iio: accel: adis16240: Call '__adis_initial_startup()'
> iio: imu: adis: Remove adis_initial_startup function
>
> drivers/iio/accel/adis16201.c | 2 +-
> drivers/iio/accel/adis16209.c | 2 +-
> drivers/iio/gyro/adis16136.c | 2 +-
> drivers/iio/gyro/adis16260.c | 2 +-
> drivers/iio/imu/adis.c | 28 ++++++++++-----------------
> drivers/iio/imu/adis16400.c | 2 +-
> drivers/staging/iio/accel/adis16203.c | 2 +-
> drivers/staging/iio/accel/adis16240.c | 2 +-
> include/linux/iio/imu/adis.h | 17 ++++++++--------
> 9 files changed, 25 insertions(+), 34 deletions(-)
>

2022-11-23 21:28:08

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v6 1/9] iio: adis: add '__adis_enable_irq()' implementation

On Tue, 22 Nov 2022 10:27:49 +0200
Ramona Bolboaca <[email protected]> wrote:

> 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: b600bd7eb3335 ("iio: adis: do not disabe IRQs in 'adis_init()'")
> Signed-off-by: Ramona Bolboaca <[email protected]>
> Reviewed-by: Nuno Sá <[email protected]>
Build issue in here that I've fixed up.

> ---
> drivers/iio/imu/adis.c | 28 ++++++++++------------------
> include/linux/iio/imu/adis.h | 13 ++++++++++++-
> 2 files changed, 22 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c
> index f7fcfd04f659..bc40240b29e2 100644
> --- a/drivers/iio/imu/adis.c
> +++ b/drivers/iio/imu/adis.c
> @@ -270,23 +270,19 @@ EXPORT_SYMBOL_NS(adis_debugfs_reg_access, IIO_ADISLIB);
> #endif
>
> /**
> - * adis_enable_irq() - Enable or disable data ready IRQ
> + * __adis_enable_irq() - Enable or disable data ready IRQ (unlocked)
> * @adis: The adis device
> * @enable: Whether to enable the IRQ
> *
> * 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;
>
> - mutex_lock(&adis->state_lock);
> -
> - if (adis->data->enable_irq) {
> - ret = adis->data->enable_irq(adis, enable);
> - goto out_unlock;
> - }
> + if (adis->data->enable_irq)
> + return adis->data->enable_irq(adis, enable);
>
> if (adis->data->unmasked_drdy) {
> if (enable)
> @@ -294,12 +290,12 @@ int adis_enable_irq(struct adis *adis, bool enable)
> else
> disable_irq(adis->spi->irq);
>
> - goto out_unlock;
> + return 0;
> }
>
> ret = __adis_read_reg_16(adis, adis->data->msc_ctrl_reg, &msc);
> if (ret)
> - goto out_unlock;
> + return ret;
>
> msc |= ADIS_MSC_CTRL_DATA_RDY_POL_HIGH;
> msc &= ~ADIS_MSC_CTRL_DATA_RDY_DIO2;
> @@ -308,13 +304,9 @@ int adis_enable_irq(struct adis *adis, bool enable)
> else
> msc &= ~ADIS_MSC_CTRL_DATA_RDY_EN;
>
> - ret = __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc);
> -
> -out_unlock:
> - mutex_unlock(&adis->state_lock);
> - return ret;
> + return __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc);
> }
> -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)
> @@ -445,7 +437,7 @@ int __adis_initial_startup(struct adis *adis)
> * with 'IRQF_NO_AUTOEN' anyways.
> */
> if (!adis->data->unmasked_drdy)
> - adis_enable_irq(adis, false);
> + __adis_enable_irq(adis, false);
>
> if (!adis->data->prod_id_reg)
> return 0;
> diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
> index 515ca09764fe..d789ecf8d0c8 100644
> --- a/include/linux/iio/imu/adis.h
> +++ b/include/linux/iio/imu/adis.h
> @@ -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)); \
> })
>
> -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;
> +}
> +
> int __adis_check_status(struct adis *adis);
> int __adis_initial_startup(struct adis *adis);
> +int __adis_enable_irq(struct adis *adis, bool enable);

Move the above down here seeing as __adis_enable_irq() isn't
defined until this point (and that gave a bunch of build issues).

>
> static inline int adis_check_status(struct adis *adis)
> {