Skip to contentSkip to conversation

Adis IRQ fixes and minor improvements

PATCH Applied Nuno Sa 3 participants 31 messages Apr 22, 2021 – Apr 26, 2021

Subsystems (4)

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore

Nuno Sa

author maintainer
#0 lore raw

v2 cover Adis IRQ fixes and minor improvements

The primary goal of this series was to fix the return value on some trigger handlers as spotted in [1]. While doing it, I found some minor improvements that I think are simple enough to include in this series.

As for the first 2 patches, I opted to not do any functional change so I'm keeping the 'if (!adis->buffer)' check. However, 'adis-buffer' is allocated in 'update_scan_mode' hook which means we should be sure that the buffer is allocated and the check is really not needed. I did not went into the details but is there any way for the trigger handler to be called before the 'update_scan_mode' hook? If not, I'm happy in sending a v2 where we just remove the 'if'...

Changes in v2:
* Remove the 'if' check for the allocated buffer;
* Make sure the adis 'state_lock' is unlocked on error paths;
* Fixed the commit message on the first 3 patches.
* Dropped ("iio: adis16475: re-set max spi transfer") and added 3 new
patches (last 3 in the series ) to fix a potential race with the spi core as discussed in [2].

[1]: https://marc.info/?l=linux-iio&m=161815197426882&w=2
[2]: https://marc.info/?l=linux-iio&m=161884696722142&w=2

Nuno Sa (9):
iio: adis_buffer: do not return ints in irq handlers
iio: adis16400: do not return ints in irq handlers
iio: adis16475: do not return ints in irq handlers
iio: adis_buffer: check return value on page change
iio: adis_buffer: don't push data to buffers on failure
iio: adis_buffer: update device page after changing it
iio: adis: add burst_max_speed_hz variable
iio: adis16475: do not directly change spi 'max_speed_hz'
iio: adis16400: do not directly change spi 'max_speed_hz'

 drivers/iio/imu/adis16400.c   | 18 ++----------------
 drivers/iio/imu/adis16475.c   |  9 +++------
 drivers/iio/imu/adis_buffer.c | 28 +++++++++++++++++++---------
 include/linux/iio/imu/adis.h  |  2 ++
 4 files changed, 26 insertions(+), 31 deletions(-)
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH v2 1/9 iio: adis_buffer: do not return ints in irq handlers

On an IRQ handler we should not return normal error codes as 'irqreturn_t' is expected.

Fixes ccd2b52f4ac69 ("staging:iio: Add common ADIS library")
---
 drivers/iio/imu/adis_buffer.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/iio/imu/adis_buffer.c +0 -3
index ac354321f63a..175af154e443 100644
@@ -129,9 +129,6 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
 	struct adis *adis = iio_device_get_drvdata(indio_dev);
 	int ret;
 
-	if (!adis->buffer)
-		return -ENOMEM;
-
 	if (adis->data->has_paging) {
 		mutex_lock(&adis->state_lock);
 		if (adis->current_page != 0) {
Signature · 1 line
2.31.1
maintainer
#2 lore raw

Re: [PATCH v2 1/9] iio: adis_buffer: do not return ints in irq handlers

Quoted 6 lines · On Thu, 22 Apr 2021 12:19:03 +0200 Nuno Sa <[email protected]> wrote:

On an IRQ handler we should not return normal error codes as 'irqreturn_t' is expected.

Fixes ccd2b52f4ac69 ("staging:iio: Add common ADIS library")

This is an interesting one in the sense it's fixing a bug that can't actually happen (hence why you can just drop the check ;) As such I've applied it to the togreg branch of iio.git and added a note that it doesn't need to go into stable.

Thanks,

Jonathan

Quoted 18 lines
---
 drivers/iio/imu/adis_buffer.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/iio/imu/adis_buffer.c +0 -3
index ac354321f63a..175af154e443 100644
@@ -129,9 +129,6 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
 	struct adis *adis = iio_device_get_drvdata(indio_dev);
 	int ret;
 
-	if (!adis->buffer)
-		return -ENOMEM;
-
 	if (adis->data->has_paging) {
 		mutex_lock(&adis->state_lock);
 		if (adis->current_page != 0) {
author maintainer
#3 lore raw

PATCH v2 2/9 iio: adis16400: do not return ints in irq handlers

In reply to Nuno Sa

On an IRQ handler we should not return normal error codes as 'irqreturn_t' is expected.

Fixes 5eda3550a3cc1 ("staging:iio:adis16400: Preallocate transfer message")
---
 drivers/iio/imu/adis16400.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/iio/imu/adis16400.c +0 -3
index 768aa493a1a6..b2f92b55b910 100644
@@ -645,9 +645,6 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
 	void *buffer;
 	int ret;
 
-	if (!adis->buffer)
-		return -ENOMEM;
-
 	if (!(st->variant->flags & ADIS16400_NO_BURST) &&
 		st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) {
 		st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST;
Signature · 1 line
2.31.1
maintainer
#4 lore raw

Re: [PATCH v2 2/9] iio: adis16400: do not return ints in irq handlers

Quoted 6 lines · On Thu, 22 Apr 2021 12:19:04 +0200 Nuno Sa <[email protected]> wrote:

On an IRQ handler we should not return normal error codes as 'irqreturn_t' is expected.

Fixes 5eda3550a3cc1 ("staging:iio:adis16400: Preallocate transfer message")

Same approach as for previous patch.

Applied to the togreg branch of iio.git and pushed out as testing.

Thanks,

Jonathan

Quoted 18 lines
---
 drivers/iio/imu/adis16400.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/iio/imu/adis16400.c +0 -3
index 768aa493a1a6..b2f92b55b910 100644
@@ -645,9 +645,6 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
 	void *buffer;
 	int ret;
 
-	if (!adis->buffer)
-		return -ENOMEM;
-
 	if (!(st->variant->flags & ADIS16400_NO_BURST) &&
 		st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) {
 		st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST;
author maintainer
#5 lore raw

PATCH v2 3/9 iio: adis16475: do not return ints in irq handlers

In reply to Nuno Sa

On an IRQ handler we should return normal error codes as 'irqreturn_t' is expected.

Fixes fff7352bf7a3c ("iio: imu: Add support for adis16475")
---
 drivers/iio/imu/adis16475.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/imu/adis16475.c +1 -1
index 1de62fc79e0f..51b76444db0b 100644
@@ -1068,7 +1068,7 @@ static irqreturn_t adis16475_trigger_handler(int irq, void *p)
 
 	ret = spi_sync(adis->spi, &adis->msg);
 	if (ret)
-		return ret;
+		goto check_burst32;
 
 	adis->spi->max_speed_hz = cached_spi_speed_hz;
 	buffer = adis->buffer;
Signature · 1 line
2.31.1
Reviewed-by on v2 3/9
#6 lore raw

Re: [PATCH v2 3/9] iio: adis16475: do not return ints in irq handlers

Quoted 4 lines · Nuno Sa

On an IRQ handler we should return normal error codes as 'irqreturn_t' is expected.

Quoted 22 lines
Fixes fff7352bf7a3c ("iio: imu: Add support for adis16475")
---
 drivers/iio/imu/adis16475.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/imu/adis16475.c +1 -2
index 1de62fc79e0f..51b76444db0b 100644
@@ -1068,7 +1068,7 @@ static irqreturn_t adis16475_trigger_handler(int irq, void *p)
 
        ret = spi_sync(adis->spi, &adis->msg);
        if (ret)
-               return ret;
+               goto check_burst32;
 
        adis->spi->max_speed_hz = cached_spi_speed_hz;
        buffer = adis->buffer;
--

2.31.1

maintainer
#7 lore raw

Re: [PATCH v2 3/9] iio: adis16475: do not return ints in irq handlers

Quoted 10 lines · On Fri, 23 Apr 2021 09:41:26 +0300 Alexandru Ardelean <[email protected]>…
Quoted 4 lines · Nuno Sa

On an IRQ handler we should return normal error codes as 'irqreturn_t' is expected.

Quoted 2 lines
Fixes fff7352bf7a3c ("iio: imu: Add support for adis16475")

Hi Nuno,

This needs a more detailed commit message as it is simply changing the return code. That goto does other stuff.
Please add some more info and send a v3 with this + other patches I that build on it and hence I won't be able to apply.

Whilst this one is a real bug, I'm not that fussed about backporting it quickly so will probably be fine to take this via togreg once the commit message gives enough detail.

Thanks,

Jonathan

Quoted 20 lines
Quoted 20 lines
---
 drivers/iio/imu/adis16475.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/imu/adis16475.c +1 -2
index 1de62fc79e0f..51b76444db0b 100644
@@ -1068,7 +1068,7 @@ static irqreturn_t adis16475_trigger_handler(int irq, void *p)
 
        ret = spi_sync(adis->spi, &adis->msg);
        if (ret)
-               return ret;
+               goto check_burst32;
 
        adis->spi->max_speed_hz = cached_spi_speed_hz;
        buffer = adis->buffer;
--

2.31.1

author maintainer
#8 lore raw

RE: [PATCH v2 3/9] iio: adis16475: do not return ints in irq handlers

Quoted 30 lines

From: Jonathan Cameron <[email protected]>
Sent: Saturday, April 24, 2021 1:07 PM
To: Alexandru Ardelean <[email protected]>
Cc: Sa, Nuno <[email protected]>; linux-iio <linux- [email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: Re: [PATCH v2 3/9] iio: adis16475: do not return ints in irq handlers

[External]

Quoted 1 line · On Fri, 23 Apr 2021 09:41:26 +0300 Alexandru Ardelean <[email protected]>…

On Thu, Apr 22, 2021 at 1:17 PM Nuno Sa <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines

On an IRQ handler we should return normal error codes as

'irqreturn_t'

Quoted 7 lines
Quoted 2 lines

is expected.

Quoted 2 lines
Fixes fff7352bf7a3c ("iio: imu: Add support for adis16475")

Hi Nuno,

Quoted 8 lines

This needs a more detailed commit message as it is simply changing the return code. That goto does other stuff.
Please add some more info and send a v3 with this + other patches I that build on it and hence I won't be able to apply.

Whilst this one is a real bug, I'm not that fussed about backporting it quickly so will probably be fine to take this via togreg once the commit message gives enough detail.

Agreed...

- Nuno Sá

author maintainer
#9 lore raw

PATCH v2 4/9 iio: adis_buffer: check return value on page change

In reply to Nuno Sa

On the trigger handler, we might need to change the device page. Hence, we should check the return value from 'spi_write()' and act accordingly.

---
 drivers/iio/imu/adis_buffer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/iio/imu/adis_buffer.c +7 -1
index 175af154e443..0ae551a748eb 100644
@@ -134,7 +134,12 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
 		if (adis->current_page != 0) {
 			adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID);
 			adis->tx[1] = 0;
-			spi_write(adis->spi, adis->tx, 2);
+			ret = spi_write(adis->spi, adis->tx, 2);
+			if (ret) {
+				dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret);
+				mutex_unlock(&adis->state_lock);
+				goto irq_done;
+			}
 		}
 	}
 
@@ -151,6 +156,7 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
 	iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
 		pf->timestamp);
 
+irq_done:
 	iio_trigger_notify_done(indio_dev->trig);
 
 	return IRQ_HANDLED;
Signature · 1 line
2.31.1
Reviewed-by on v2 4/9
#10 lore raw

Re: [PATCH v2 4/9] iio: adis_buffer: check return value on page change

Quoted 4 lines · Nuno Sa

On the trigger handler, we might need to change the device page. Hence, we should check the return value from 'spi_write()' and act accordingly.

Quoted 34 lines
---
 drivers/iio/imu/adis_buffer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/iio/imu/adis_buffer.c +7 -2
index 175af154e443..0ae551a748eb 100644
@@ -134,7 +134,12 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
                if (adis->current_page != 0) {
                        adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID);
                        adis->tx[1] = 0;
-                       spi_write(adis->spi, adis->tx, 2);
+                       ret = spi_write(adis->spi, adis->tx, 2);
+                       if (ret) {
+                               dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret);
+                               mutex_unlock(&adis->state_lock);
+                               goto irq_done;
+                       }
                }
        }
 
@@ -151,6 +156,7 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
        iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
                pf->timestamp);
 
+irq_done:
        iio_trigger_notify_done(indio_dev->trig);
 
        return IRQ_HANDLED;
--

2.31.1

maintainer Applied
#11 lore raw

Re: [PATCH v2 4/9] iio: adis_buffer: check return value on page change

Quoted 7 lines · On Fri, 23 Apr 2021 10:14:48 +0300 Alexandru Ardelean <[email protected]>…
Quoted 4 lines · Nuno Sa

On the trigger handler, we might need to change the device page. Hence, we should check the return value from 'spi_write()' and act accordingly.

Applied to the togreg branch of iio.git.

Thanks,

Jonathan

Quoted 35 lines
Quoted 35 lines
---
 drivers/iio/imu/adis_buffer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/iio/imu/adis_buffer.c +7 -2
index 175af154e443..0ae551a748eb 100644
@@ -134,7 +134,12 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
                if (adis->current_page != 0) {
                        adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID);
                        adis->tx[1] = 0;
-                       spi_write(adis->spi, adis->tx, 2);
+                       ret = spi_write(adis->spi, adis->tx, 2);
+                       if (ret) {
+                               dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret);
+                               mutex_unlock(&adis->state_lock);
+                               goto irq_done;
+                       }
                }
        }
 
@@ -151,6 +156,7 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
        iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
                pf->timestamp);
 
+irq_done:
        iio_trigger_notify_done(indio_dev->trig);
 
        return IRQ_HANDLED;
--

2.31.1

author maintainer
#12 lore raw

PATCH v2 5/9 iio: adis_buffer: don't push data to buffers on failure

In reply to Nuno Sa

There's no point in pushing data to IIO buffers in case 'spi_sync()' fails.

---
 drivers/iio/imu/adis_buffer.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iio/imu/adis_buffer.c +5 -2
index 0ae551a748eb..a29d22f657ce 100644
@@ -144,9 +144,12 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
 	}
 
 	ret = spi_sync(adis->spi, &adis->msg);
-	if (ret)
+	if (ret) {
 		dev_err(&adis->spi->dev, "Failed to read data: %d", ret);
-
+		if (adis->data->has_paging)
+			mutex_unlock(&adis->state_lock);
+		goto irq_done;
+	}
 
 	if (adis->data->has_paging) {
 		adis->current_page = 0;
Signature · 1 line
2.31.1
Reviewed-by on v2 5/9
#13 lore raw

Re: [PATCH v2 5/9] iio: adis_buffer: don't push data to buffers on failure

Quoted 4 lines · Nuno Sa

There's no point in pushing data to IIO buffers in case 'spi_sync()' fails.

Overall, this feels like it's adding some duplication. However, short-term I'm not seeing a considerably better way to do this. Maybe, this would require some refactoring of the adis_trigger_handler() to handle the paging logic a bit more elegantly.
But that's a broader change.

Quoted 27 lines
---
 drivers/iio/imu/adis_buffer.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iio/imu/adis_buffer.c +5 -3
index 0ae551a748eb..a29d22f657ce 100644
@@ -144,9 +144,12 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
        }
 
        ret = spi_sync(adis->spi, &adis->msg);
-       if (ret)
+       if (ret) {
                dev_err(&adis->spi->dev, "Failed to read data: %d", ret);
-
+               if (adis->data->has_paging)
+                       mutex_unlock(&adis->state_lock);
+               goto irq_done;
+       }
 
        if (adis->data->has_paging) {
                adis->current_page = 0;
--

2.31.1

maintainer
#14 lore raw

Re: [PATCH v2 5/9] iio: adis_buffer: don't push data to buffers on failure

Quoted 6 lines · On Fri, 23 Apr 2021 10:28:08 +0300 Alexandru Ardelean <[email protected]>…
Quoted 4 lines · Nuno Sa

There's no point in pushing data to IIO buffers in case 'spi_sync()' fails.

Quoted 8 lines

Overall, this feels like it's adding some duplication. However, short-term I'm not seeing a considerably better way to do this. Maybe, this would require some refactoring of the adis_trigger_handler() to handle the paging logic a bit more elegantly.
But that's a broader change.

In here the read failed, but I think the switch to current_page = 0 succeeded (as was before this spi_sync). So should we not be setting current_page = 0 even int his error path?

With that in mind can we just move the if (ret) check past the existing unlock? + does it make sense to just move the setting of current_page = 0 up to where it's actually set?

Quoted 28 lines
Quoted 28 lines
---
 drivers/iio/imu/adis_buffer.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iio/imu/adis_buffer.c +5 -3
index 0ae551a748eb..a29d22f657ce 100644
@@ -144,9 +144,12 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
        }
 
        ret = spi_sync(adis->spi, &adis->msg);
-       if (ret)
+       if (ret) {
                dev_err(&adis->spi->dev, "Failed to read data: %d", ret);
-
+               if (adis->data->has_paging)
+                       mutex_unlock(&adis->state_lock);
+               goto irq_done;
+       }
 
        if (adis->data->has_paging) {
                adis->current_page = 0;
--

2.31.1

author maintainer
#15 lore raw

PATCH v2 6/9 iio: adis_buffer: update device page after changing it

In reply to Nuno Sa

With commit 58ca347b9b24 ("iio: adis_buffer: don't push data to buffers on failure"), we return if 'spi_sync()' fails which would leave 'adis->current_page' in an incoherent state. Hence, set this variable right after we change the device page.

---
 drivers/iio/imu/adis_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/imu/adis_buffer.c +3 -3
index a29d22f657ce..dda367071980 100644
@@ -140,6 +140,8 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
 				mutex_unlock(&adis->state_lock);
 				goto irq_done;
 			}
+
+			adis->current_page = 0;
 		}
 	}
 
@@ -151,10 +153,8 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
 		goto irq_done;
 	}
 
-	if (adis->data->has_paging) {
-		adis->current_page = 0;
+	if (adis->data->has_paging)
 		mutex_unlock(&adis->state_lock);
-	}
 
 	iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
 		pf->timestamp);
Signature · 1 line
2.31.1
#16 lore raw

Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

Quoted 25 lines · Nuno Sa

With commit 58ca347b9b24 ("iio: adis_buffer: don't push data to buffers on failure"), we return if 'spi_sync()' fails which would leave 'adis->current_page' in an incoherent state. Hence, set this variable right after we change the device page.

---
 drivers/iio/imu/adis_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/imu/adis_buffer.c +2 -0
index a29d22f657ce..dda367071980 100644
@@ -140,6 +140,8 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
                                mutex_unlock(&adis->state_lock);
                                goto irq_done;
                        }
+
+                       adis->current_page = 0;
                }
        }
 

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq, void *p) · line 157

Quoted 8 lines
drivers/iio/imu/adis_buffer.c +1 -3
@@ -151,10 +153,8 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
                goto irq_done;
        }
 
-       if (adis->data->has_paging) {
-               adis->current_page = 0;
+       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);
-       }

So, continuing from my comment here [1]:
https://patchwork.kernel.org/project/linux-iio/patch/[email protected]/

This can become more elegant, because this block:

       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);

can be moved right after "ret = spi_sync(adis->spi, &adis->msg);"

And then the duplication added in patch [1] can be cleaned up.
So maybe a re-ordering of patches could simplify/remove the added duplication.

Quoted 6 lines
drivers/iio/imu/adis_buffer.c +0 -1
        iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
                pf->timestamp);
--

2.31.1

author maintainer
#17 lore raw

RE: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

Quoted 60 lines

From: Alexandru Ardelean <[email protected]>
Sent: Friday, April 23, 2021 9:33 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

[External]

Quoted 2 lines · Nuno Sa

With commit 58ca347b9b24 ("iio: adis_buffer: don't push data to

buffers on

Review

Quoted 10 lines

failure"), we return if 'spi_sync()' fails which would leave 'adis->current_page' in an incoherent state. Hence, set this variable right after we change the device page.

---
 drivers/iio/imu/adis_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/imu/adis_buffer.c

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq,

Quoted 4 lines

index a29d22f657ce..dda367071980 100644

drivers/iio/imu/adis_buffer.c +0 -0
@@ -140,6 +140,8 @@ static irqreturn_t adis_trigger_handler(int irq,

void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int

Quoted 9 lines
drivers/iio/imu/adis_buffer.c +2 -0
                                mutex_unlock(&adis->state_lock);
                                goto irq_done;
                        }
+
+                       adis->current_page = 0;
                }
        }
 
@@ -151,10 +153,8 @@ static irqreturn_t adis_trigger_handler(int

irq, void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq, void *p) · line 157

Quoted 8 lines
drivers/iio/imu/adis_buffer.c +1 -3
                goto irq_done;
        }
 
-       if (adis->data->has_paging) {
-               adis->current_page = 0;
+       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);
-       }

So, continuing from my comment here [1]:

https://urldefense.com/v3/__https://patchwork.kernel.org/project/li
nux-iio/patch/20210422101911.135630-6- [email protected]/__;!!A3Ni8CS0y2Y!u1RyPNeh8e5m7lPfDa5H5ZjT hA9TdsLGvk2m1kFQBbAKe40PmvQS8O8N-f-GEg$

This can become more elegant, because this block:

Quoted 9 lines
       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);

can be moved right after "ret = spi_sync(adis->spi, &adis->msg);"

And then the duplication added in patch [1] can be cleaned up. So maybe a re-ordering of patches could simplify/remove the added duplication.

Hmmm I'm not following you :). What's your idea? You mean the block inside the 'if (ret)' in case spi_sync fails? If so, we can move it but then we cannot do the goto jump... you mean something like?

ret = spi_sync();
if (adis->data->has_paging)

	mutex_unlock(&adis->state_lock);
if (ret) {
	dev_err();
	goto irq_done;
}

I don't particularly like the paging stuff after the spi_sync but this avoids some duplication for sure... and reduces some lines of code :)

- Nuno Sá

#18 lore raw

Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

Quoted 77 lines · Nuno
Quoted 61 lines

From: Alexandru Ardelean <[email protected]>
Sent: Friday, April 23, 2021 9:33 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

[External]

Quoted 2 lines · Nuno Sa

With commit 58ca347b9b24 ("iio: adis_buffer: don't push data to

buffers on

Review

Quoted 10 lines

failure"), we return if 'spi_sync()' fails which would leave 'adis->current_page' in an incoherent state. Hence, set this variable right after we change the device page.

---
 drivers/iio/imu/adis_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/imu/adis_buffer.c

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq,

Quoted 4 lines

index a29d22f657ce..dda367071980 100644

drivers/iio/imu/adis_buffer.c +0 -0
@@ -140,6 +140,8 @@ static irqreturn_t adis_trigger_handler(int irq,

void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int

Quoted 9 lines
drivers/iio/imu/adis_buffer.c +2 -0
                                mutex_unlock(&adis->state_lock);
                                goto irq_done;
                        }
+
+                       adis->current_page = 0;
                }
        }
 
@@ -151,10 +153,8 @@ static irqreturn_t adis_trigger_handler(int

irq, void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq, void *p) · line 157

Quoted 8 lines
drivers/iio/imu/adis_buffer.c +1 -3
                goto irq_done;
        }
 
-       if (adis->data->has_paging) {
-               adis->current_page = 0;
+       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);
-       }

So, continuing from my comment here [1]:

https://urldefense.com/v3/__https://patchwork.kernel.org/project/li
nux-iio/patch/20210422101911.135630-6- [email protected]/__;!!A3Ni8CS0y2Y!u1RyPNeh8e5m7lPfDa5H5ZjT hA9TdsLGvk2m1kFQBbAKe40PmvQS8O8N-f-GEg$

This can become more elegant, because this block:

Quoted 9 lines
       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);

can be moved right after "ret = spi_sync(adis->spi, &adis->msg);"

And then the duplication added in patch [1] can be cleaned up. So maybe a re-ordering of patches could simplify/remove the added duplication.

Hmmm I'm not following you :). What's your idea? You mean the block inside the 'if (ret)' in case spi_sync fails? If so, we can move it but then we cannot do the goto jump... you mean something like?

ret = spi_sync();
if (adis->data->has_paging)

Quoted 8 lines
        mutex_unlock(&adis->state_lock);
if (ret) {
        dev_err();
        goto irq_done;
}

I don't particularly like the paging stuff after the spi_sync but this avoids some duplication for sure... and reduces some lines of code :)

Yeah, this was the suggestion.
No strong opinion about it.

Quoted 2 lines

- Nuno Sá

maintainer
#19 lore raw

Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

Quoted 84 lines · On Fri, 23 Apr 2021 16:56:26 +0300 Alexandru Ardelean <[email protected]>…
Quoted 83 lines · Nuno
Quoted 61 lines

From: Alexandru Ardelean <[email protected]>
Sent: Friday, April 23, 2021 9:33 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

[External]

Quoted 2 lines · Nuno Sa

With commit 58ca347b9b24 ("iio: adis_buffer: don't push data to

buffers on

Review

Quoted 10 lines

failure"), we return if 'spi_sync()' fails which would leave 'adis->current_page' in an incoherent state. Hence, set this variable right after we change the device page.

---
 drivers/iio/imu/adis_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/imu/adis_buffer.c

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq,

Quoted 4 lines

index a29d22f657ce..dda367071980 100644

drivers/iio/imu/adis_buffer.c +0 -0
@@ -140,6 +140,8 @@ static irqreturn_t adis_trigger_handler(int irq,  

void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int

Quoted 9 lines
drivers/iio/imu/adis_buffer.c +2 -0
                                mutex_unlock(&adis->state_lock);
                                goto irq_done;
                        }
+
+                       adis->current_page = 0;
                }
        }
 
@@ -151,10 +153,8 @@ static irqreturn_t adis_trigger_handler(int  

irq, void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq, void *p) · line 157

Quoted 8 lines
drivers/iio/imu/adis_buffer.c +1 -3
                goto irq_done;
        }
 
-       if (adis->data->has_paging) {
-               adis->current_page = 0;
+       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);
-       }  

So, continuing from my comment here [1]:

https://urldefense.com/v3/__https://patchwork.kernel.org/project/li
nux-iio/patch/20210422101911.135630-6- [email protected]/__;!!A3Ni8CS0y2Y!u1RyPNeh8e5m7lPfDa5H5ZjT hA9TdsLGvk2m1kFQBbAKe40PmvQS8O8N-f-GEg$

This can become more elegant, because this block:

Quoted 9 lines
       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);

can be moved right after "ret = spi_sync(adis->spi, &adis->msg);"

And then the duplication added in patch [1] can be cleaned up. So maybe a re-ordering of patches could simplify/remove the added duplication.

Hmmm I'm not following you :). What's your idea? You mean the block inside the 'if (ret)' in case spi_sync fails? If so, we can move it but then we cannot do the goto jump... you mean something like?

ret = spi_sync();
if (adis->data->has_paging)

        mutex_unlock(&adis->state_lock);
if (ret) {
        dev_err();
        goto irq_done;
}
Quoted 5 lines
Quoted 2 lines

I don't particularly like the paging stuff after the spi_sync but this avoids some duplication for sure... and reduces some lines of code :)

Yeah, this was the suggestion.
No strong opinion about it.

Ah. I should probably read ahead a bit before commenting on earlier patches ;)

I was thinking this was the way to go. It would be an entirely standard pattern if not for the if (adis->data->has_paging) being there.

Hmm maybe some helpers would make this more readable?

adis_mutex_lock_if_paging(adis);
adis_mutex_unlock_if_paging(adis);

Probably not worth it given single usecase. I'd go with what you have above. I'd also reorder this before the previous patch as that will make that one simpler.

Jonathan

Quoted 3 lines
Quoted 3 lines

- Nuno Sá

maintainer
#20 lore raw

Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

Quoted 97 lines · On Sat, 24 Apr 2021 12:18:06 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 84 lines · On Fri, 23 Apr 2021 16:56:26 +0300 Alexandru Ardelean <[email protected]>…
Quoted 83 lines · Nuno
Quoted 61 lines

From: Alexandru Ardelean <[email protected]>
Sent: Friday, April 23, 2021 9:33 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

[External]

Quoted 2 lines · Nuno Sa

With commit 58ca347b9b24 ("iio: adis_buffer: don't push data to

buffers on

Review

Quoted 10 lines

failure"), we return if 'spi_sync()' fails which would leave 'adis->current_page' in an incoherent state. Hence, set this variable right after we change the device page.

---
 drivers/iio/imu/adis_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/imu/adis_buffer.c

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq,

Quoted 4 lines

index a29d22f657ce..dda367071980 100644

drivers/iio/imu/adis_buffer.c +0 -0
@@ -140,6 +140,8 @@ static irqreturn_t adis_trigger_handler(int irq,    

void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int

Quoted 9 lines
drivers/iio/imu/adis_buffer.c +2 -0
                                mutex_unlock(&adis->state_lock);
                                goto irq_done;
                        }
+
+                       adis->current_page = 0;
                }
        }
 
@@ -151,10 +153,8 @@ static irqreturn_t adis_trigger_handler(int    

irq, void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq, void *p) · line 157

Quoted 8 lines
drivers/iio/imu/adis_buffer.c +1 -3
                goto irq_done;
        }
 
-       if (adis->data->has_paging) {
-               adis->current_page = 0;
+       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);
-       }    

So, continuing from my comment here [1]:

https://urldefense.com/v3/__https://patchwork.kernel.org/project/li
nux-iio/patch/20210422101911.135630-6- [email protected]/__;!!A3Ni8CS0y2Y!u1RyPNeh8e5m7lPfDa5H5ZjT hA9TdsLGvk2m1kFQBbAKe40PmvQS8O8N-f-GEg$

This can become more elegant, because this block:

Quoted 9 lines
       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);

can be moved right after "ret = spi_sync(adis->spi, &adis->msg);"

And then the duplication added in patch [1] can be cleaned up. So maybe a re-ordering of patches could simplify/remove the added duplication.

Hmmm I'm not following you :). What's your idea? You mean the block inside the 'if (ret)' in case spi_sync fails? If so, we can move it but then we cannot do the goto jump... you mean something like?

ret = spi_sync();
if (adis->data->has_paging)

        mutex_unlock(&adis->state_lock);
if (ret) {
        dev_err();
        goto irq_done;
}
Quoted 5 lines
Quoted 2 lines

I don't particularly like the paging stuff after the spi_sync but this avoids some duplication for sure... and reduces some lines of code :)

Yeah, this was the suggestion.
No strong opinion about it.

Ah. I should probably read ahead a bit before commenting on earlier patches ;)

I was thinking this was the way to go. It would be an entirely standard pattern if not for the if (adis->data->has_paging) being there.

Quoted 6 lines

Hmm maybe some helpers would make this more readable?

adis_mutex_lock_if_paging(adis);
adis_mutex_unlock_if_paging(adis);

Probably not worth it given single usecase. I'd go with what you have above.

Ah realised this was unclear just after hitting send. I mean the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

ret = spi_sync();
if (adis->data->has_paging)

        mutex_unlock(&adis->state_lock);
if (ret) {
        dev_err();
        goto irq_done;
}

approach.

Quoted 8 lines

I'd also reorder this before the previous patch as that will make that one simpler.

Jonathan

Quoted 3 lines
Quoted 3 lines

- Nuno Sá

maintainer
#21 lore raw

Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

Quoted 116 lines · On Sat, 24 Apr 2021 12:19:52 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 97 lines · On Sat, 24 Apr 2021 12:18:06 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 84 lines · On Fri, 23 Apr 2021 16:56:26 +0300 Alexandru Ardelean <[email protected]>…
Quoted 83 lines · Nuno
Quoted 61 lines

From: Alexandru Ardelean <[email protected]>
Sent: Friday, April 23, 2021 9:33 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

[External]

Quoted 2 lines · Nuno Sa

With commit 58ca347b9b24 ("iio: adis_buffer: don't push data to

buffers on

Review

Quoted 10 lines

failure"), we return if 'spi_sync()' fails which would leave 'adis->current_page' in an incoherent state. Hence, set this variable right after we change the device page.

---
 drivers/iio/imu/adis_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/imu/adis_buffer.c

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq,

Quoted 4 lines

index a29d22f657ce..dda367071980 100644

drivers/iio/imu/adis_buffer.c +0 -0
@@ -140,6 +140,8 @@ static irqreturn_t adis_trigger_handler(int irq,      

void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int

Quoted 9 lines
drivers/iio/imu/adis_buffer.c +2 -0
                                mutex_unlock(&adis->state_lock);
                                goto irq_done;
                        }
+
+                       adis->current_page = 0;
                }
        }
 
@@ -151,10 +153,8 @@ static irqreturn_t adis_trigger_handler(int      

irq, void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t adis_trigger_handler(int irq, void *p) · line 157

Quoted 8 lines
drivers/iio/imu/adis_buffer.c +1 -3
                goto irq_done;
        }
 
-       if (adis->data->has_paging) {
-               adis->current_page = 0;
+       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);
-       }      

So, continuing from my comment here [1]:

https://urldefense.com/v3/__https://patchwork.kernel.org/project/li
nux-iio/patch/20210422101911.135630-6- [email protected]/__;!!A3Ni8CS0y2Y!u1RyPNeh8e5m7lPfDa5H5ZjT hA9TdsLGvk2m1kFQBbAKe40PmvQS8O8N-f-GEg$

This can become more elegant, because this block:

Quoted 9 lines
       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);

can be moved right after "ret = spi_sync(adis->spi, &adis->msg);"

And then the duplication added in patch [1] can be cleaned up. So maybe a re-ordering of patches could simplify/remove the added duplication.

Hmmm I'm not following you :). What's your idea? You mean the block inside the 'if (ret)' in case spi_sync fails? If so, we can move it but then we cannot do the goto jump... you mean something like?

ret = spi_sync();
if (adis->data->has_paging)

        mutex_unlock(&adis->state_lock);
if (ret) {
        dev_err();
        goto irq_done;
}
Quoted 5 lines
Quoted 2 lines

I don't particularly like the paging stuff after the spi_sync but this avoids some duplication for sure... and reduces some lines of code :)

Yeah, this was the suggestion.
No strong opinion about it.

Ah. I should probably read ahead a bit before commenting on earlier patches ;)

I was thinking this was the way to go. It would be an entirely standard pattern if not for the if (adis->data->has_paging) being there.

Quoted 6 lines

Hmm maybe some helpers would make this more readable?

adis_mutex_lock_if_paging(adis);
adis_mutex_unlock_if_paging(adis);

Probably not worth it given single usecase. I'd go with what you have above.

Ah realised this was unclear just after hitting send. I mean the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

ret = spi_sync();
if (adis->data->has_paging)

        mutex_unlock(&adis->state_lock);
if (ret) {
        dev_err();
        goto irq_done;
}  
Quoted 1 line

approach.

As I love replying to myself ;)

From the other adis patch, I noticed that we have adis_dev_lock()

Probably good to have a follow up patch that tidies the drivers up to use that where appropriate. Good not to do it in these patches though as that would just make them locally harder to read.

Thanks,

Jonathan

Quoted 10 lines
Quoted 9 lines

I'd also reorder this before the previous patch as that will make that one simpler.

Jonathan

Quoted 3 lines
Quoted 3 lines

- Nuno Sá

author maintainer
#22 lore raw

RE: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

Quoted 154 lines

From: Jonathan Cameron <[email protected]>
Sent: Saturday, April 24, 2021 1:31 PM
To: Alexandru Ardelean <[email protected]>
Cc: Sa, Nuno <[email protected]>; linux-iio <linux- [email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

[External]

Quoted 7 lines · On Sat, 24 Apr 2021 12:19:52 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 4 lines · On Sat, 24 Apr 2021 12:18:06 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 1 line · On Fri, 23 Apr 2021 16:56:26 +0300 Alexandru Ardelean <[email protected]>…

On Fri, Apr 23, 2021 at 3:20 PM Sa, Nuno <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

From: Alexandru Ardelean <[email protected]>
Sent: Friday, April 23, 2021 9:33 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: Re: [PATCH v2 6/9] iio: adis_buffer: update device

page after

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

changing it

[External]

On Thu, Apr 22, 2021 at 1:17 PM Nuno Sa

<[email protected]>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines · wrote:

With commit 58ca347b9b24 ("iio: adis_buffer: don't push

data to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

buffers on

Quoted 2 lines

failure"), we return if 'spi_sync()' fails which would leave 'adis->current_page' in an incoherent state. Hence, set this

variable

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

right after we change the device page.

---
 drivers/iio/imu/adis_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/iio/imu/adis_buffer.c

drivers/iio/imu/adis_buffer.c static irqreturn_t

Quoted 4 lines

index a29d22f657ce..dda367071980 100644

drivers/iio/imu/adis_buffer.c +0 -0
@@ -140,6 +140,8 @@ static irqreturn_t

adis_trigger_handler(int irq,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t

Quoted 9 lines
drivers/iio/imu/adis_buffer.c +2 -0
                                mutex_unlock(&adis->state_lock);
                                goto irq_done;
                        }
+
+                       adis->current_page = 0;
                }
        }
 
@@ -151,10 +153,8 @@ static irqreturn_t

adis_trigger_handler(int

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

irq, void *p)

Quoted 8 lines
drivers/iio/imu/adis_buffer.c +1 -3
                goto irq_done;
        }
 
-       if (adis->data->has_paging) {
-               adis->current_page = 0;
+       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);
-       }
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

So, continuing from my comment here [1]:

https://urldefense.com/v3/__https://patchwork.kernel.org/project/li

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

nux-iio/patch/20210422101911.135630-6-

[email protected]/__;!!A3Ni8CS0y2Y!u1RyPNeh8e5m7lPfDa5H5ZjT

Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

hA9TdsLGvk2m1kFQBbAKe40PmvQS8O8N-f-GEg$

This can become more elegant, because this block:

       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);

can be moved right after "ret = spi_sync(adis->spi, &adis-

msg);"

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

And then the duplication added in patch [1] can be cleaned

up.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

So maybe a re-ordering of patches could simplify/remove the

added

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

duplication.

Hmmm I'm not following you :). What's your idea? You mean

the block

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

inside the 'if (ret)' in case spi_sync fails? If so, we can move it

but then

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

we cannot do the goto jump... you mean something like?

ret = spi_sync();
if (adis->data->has_paging)

        mutex_unlock(&adis->state_lock);
if (ret) {
        dev_err();
        goto irq_done;
}

I don't particularly like the paging stuff after the spi_sync but

this avoids

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

some duplication for sure... and reduces some lines of code :)

Yeah, this was the suggestion.
No strong opinion about it.

Ah. I should probably read ahead a bit before commenting on

earlier patches ;)

Quoted 2 lines
Quoted 2 lines

I was thinking this was the way to go. It would be an entirely

standard pattern

Quoted 8 lines
Quoted 8 lines

if not for the if (adis->data->has_paging) being there.

Hmm maybe some helpers would make this more readable?

adis_mutex_lock_if_paging(adis);
adis_mutex_unlock_if_paging(adis);

Probably not worth it given single usecase. I'd go with what you

have above.

Quoted 11 lines

Ah realised this was unclear just after hitting send. I mean the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

ret = spi_sync();
if (adis->data->has_paging)

        mutex_unlock(&adis->state_lock);
if (ret) {
        dev_err();
        goto irq_done;
}

approach.

As I love replying to myself ;)

Quoted 8 lines

From the other adis patch, I noticed that we have adis_dev_lock()

Probably good to have a follow up patch that tidies the drivers up to use
that where appropriate. Good not to do it in these patches though as that
would just make them locally harder to read.

Hi Jonathan,

I did thought about using the helpers here. But my goal with the helpers was to use them in drivers and keep the core as is. As we can think of adis_buffer as part of the lib core implementation, I was fine in leaving the 'raw' mutex access here.

Anyways, I do not have strong feelings about this so if you prefer to have adis.c and adis_buffer.c using the mutex helpers, I'm happy in doing so in a follow up patch (not sure if it would make sense to also apply the helpers in adis.h as we might need some reordering of the helpers)...

- Nuno Sá

author maintainer
#23 lore raw

RE: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

In reply to Jonathan Cameron
Quoted 128 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Saturday, April 24, 2021 1:18 PM
To: Alexandru Ardelean <[email protected]>
Cc: Sa, Nuno <[email protected]>; linux-iio <linux- [email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: Re: [PATCH v2 6/9] iio: adis_buffer: update device page after changing it

[External]

Quoted 1 line · On Fri, 23 Apr 2021 16:56:26 +0300 Alexandru Ardelean <[email protected]>…

On Fri, Apr 23, 2021 at 3:20 PM Sa, Nuno <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 9 lines

From: Alexandru Ardelean <[email protected]>
Sent: Friday, April 23, 2021 9:33 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Hennerich, Michael <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: Re: [PATCH v2 6/9] iio: adis_buffer: update device page

after

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

changing it

[External]

Quoted 2 lines · Nuno Sa

With commit 58ca347b9b24 ("iio: adis_buffer: don't push data

to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

buffers on

Quoted 2 lines

failure"), we return if 'spi_sync()' fails which would leave 'adis->current_page' in an incoherent state. Hence, set this

variable

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

right after we change the device page.

---
 drivers/iio/imu/adis_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/iio/imu/adis_buffer.c

drivers/iio/imu/adis_buffer.c static irqreturn_t

Quoted 4 lines

index a29d22f657ce..dda367071980 100644

drivers/iio/imu/adis_buffer.c +0 -0
@@ -140,6 +140,8 @@ static irqreturn_t

adis_trigger_handler(int irq,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

void *p)

drivers/iio/imu/adis_buffer.c static irqreturn_t

Quoted 9 lines
drivers/iio/imu/adis_buffer.c +2 -0
                                mutex_unlock(&adis->state_lock);
                                goto irq_done;
                        }
+
+                       adis->current_page = 0;
                }
        }
 
@@ -151,10 +153,8 @@ static irqreturn_t

adis_trigger_handler(int

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

irq, void *p)

Quoted 8 lines
drivers/iio/imu/adis_buffer.c +1 -3
                goto irq_done;
        }
 
-       if (adis->data->has_paging) {
-               adis->current_page = 0;
+       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);
-       }
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

So, continuing from my comment here [1]:

https://urldefense.com/v3/__https://patchwork.kernel.org/project/li

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

nux-iio/patch/20210422101911.135630-6-

[email protected]/__;!!A3Ni8CS0y2Y!u1RyPNeh8e5m7lPfDa5H5ZjT

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

hA9TdsLGvk2m1kFQBbAKe40PmvQS8O8N-f-GEg$

This can become more elegant, because this block:

       if (adis->data->has_paging)
                mutex_unlock(&adis->state_lock);

can be moved right after "ret = spi_sync(adis->spi, &adis->msg);"

And then the duplication added in patch [1] can be cleaned up. So maybe a re-ordering of patches could simplify/remove the

added

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

duplication.

Hmmm I'm not following you :). What's your idea? You mean the

block

Quoted 1 line
Quoted 1 line

inside the 'if (ret)' in case spi_sync fails? If so, we can move it but

then

Quoted 11 lines
Quoted 11 lines

we cannot do the goto jump... you mean something like?

ret = spi_sync();
if (adis->data->has_paging)

        mutex_unlock(&adis->state_lock);
if (ret) {
        dev_err();
        goto irq_done;
}

I don't particularly like the paging stuff after the spi_sync but this

avoids

Quoted 4 lines
Quoted 1 line

some duplication for sure... and reduces some lines of code :)

Yeah, this was the suggestion.
No strong opinion about it.

Ah. I should probably read ahead a bit before commenting on earlier patches ;)

I was thinking this was the way to go. It would be an entirely standard pattern
if not for the if (adis->data->has_paging) being there.

Hmm maybe some helpers would make this more readable?

Quoted 8 lines

adis_mutex_lock_if_paging(adis);
adis_mutex_unlock_if_paging(adis);

Probably not worth it given single usecase. I'd go with what you have above.
I'd also reorder this before the previous patch as that will make that one simpler.

Agreed...

- Nuno Sá

author maintainer
#24 lore raw

PATCH v2 7/9 iio: adis: add burst_max_speed_hz variable

In reply to Nuno Sa

Typically, in burst mode, the device cannot operate at it's full spi speed. Hence, the spi transfers for burst mode have to take this into account. With this change we avoid a potential race with the spi core as drivers were 'hacking' the device 'max_speed_hz' directly in the trigger handler.

---
 drivers/iio/imu/adis_buffer.c | 4 ++++
 include/linux/iio/imu/adis.h  | 2 ++
 2 files changed, 6 insertions(+)
drivers/iio/imu/adis_buffer.c +4 -0
index dda367071980..82239da2f441 100644
@@ -51,9 +51,13 @@ static int adis_update_scan_mode_burst(struct iio_dev *indio_dev,
 	adis->xfer[0].tx_buf = tx;
 	adis->xfer[0].bits_per_word = 8;
 	adis->xfer[0].len = 2;
+	if (adis->data->burst_max_speed_hz)
+		adis->xfer[0].speed_hz = adis->data->burst_max_speed_hz;
 	adis->xfer[1].rx_buf = adis->buffer;
 	adis->xfer[1].bits_per_word = 8;
 	adis->xfer[1].len = burst_length;
+	if (adis->data->burst_max_speed_hz)
+		adis->xfer[1].speed_hz = adis->data->burst_max_speed_hz;
 
 	spi_message_init(&adis->msg);
 	spi_message_add_tail(&adis->xfer[0], &adis->msg);
include/linux/iio/imu/adis.h +2 -0
index f9b728d490b1..cf49997d5903 100644
@@ -55,6 +55,7 @@ struct adis_timeout {
  *			this should be the minimum size supported by the device.
  * @burst_max_len:	Holds the maximum burst size when the device supports
  *			more than one burst mode with different sizes
+ * @burst_max_speed_hz:	Maximum spi speed that can be used in burst mode
  */
 struct adis_data {
 	unsigned int read_delay;
@@ -83,6 +84,7 @@ struct adis_data {
 	unsigned int burst_reg_cmd;
 	unsigned int burst_len;
 	unsigned int burst_max_len;
+	unsigned int burst_max_speed_hz;
 };
 
 /**
Signature · 1 line
2.31.1
Reviewed-by on v2 7/9
#25 lore raw

Re: [PATCH v2 7/9] iio: adis: add burst_max_speed_hz variable

Quoted 7 lines · Nuno Sa

Typically, in burst mode, the device cannot operate at it's full spi speed. Hence, the spi transfers for burst mode have to take this into account. With this change we avoid a potential race with the spi core as drivers were 'hacking' the device 'max_speed_hz' directly in the trigger handler.

Quoted 47 lines
---
 drivers/iio/imu/adis_buffer.c | 4 ++++
 include/linux/iio/imu/adis.h  | 2 ++
 2 files changed, 6 insertions(+)
drivers/iio/imu/adis_buffer.c +4 -0
index dda367071980..82239da2f441 100644
@@ -51,9 +51,13 @@ static int adis_update_scan_mode_burst(struct iio_dev *indio_dev,
        adis->xfer[0].tx_buf = tx;
        adis->xfer[0].bits_per_word = 8;
        adis->xfer[0].len = 2;
+       if (adis->data->burst_max_speed_hz)
+               adis->xfer[0].speed_hz = adis->data->burst_max_speed_hz;
        adis->xfer[1].rx_buf = adis->buffer;
        adis->xfer[1].bits_per_word = 8;
        adis->xfer[1].len = burst_length;
+       if (adis->data->burst_max_speed_hz)
+               adis->xfer[1].speed_hz = adis->data->burst_max_speed_hz;
 
        spi_message_init(&adis->msg);
        spi_message_add_tail(&adis->xfer[0], &adis->msg);
include/linux/iio/imu/adis.h +2 -1
index f9b728d490b1..cf49997d5903 100644
@@ -55,6 +55,7 @@ struct adis_timeout {
  *                     this should be the minimum size supported by the device.
  * @burst_max_len:     Holds the maximum burst size when the device supports
  *                     more than one burst mode with different sizes
+ * @burst_max_speed_hz:        Maximum spi speed that can be used in burst mode
  */
 struct adis_data {
        unsigned int read_delay;
@@ -83,6 +84,7 @@ struct adis_data {
        unsigned int burst_reg_cmd;
        unsigned int burst_len;
        unsigned int burst_max_len;
+       unsigned int burst_max_speed_hz;
 };
 
 /**
--

2.31.1

maintainer
#26 lore raw

Re: [PATCH v2 7/9] iio: adis: add burst_max_speed_hz variable

Quoted 10 lines · On Fri, 23 Apr 2021 10:34:24 +0300 Alexandru Ardelean <[email protected]>…
Quoted 7 lines · Nuno Sa

Typically, in burst mode, the device cannot operate at it's full spi speed. Hence, the spi transfers for burst mode have to take this into account. With this change we avoid a potential race with the spi core as drivers were 'hacking' the device 'max_speed_hz' directly in the trigger handler.

Rest of series looks good to me. Nice cleanup / fixes ;)

I'll probably take this the slow way though rather than through fixes. Race has been there a while after all with no reports so it can wait a cycle. I'll think about whether to mark them for stable when applying. On this particular occasion we may want to do an explicit stable email as the need to pick up the whole series (minus the first 2 I think) even though some parts of it are not fixes as such but precursor rework.

Thanks,

Jonathan

Quoted 49 lines
Quoted 49 lines
---
 drivers/iio/imu/adis_buffer.c | 4 ++++
 include/linux/iio/imu/adis.h  | 2 ++
 2 files changed, 6 insertions(+)
drivers/iio/imu/adis_buffer.c +4 -0
index dda367071980..82239da2f441 100644
@@ -51,9 +51,13 @@ static int adis_update_scan_mode_burst(struct iio_dev *indio_dev,
        adis->xfer[0].tx_buf = tx;
        adis->xfer[0].bits_per_word = 8;
        adis->xfer[0].len = 2;
+       if (adis->data->burst_max_speed_hz)
+               adis->xfer[0].speed_hz = adis->data->burst_max_speed_hz;
        adis->xfer[1].rx_buf = adis->buffer;
        adis->xfer[1].bits_per_word = 8;
        adis->xfer[1].len = burst_length;
+       if (adis->data->burst_max_speed_hz)
+               adis->xfer[1].speed_hz = adis->data->burst_max_speed_hz;
 
        spi_message_init(&adis->msg);
        spi_message_add_tail(&adis->xfer[0], &adis->msg);
include/linux/iio/imu/adis.h +2 -1
index f9b728d490b1..cf49997d5903 100644
@@ -55,6 +55,7 @@ struct adis_timeout {
  *                     this should be the minimum size supported by the device.
  * @burst_max_len:     Holds the maximum burst size when the device supports
  *                     more than one burst mode with different sizes
+ * @burst_max_speed_hz:        Maximum spi speed that can be used in burst mode
  */
 struct adis_data {
        unsigned int read_delay;
@@ -83,6 +84,7 @@ struct adis_data {
        unsigned int burst_reg_cmd;
        unsigned int burst_len;
        unsigned int burst_max_len;
+       unsigned int burst_max_speed_hz;
 };
 
 /**
--

2.31.1

author maintainer
#27 lore raw

PATCH v2 8/9 iio: adis16475: do not directly change spi 'max_speed_hz'

In reply to Nuno Sa

With commit 65f2f661e71d ("iio: adis: add burst_max_speed_hz variable"), we just need to define 'burst_max_speed_hz' and the adis core will take care of setting up the spi transfers for burst mode. Hence, we fix a potential race with the spi core where we could be left with an invalid 'max_speed_hz'.

Fixes fff7352bf7a3c ("iio: imu: Add support for adis16475")
---
 drivers/iio/imu/adis16475.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/imu/adis16475.c +2 -5
index 51b76444db0b..5654c0c15426 100644
@@ -645,7 +645,8 @@ static int adis16475_enable_irq(struct adis *adis, bool enable)
 	.timeouts = (_timeouts),					\
 	.burst_reg_cmd = ADIS16475_REG_GLOB_CMD,			\
 	.burst_len = ADIS16475_BURST_MAX_DATA,				\
-	.burst_max_len = ADIS16475_BURST32_MAX_DATA			\
+	.burst_max_len = ADIS16475_BURST32_MAX_DATA,			\
+	.burst_max_speed_hz = ADIS16475_BURST_MAX_SPEED			\
 }
 
 static const struct adis16475_sync adis16475_sync_mode[] = {
@@ -1062,15 +1063,11 @@ static irqreturn_t adis16475_trigger_handler(int irq, void *p)
 	bool valid;
 	/* offset until the first element after gyro and accel */
 	const u8 offset = st->burst32 ? 13 : 7;
-	const u32 cached_spi_speed_hz = adis->spi->max_speed_hz;
-
-	adis->spi->max_speed_hz = ADIS16475_BURST_MAX_SPEED;
 
 	ret = spi_sync(adis->spi, &adis->msg);
 	if (ret)
 		goto check_burst32;
 
-	adis->spi->max_speed_hz = cached_spi_speed_hz;
 	buffer = adis->buffer;
 
 	crc = be16_to_cpu(buffer[offset + 2]);
Signature · 1 line
2.31.1
Reviewed-by on v2 8/9
#28 lore raw

Re: [PATCH v2 8/9] iio: adis16475: do not directly change spi 'max_speed_hz'

Quoted 7 lines · Nuno Sa

With commit 65f2f661e71d ("iio: adis: add burst_max_speed_hz variable"), we just need to define 'burst_max_speed_hz' and the adis core will take care of setting up the spi transfers for burst mode. Hence, we fix a potential race with the spi core where we could be left with an invalid 'max_speed_hz'.

This looks more elegant.

Quoted 39 lines
Fixes fff7352bf7a3c ("iio: imu: Add support for adis16475")
---
 drivers/iio/imu/adis16475.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/imu/adis16475.c +2 -6
index 51b76444db0b..5654c0c15426 100644
@@ -645,7 +645,8 @@ static int adis16475_enable_irq(struct adis *adis, bool enable)
        .timeouts = (_timeouts),                                        \
        .burst_reg_cmd = ADIS16475_REG_GLOB_CMD,                        \
        .burst_len = ADIS16475_BURST_MAX_DATA,                          \
-       .burst_max_len = ADIS16475_BURST32_MAX_DATA                     \
+       .burst_max_len = ADIS16475_BURST32_MAX_DATA,                    \
+       .burst_max_speed_hz = ADIS16475_BURST_MAX_SPEED                 \
 }
 
 static const struct adis16475_sync adis16475_sync_mode[] = {
@@ -1062,15 +1063,11 @@ static irqreturn_t adis16475_trigger_handler(int irq, void *p)
        bool valid;
        /* offset until the first element after gyro and accel */
        const u8 offset = st->burst32 ? 13 : 7;
-       const u32 cached_spi_speed_hz = adis->spi->max_speed_hz;
-
-       adis->spi->max_speed_hz = ADIS16475_BURST_MAX_SPEED;
 
        ret = spi_sync(adis->spi, &adis->msg);
        if (ret)
                goto check_burst32;
 
-       adis->spi->max_speed_hz = cached_spi_speed_hz;
        buffer = adis->buffer;
 
        crc = be16_to_cpu(buffer[offset + 2]);
--

2.31.1

author maintainer
#29 lore raw

PATCH v2 9/9 iio: adis16400: do not directly change spi 'max_speed_hz'

In reply to Nuno Sa

With commit 65f2f661e71d ("iio: adis: add burst_max_speed_hz variable"), we just need to define 'burst_max_speed_hz' and the adis core will take care of setting up the spi transfers for burst mode. Hence, we fix a potential race with the spi core where we could be left witn an invalid 'max_speed_hz'.

Fixes 5eda3550a3cc1 ("staging:iio:adis16400: Preallocate transfer message")
---
 drivers/iio/imu/adis16400.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/iio/imu/adis16400.c +2 -13
index b2f92b55b910..cb8d3ffab6fc 100644
@@ -641,25 +641,13 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct adis16400_state *st = iio_priv(indio_dev);
 	struct adis *adis = &st->adis;
-	u32 old_speed_hz = st->adis.spi->max_speed_hz;
 	void *buffer;
 	int ret;
 
-	if (!(st->variant->flags & ADIS16400_NO_BURST) &&
-		st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) {
-		st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST;
-		spi_setup(st->adis.spi);
-	}
-
 	ret = spi_sync(adis->spi, &adis->msg);
 	if (ret)
 		dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret);
 
-	if (!(st->variant->flags & ADIS16400_NO_BURST)) {
-		st->adis.spi->max_speed_hz = old_speed_hz;
-		spi_setup(st->adis.spi);
-	}
-
 	if (st->variant->flags & ADIS16400_BURST_DIAG_STAT)
 		buffer = adis->buffer + sizeof(u16);
 	else
@@ -965,7 +953,8 @@ static const char * const adis16400_status_error_msgs[] = {
 		BIT(ADIS16400_DIAG_STAT_POWER_LOW),			\
 	.timeouts = (_timeouts),					\
 	.burst_reg_cmd = ADIS16400_GLOB_CMD,				\
-	.burst_len = (_burst_len)					\
+	.burst_len = (_burst_len),					\
+	.burst_max_speed_hz = ADIS16400_SPI_BURST			\
 }
 
 static const struct adis_timeout adis16300_timeouts = {
Signature · 1 line
2.31.1
Reviewed-by on v2 9/9
#30 lore raw

Re: [PATCH v2 9/9] iio: adis16400: do not directly change spi 'max_speed_hz'

Quoted 7 lines · Nuno Sa

With commit 65f2f661e71d ("iio: adis: add burst_max_speed_hz variable"), we just need to define 'burst_max_speed_hz' and the adis core will take care of setting up the spi transfers for burst mode. Hence, we fix a potential race with the spi core where we could be left witn an invalid 'max_speed_hz'.

This looks even more elegant than the previous.

Quoted 49 lines
Fixes 5eda3550a3cc1 ("staging:iio:adis16400: Preallocate transfer message")
---
 drivers/iio/imu/adis16400.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/iio/imu/adis16400.c +2 -14
index b2f92b55b910..cb8d3ffab6fc 100644
@@ -641,25 +641,13 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
        struct iio_dev *indio_dev = pf->indio_dev;
        struct adis16400_state *st = iio_priv(indio_dev);
        struct adis *adis = &st->adis;
-       u32 old_speed_hz = st->adis.spi->max_speed_hz;
        void *buffer;
        int ret;
 
-       if (!(st->variant->flags & ADIS16400_NO_BURST) &&
-               st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) {
-               st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST;
-               spi_setup(st->adis.spi);
-       }
-
        ret = spi_sync(adis->spi, &adis->msg);
        if (ret)
                dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret);
 
-       if (!(st->variant->flags & ADIS16400_NO_BURST)) {
-               st->adis.spi->max_speed_hz = old_speed_hz;
-               spi_setup(st->adis.spi);
-       }
-
        if (st->variant->flags & ADIS16400_BURST_DIAG_STAT)
                buffer = adis->buffer + sizeof(u16);
        else
@@ -965,7 +953,8 @@ static const char * const adis16400_status_error_msgs[] = {
                BIT(ADIS16400_DIAG_STAT_POWER_LOW),                     \
        .timeouts = (_timeouts),                                        \
        .burst_reg_cmd = ADIS16400_GLOB_CMD,                            \
-       .burst_len = (_burst_len)                                       \
+       .burst_len = (_burst_len),                                      \
+       .burst_max_speed_hz = ADIS16400_SPI_BURST                       \
 }
 
 static const struct adis_timeout adis16300_timeouts = {
--

2.31.1