iio: ssp_sensors: improve resource cleanup
v7 cover iio: ssp_sensors: improve resource cleanup
From: Sanjay Chitroda <[email protected]>
Hi all,
This patch series improves resource cleanup and error handling in the SSP IIO SPI driver by adopting the recently introduced cleanup helpers.
The changes focus on making probe/remove paths more robust and easier to reason about by reducing manual unwind logic and ensuring that locks and dynamically allocated resources are released consistently across all exit paths.
Key highlights of this series:
- Reuse embedded rx buffer for SPI transfer instead of allocating new DMA memory in interrupt context for write transaction between AP <-> HUB.
- Replace dynamic resource lifetime management with device‑managed (devm_) APIs to simplify cleanup and error paths.
- Refactor common helper API, improving readability and reducing duplicatation.
- Address minor codestyle warnings and use dev_err_probe in probe path.
Changes in v7:
- first 2 checkpatch patches are applied to iio/testing
- address coding type review comment from Andy at multiple places
- add warning fix in ssp_dev driver
- add new change to cancel refresh work
- add helper API for enable/disable MCU
- Following input from Andy add local variable dev to use with APIs
- v6 series: https://lore.kernel.org/all/[email protected]/
Changes in v6:
- 0005: Drop remove() path using devm action with input from David
- 0007: Replace dynamic memory allocation with embedded fixed size struct buffer
- 0004: new: drop duplication in remove()
- 0006: new: Use dev_err_probe in driver probe()
- v5 series: https://lore.kernel.org/all/[email protected]/
Changes in v5:
- Drop usage of guard() helpers to avoid mixing mutex_lock() with
guard()(), based on reviewer feedback.
- 0003: Refactor shared helper API, reducing duplication.
- 0004: Convert resource allocation and teardown to devm_ managed APIs to simplify error handling and probe/remove paths.
- v4 series: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Update sequence and make checkpatch style fix in base change
- Split WARNING and CHECK change with input of Andy as 0001 and 0002
- 0003: Use guard() instead of scoped_guard()
- 0004: Use preallocated buffer to stash memory allocation
- v3 series: https://lore.kernel.org/all/[email protected]/
No functional behavior changes are intended.
Testing:
- Compiled with W=1
- Build-tested on QEMU x86_64
Feedback and reviews are very welcome.
Thanks,
Sanjay Chitroda
Sanjay Chitroda (9):
iio: ssp_sensors: cleanup codestyle warning
iio: ssp_sensors: factor out pending list add/remove helper(s)
iio: ssp_sensors: cancel delayed work_refresh on remove
iio: ssp_sensors: factor out mcu enable/disable helper(s)
iio: ssp_sensors: use local struct device
iio: ssp_sensors: Drop duplicated wdt timer and work cleanup
iio: ssp_sensors: convert probe and teardown to devm-managed resources
iio: ssp_sensors: Use dev_err_probe
iio: ssp_sensors: reuse embedded RX buffer for SPI transfers
drivers/iio/common/ssp_sensors/ssp.h | 3 + drivers/iio/common/ssp_sensors/ssp_dev.c | 168 ++++++++++++----------- drivers/iio/common/ssp_sensors/ssp_spi.c | 78 +++++------ 3 files changed, 128 insertions(+), 121 deletions(-)
base-commit: eade2b843d9b1f668fc1775f15611bb0a1999cd9
Signature · 1 line
2.34.1
PATCH v7 1/9 iio: ssp_sensors: cleanup codestyle warning
From: Sanjay Chitroda <[email protected]>
Reported by checkpatch:
FILE: drivers/iio/common/ssp_sensors/ssp_dev.c
WARNING: Prefer __packed over __attribute__((__packed__)) +} __attribute__((__packed__));
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/common/ssp_sensors/ssp_dev.c +1 -1
@@ -28,7 +28,7 @@ struct ssp_instruction {__le32 a;__le32 b;u8 c; -} __attribute__((__packed__)); +}__packed__ ;static const u8 ssp_magnitude_table[] = {110 ,85 ,171 ,71 ,203 ,195 ,0 ,67 ,208 ,56 ,175 ,244 ,206 ,213 ,0 ,92 ,250 ,0 ,55 ,48 ,189 ,252 ,171 ,
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v7 1/9] iio: ssp_sensors: cleanup codestyle warning
Quoted 9 lines · On Sun, 26 Apr 2026 14:47:02 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Reported by checkpatch:
FILE:drivers/iio/common/ssp_sensors/ssp_dev.cWARNING: Prefer
__packedover __attribute__((__packed__)) +} __attribute__((__packed__));Signed-off-by Sanjay Chitroda <[email protected]>
Applied to the testing branch of iio.git.
I'm trying to pick up some of the patches on list just to reduce how many are getting sent in new revisions and the time it takes people to look at them each time.
Not sure how far I'll get in your series so look out for when I stop saying I've applied them.
thanks,
Jonathan
Quoted 17 lines
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/common/ssp_sensors/ssp_dev.c +1
-1@@ -28,7 +28,7 @@ struct ssp_instruction {__le32 a;__le32 b;u8 c; -} __attribute__((__packed__)); +}__packed__ ;static const u8 ssp_magnitude_table[] = {110 ,85 ,171 ,71 ,203 ,195 ,0 ,67 ,208 ,56 ,175 ,244 ,206 ,213 ,0 ,92 ,250 ,0 ,55 ,48 ,189 ,252 ,171 ,
Re: [PATCH v7 1/9] iio: ssp_sensors: cleanup codestyle warning
Quoted 18 lines · Jonathan Cameron
Quoted 9 lines · On Sun, 26 Apr 2026 14:47:02 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Reported by checkpatch:
FILE:drivers/iio/common/ssp_sensors/ssp_dev.cWARNING: Prefer
__packedover __attribute__((__packed__)) +} __attribute__((__packed__));Signed-off-by Sanjay Chitroda <[email protected]>Applied to the testing branch of iio.git.
I'm trying to pick up some of the patches on list just to reduce how many are getting sent in new revisions and the time it takes people to look at them each time.
Quoted 7 lines
Not sure how far I'll get in your series so look out for when I stop saying I've applied them.
thanks,
Jonathan
This was started with single change and later based on valuable input and guidance from you and Andy and during the internal review and development of driver some new change is getting appended and series is getting long even after taking few changes to iio.
Hoping to close this soon, so I can divert my focus in other open parts.
Thanks,
Sanjay Chitroda
Quoted 18 lines
Quoted 17 lines
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/common/ssp_sensors/ssp_dev.c +1
-1@@ -28,7 +28,7 @@ struct ssp_instruction {__le32 a;__le32 b;u8 c; -} __attribute__((__packed__)); +}__packed__ ;static const u8 ssp_magnitude_table[] = {110 ,85 ,171 ,71 ,203 ,195 ,0 ,67 ,208 ,56 ,175 ,244 ,206 ,213 ,0 ,92 ,250 ,0 ,55 ,48 ,189 ,252 ,171 ,
David Lechner
reviewerRe: [PATCH v7 1/9] iio: ssp_sensors: cleanup codestyle warning
In reply to Jonathan CameronQuoted 29 lines · Jonathan Cameron
Quoted 9 lines · On Sun, 26 Apr 2026 14:47:02 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Reported by checkpatch:
FILE:drivers/iio/common/ssp_sensors/ssp_dev.cWARNING: Prefer
__packedover __attribute__((__packed__)) +} __attribute__((__packed__));Signed-off-by Sanjay Chitroda <[email protected]>Applied to the testing branch of iio.git.
I'm trying to pick up some of the patches on list just to reduce how many are getting sent in new revisions and the time it takes people to look at them each time.
Not sure how far I'll get in your series so look out for when I stop saying I've applied them.
thanks,
Jonathan
Quoted 4 lines
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_dev.c struct ssp_instruction { · line 31
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +1
-1@@ -28,7 +28,7 @@ struct ssp_instruction {__le32 a;__le32 b;u8 c; -} __attribute__((__packed__)); +}__packed__ ;
Too late now, but this isn't the recommended __packed as it was in the first 6 revisions of this patch and there is no changelog to explain why it was changed.
Quoted 4 lines
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +0
-0static const u8 ssp_magnitude_table[] = {110 ,85 ,171 ,71 ,203 ,195 ,0 ,67 ,208 ,56 ,175 ,244 ,206 ,213 ,0 ,92 ,250 ,0 ,55 ,48 ,189 ,252 ,171 ,
PATCH v7 2/9 iio: ssp_sensors: factor out pending list add/remove helper(s)
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
The SSP SPI transfer path manipulates the pending message list in multiple places, each time open-coding the same locking and list operations.
Re-factor the pending list add and delete logic into small helper functions and drop use_no_irq variable to avoid duplication and simplify transfer flow to follow.
No functional change intended.
---
Changes in v7:
- Following suggestion from Andy, keep helper API definition in single
line and re-place the comment section
- v6 change: https://lore.kernel.org/all/[email protected]/
Changes in v6:
- Include tag for the suggestion of helper functions
- Drop completely use_no_irq variable with review comment from Andy
- v5 change: https://lore.kernel.org/all/[email protected]/
--- drivers/iio/common/ssp_sensors/ssp_spi.c | 58 ++++++++++++++---------- 1 file changed, 33 insertions(+), 25 deletions(-)
drivers/iio/common/ssp_sensors/ssp_spi.c +33 -25
@@ -174,15 +174,35 @@ static int ssp_check_lines(struct ssp_data *data, bool state)return 0 ; } +static inline void ssp_pending_add (struct ssp_data *data,struct ssp_msg *msg) +{ +/* +* Check if this is a short one way message or the whole transfer has +* second part after an interrupt. +*/ +if (msg->length ==0 ) +return ; + +mutex_lock (&data->pending_lock); +list_add_tail (&msg->list, &data->pending_list); +mutex_unlock (&data->pending_lock); +} + +static inline void ssp_pending_del (struct ssp_data *data,struct ssp_msg *msg) +{ +/* See ssp_pending_add() for transfer length logic */ +if (msg->length ==0 ) +return ; + +mutex_lock (&data->pending_lock); +list_del (&msg->list); +mutex_unlock (&data->pending_lock); +} +static int ssp_do_transfer (struct ssp_data *data,struct ssp_msg *msg,struct completion *done,int timeout) {int status; -/* -* check if this is a short one way message or the whole transfer has -* second part after an interrupt -*/ -const bool use_no_irq = msg->length ==0 ;if (data->shut_down)return -EPERM ;
@@ -202,35 +222,23 @@ static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, goto _error_locked; } -if (!use_no_irq) { -mutex_lock (&data->pending_lock); -list_add_tail (&msg->list, &data->pending_list); -mutex_unlock (&data->pending_lock); - } +ssp_pending_add (data, msg); status =ssp_check_lines (data, true);if (status <0 ) { -if (!use_no_irq) { -mutex_lock (&data->pending_lock); -list_del (&msg->list); -mutex_unlock (&data->pending_lock); - } +ssp_pending_del (data, msg); goto _error_locked; }mutex_unlock (&data->comm_lock); -if (!use_no_irq && done) -if (wait_for_completion_timeout (done, -msecs_to_jiffies (timeout)) == -0 ) { -mutex_lock (&data->pending_lock); -list_del (&msg->list); -mutex_unlock (&data->pending_lock); +if (msg->length && done && + !wait_for_completion_timeout (done,msecs_to_jiffies (timeout))) { +ssp_pending_del (data, msg); - data->timeout_cnt++; -return -ETIMEDOUT ; - } + data->timeout_cnt++; +return -ETIMEDOUT ; + }return 0 ;
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v7 2/9] iio: ssp_sensors: factor out pending list add/remove helper(s)
Quoted 34 lines · On Sun, 26 Apr 2026 14:47:03 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
The SSP SPI transfer path manipulates the pending message list in multiple places, each time open-coding the same locking and list operations.
Re-factor the pending list add and delete logic into small helper functions and drop
use_no_irqvariable to avoid duplication and simplify transfer flow to follow.No functional change intended.
Signed-off-by Sanjay Chitroda <[email protected]>Suggested-by Andy Shevchenko <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>---
Changes in v7:
- Following suggestion from Andy, keep helper API definition in single
line and re-place the comment section
- v6 change: https://lore.kernel.org/all/[email protected]/
Changes in v6:
- Include tag for the suggestion of helper functions
- Drop completelyuse_no_irqvariable with review comment from Andy
- v5 change: https://lore.kernel.org/all/[email protected]/--- drivers/iio/common/ssp_sensors/ssp_spi.c | 58 ++++++++++++++---------- 1 file changed, 33 insertions(+), 25 deletions(-)drivers/iio/common/ssp_sensors/ssp_spi.c +0
-0@@ -174,15 +174,35 @@ static int ssp_check_lines(struct ssp_data *data, bool state)return 0 ;
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_check_lines(struct ssp_data *data, bool state) · line 184
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +8
-0} +static inline void ssp_pending_add (struct ssp_data *data,struct ssp_msg *msg) +{ +/* +* Check if this is a short one way message or the whole transfer has +* second part after an interrupt. +*/ +if (msg->length ==0 ) +return ;
I know Andy suggested your bring these into the helpers, but to me it's obscuring flow as it looks at the caller like it was added to the pending list when it wasn't.. And we end up with multiple checks on msg_length where we had one before.
One option would be to have it return a bool to indicate whether it was added to the pending list or not.
Andy, would that work for you?
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_check_lines(struct ssp_data *data, bool state) · line 194
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +10
-0+ +mutex_lock (&data->pending_lock); +list_add_tail (&msg->list, &data->pending_list); +mutex_unlock (&data->pending_lock); +} + +static inline void ssp_pending_del (struct ssp_data *data,struct ssp_msg *msg) +{ +/* See ssp_pending_add() for transfer length logic */ +if (msg->length ==0 )
Not useful to know if this happened at caller, so no need to return bool from this.
Quoted 20 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +7
-5+return ; + +mutex_lock (&data->pending_lock); +list_del (&msg->list); +mutex_unlock (&data->pending_lock); +} +static int ssp_do_transfer (struct ssp_data *data,struct ssp_msg *msg,struct completion *done,int timeout) {int status; -/* -* check if this is a short one way message or the whole transfer has -* second part after an interrupt -*/ -const bool use_no_irq = msg->length ==0 ;if (data->shut_down)return -EPERM ;
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, · line 225
Quoted 9 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-5@@ -202,35 +222,23 @@ static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, goto _error_locked; } -if (!use_no_irq) { -mutex_lock (&data->pending_lock); -list_add_tail (&msg->list, &data->pending_list); -mutex_unlock (&data->pending_lock); - } +ssp_pending_add (data, msg);
With suggestion above this would become
use_irq = ssp_pending_add(data, msg);
Quoted 12 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-5status =ssp_check_lines (data, true);if (status <0 ) { -if (!use_no_irq) { -mutex_lock (&data->pending_lock); -list_del (&msg->list); -mutex_unlock (&data->pending_lock); - } +ssp_pending_del (data, msg); goto _error_locked; }
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, · line 235
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-7mutex_unlock (&data->comm_lock); -if (!use_no_irq && done) -if (wait_for_completion_timeout (done, -msecs_to_jiffies (timeout)) == -0 ) { -mutex_lock (&data->pending_lock); -list_del (&msg->list); -mutex_unlock (&data->pending_lock); + if (msg->length && done &&
then
if (use_irq && done && !wait_for_completion_timeout()
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, · line 244
Quoted 12 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +5
-3+ !wait_for_completion_timeout(done, msecs_to_jiffies(timeout))) { +ssp_pending_del (data, msg); - data->timeout_cnt++; -return -ETIMEDOUT ; - } + data->timeout_cnt++; +return -ETIMEDOUT ; + }return 0 ;
The mix of using a goto error handling block and not in here is not elegant but it's would take quite a bit of reorganizing to tidy that up. One option would be to factor out this bit
mutex_lock(&data->comm_lock);
status = ssp_check_lines(data, false);
if (status < 0)
goto _error_locked;
status = spi_write(data->spi, msg->buffer, SSP_HEADER_SIZE);
if (status < 0) {
gpiod_set_value_cansleep(data->ap_mcu_gpiod, 1);
dev_err(SSP_DEV, "%s spi_write fail\n", __func__);
goto _error_locked;
}
if (!use_no_irq) {
mutex_lock(&data->pending_lock);
list_add_tail(&msg->list, &data->pending_list);
mutex_unlock(&data->pending_lock);
}
status = ssp_check_lines(data, true);
if (status < 0) {
if (!use_no_irq) {
mutex_lock(&data->pending_lock);
list_del(&msg->list);
mutex_unlock(&data->pending_lock);
}
goto _error_locked;
}
mutex_unlock(&data->comm_lock);into a helper, use guard() for the outer mutex and then direct returns.
Then we only have a simple check on return value from that to decide to increment the counter and exit on error.
Re: [PATCH v7 2/9] iio: ssp_sensors: factor out pending list add/remove helper(s)
Quoted 2 lines · Jonathan Cameron
On Sun, 26 Apr 2026 14:47:03 +0530
Sanjay Chitroda <[email protected]> wrote:
...
Quoted 14 lines
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_check_lines(struct ssp_data *data, bool state) · line 184
Quoted 8 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +8
-0+static inline void ssp_pending_add (struct ssp_data *data,struct ssp_msg *msg) +{ +/* +* Check if this is a short one way message or the whole transfer has +* second part after an interrupt. +*/ +if (msg->length ==0 ) +return ;I know Andy suggested your bring these into the helpers, but to me it's obscuring flow as it looks at the caller like it was added to the pending list when it wasn't.. And we end up with multiple checks on
msg_lengthwhere we had one before.
Quoted 4 lines
One option would be to have it return a bool to indicate whether it was added to the pending list or not.
Andy, would that work for you?
Sure.
I have looked at the proposed use and have no objections on the approach.
Quoted 4 lines
Quoted 4 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +4
-0+mutex_lock (&data->pending_lock); +list_add_tail (&msg->list, &data->pending_list); +mutex_unlock (&data->pending_lock); +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 2/9] iio: ssp_sensors: factor out pending list add/remove helper(s)
In reply to Jonathan CameronQuoted 93 lines · Jonathan Cameron
Quoted 34 lines · On Sun, 26 Apr 2026 14:47:03 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
The SSP SPI transfer path manipulates the pending message list in multiple places, each time open-coding the same locking and list operations.
Re-factor the pending list add and delete logic into small helper functions and drop
use_no_irqvariable to avoid duplication and simplify transfer flow to follow.No functional change intended.
Signed-off-by Sanjay Chitroda <[email protected]>Suggested-by Andy Shevchenko <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>---
Changes in v7:
- Following suggestion from Andy, keep helper API definition in single
line and re-place the comment section
- v6 change: https://lore.kernel.org/all/[email protected]/
Changes in v6:
- Include tag for the suggestion of helper functions
- Drop completelyuse_no_irqvariable with review comment from Andy
- v5 change: https://lore.kernel.org/all/[email protected]/--- drivers/iio/common/ssp_sensors/ssp_spi.c | 58 ++++++++++++++---------- 1 file changed, 33 insertions(+), 25 deletions(-)drivers/iio/common/ssp_sensors/ssp_spi.c +0
-0@@ -174,15 +174,35 @@ static int ssp_check_lines(struct ssp_data *data, bool state)return 0 ;drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_check_lines(struct ssp_data *data, bool state) · line 184
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +8
-0} +static inline void ssp_pending_add (struct ssp_data *data,struct ssp_msg *msg) +{ +/* +* Check if this is a short one way message or the whole transfer has +* second part after an interrupt. +*/ +if (msg->length ==0 ) +return ;I know Andy suggested your bring these into the helpers, but to me it's obscuring flow as it looks at the caller like it was added to the pending list when it wasn't.. And we end up with multiple checks on
msg_lengthwhere we had one before.One option would be to have it return a bool to indicate whether it was added to the pending list or not.
Andy, would that work for you?
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_check_lines(struct ssp_data *data, bool state) · line 194
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +10
-0+ +mutex_lock (&data->pending_lock); +list_add_tail (&msg->list, &data->pending_list); +mutex_unlock (&data->pending_lock); +} + +static inline void ssp_pending_del (struct ssp_data *data,struct ssp_msg *msg) +{ +/* See ssp_pending_add() for transfer length logic */ +if (msg->length ==0 )Not useful to know if this happened at caller, so no need to return bool from this.
Quoted 23 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +7
-5+return ; + +mutex_lock (&data->pending_lock); +list_del (&msg->list); +mutex_unlock (&data->pending_lock); +} +static int ssp_do_transfer (struct ssp_data *data,struct ssp_msg *msg,struct completion *done,int timeout) {int status; -/* -* check if this is a short one way message or the whole transfer has -* second part after an interrupt -*/ -const bool use_no_irq = msg->length ==0 ;if (data->shut_down)return -EPERM ;@@ -202,35 +222,23 @@ static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, goto _error_locked; }
Quoted 9 lines
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, · line 225
Quoted 6 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-5-if (!use_no_irq) { -mutex_lock (&data->pending_lock); -list_add_tail (&msg->list, &data->pending_list); -mutex_unlock (&data->pending_lock); - } +ssp_pending_add (data, msg);With suggestion above this would become
Thank you for the input.
Agree will include in next series.
Quoted 72 lines
use_irq = ssp_pending_add(data, msg);Quoted 12 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-5status =ssp_check_lines (data, true);if (status <0 ) { -if (!use_no_irq) { -mutex_lock (&data->pending_lock); -list_del (&msg->list); -mutex_unlock (&data->pending_lock); - } +ssp_pending_del (data, msg); goto _error_locked; }drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, · line 235
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-7mutex_unlock (&data->comm_lock); -if (!use_no_irq && done) -if (wait_for_completion_timeout (done, -msecs_to_jiffies (timeout)) == -0 ) { -mutex_lock (&data->pending_lock); -list_del (&msg->list); -mutex_unlock (&data->pending_lock); + if (msg->length && done &&then
if (use_irq && done && !wait_for_completion_timeout()drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, · line 244
Quoted 12 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +5
-3+ !wait_for_completion_timeout(done, msecs_to_jiffies(timeout))) { +ssp_pending_del (data, msg); - data->timeout_cnt++; -return -ETIMEDOUT ; - } + data->timeout_cnt++; +return -ETIMEDOUT ; + }return 0 ;The mix of using a goto error handling block and not in here is not elegant but it's would take quite a bit of reorganizing to tidy that up. One option would be to factor out this bit
mutex_lock(&data->comm_lock); status = ssp_check_lines(data, false); if (status < 0) goto _error_locked; status = spi_write(data->spi, msg->buffer, SSP_HEADER_SIZE); if (status < 0) { gpiod_set_value_cansleep(data->ap_mcu_gpiod, 1); dev_err(SSP_DEV, "%s spi_write fail\n", __func__); goto _error_locked; } if (!use_no_irq) { mutex_lock(&data->pending_lock); list_add_tail(&msg->list, &data->pending_list); mutex_unlock(&data->pending_lock); } status = ssp_check_lines(data, true); if (status < 0) { if (!use_no_irq) { mutex_lock(&data->pending_lock); list_del(&msg->list); mutex_unlock(&data->pending_lock); } goto _error_locked; } mutex_unlock(&data->comm_lock);
Quoted 2 lines
into a helper, use
guard()for the outer mutex and then direct returns.
Hi Jonathan,
Thank you for review and point,
If we convert this change to sub-function then suggested use_irq would be shifted to sub-function; then how would you suggest to handle that bool ?
- keep msg->length as it is
- in sub function __ssp_do_transfer(data, msg), should we pass additional parameter to bool for further execution?
Or any better alternative to handle both ?
Thanks,
Sanjay Chitroda
Quoted 3 lines
Then we only have a simple check on return value from that to decide to increment the counter and exit on error.
Jonathan Cameron
maintainerRe: [PATCH v7 2/9] iio: ssp_sensors: factor out pending list add/remove helper(s)
Quoted 180 lines · On Sun, 03 May 2026 16:53:27 +0530 Sanjay Chitroda…
Quoted 93 lines · Jonathan Cameron
Quoted 34 lines · On Sun, 26 Apr 2026 14:47:03 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
The SSP SPI transfer path manipulates the pending message list in multiple places, each time open-coding the same locking and list operations.
Re-factor the pending list add and delete logic into small helper functions and drop
use_no_irqvariable to avoid duplication and simplify transfer flow to follow.No functional change intended.
Signed-off-by Sanjay Chitroda <[email protected]>Suggested-by Andy Shevchenko <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>---
Changes in v7:
- Following suggestion from Andy, keep helper API definition in single
line and re-place the comment section
- v6 change: https://lore.kernel.org/all/[email protected]/
Changes in v6:
- Include tag for the suggestion of helper functions
- Drop completelyuse_no_irqvariable with review comment from Andy
- v5 change: https://lore.kernel.org/all/[email protected]/--- drivers/iio/common/ssp_sensors/ssp_spi.c | 58 ++++++++++++++---------- 1 file changed, 33 insertions(+), 25 deletions(-)drivers/iio/common/ssp_sensors/ssp_spi.c +0
-0@@ -174,15 +174,35 @@ static int ssp_check_lines(struct ssp_data *data, bool state)return 0 ;drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_check_lines(struct ssp_data *data, bool state) · line 184
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +8
-0} +static inline void ssp_pending_add (struct ssp_data *data,struct ssp_msg *msg) +{ +/* +* Check if this is a short one way message or the whole transfer has +* second part after an interrupt. +*/ +if (msg->length ==0 ) +return ;I know Andy suggested your bring these into the helpers, but to me it's obscuring flow as it looks at the caller like it was added to the pending list when it wasn't.. And we end up with multiple checks on
msg_lengthwhere we had one before.One option would be to have it return a bool to indicate whether it was added to the pending list or not.
Andy, would that work for you?
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_check_lines(struct ssp_data *data, bool state) · line 194
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +10
-0+ +mutex_lock (&data->pending_lock); +list_add_tail (&msg->list, &data->pending_list); +mutex_unlock (&data->pending_lock); +} + +static inline void ssp_pending_del (struct ssp_data *data,struct ssp_msg *msg) +{ +/* See ssp_pending_add() for transfer length logic */ +if (msg->length ==0 )Not useful to know if this happened at caller, so no need to return bool from this.
Quoted 23 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +7
-5+return ; + +mutex_lock (&data->pending_lock); +list_del (&msg->list); +mutex_unlock (&data->pending_lock); +} +static int ssp_do_transfer (struct ssp_data *data,struct ssp_msg *msg,struct completion *done,int timeout) {int status; -/* -* check if this is a short one way message or the whole transfer has -* second part after an interrupt -*/ -const bool use_no_irq = msg->length ==0 ;if (data->shut_down)return -EPERM ;@@ -202,35 +222,23 @@ static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, goto _error_locked; }Quoted 9 lines
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, · line 225
Quoted 6 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-5-if (!use_no_irq) { -mutex_lock (&data->pending_lock); -list_add_tail (&msg->list, &data->pending_list); -mutex_unlock (&data->pending_lock); - } +ssp_pending_add (data, msg);With suggestion above this would become
Thank you for the input.
Agree will include in next series.Quoted 72 lines
use_irq = ssp_pending_add(data, msg);Quoted 12 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-5status =ssp_check_lines (data, true);if (status <0 ) { -if (!use_no_irq) { -mutex_lock (&data->pending_lock); -list_del (&msg->list); -mutex_unlock (&data->pending_lock); - } +ssp_pending_del (data, msg); goto _error_locked; }drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, · line 235
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-7mutex_unlock (&data->comm_lock); -if (!use_no_irq && done) -if (wait_for_completion_timeout (done, -msecs_to_jiffies (timeout)) == -0 ) { -mutex_lock (&data->pending_lock); -list_del (&msg->list); -mutex_unlock (&data->pending_lock); + if (msg->length && done &&then
if (use_irq && done && !wait_for_completion_timeout()drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_do_transfer(struct ssp_data *data, struct ssp_msg *msg, · line 244
Quoted 12 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +5
-3+ !wait_for_completion_timeout(done, msecs_to_jiffies(timeout))) { +ssp_pending_del (data, msg); - data->timeout_cnt++; -return -ETIMEDOUT ; - } + data->timeout_cnt++; +return -ETIMEDOUT ; + }return 0 ;The mix of using a goto error handling block and not in here is not elegant but it's would take quite a bit of reorganizing to tidy that up. One option would be to factor out this bit
mutex_lock(&data->comm_lock); status = ssp_check_lines(data, false); if (status < 0) goto _error_locked; status = spi_write(data->spi, msg->buffer, SSP_HEADER_SIZE); if (status < 0) { gpiod_set_value_cansleep(data->ap_mcu_gpiod, 1); dev_err(SSP_DEV, "%s spi_write fail\n", __func__); goto _error_locked; } if (!use_no_irq) { mutex_lock(&data->pending_lock); list_add_tail(&msg->list, &data->pending_list); mutex_unlock(&data->pending_lock); } status = ssp_check_lines(data, true); if (status < 0) { if (!use_no_irq) { mutex_lock(&data->pending_lock); list_del(&msg->list); mutex_unlock(&data->pending_lock); } goto _error_locked; } mutex_unlock(&data->comm_lock);Quoted 2 lines
into a helper, use
guard()for the outer mutex and then direct returns.
Quoted 7 lines
Hi Jonathan,
Thank you for review and point,
If we convert this change to sub-function then suggested
use_irqwould be shifted to sub-function; then how would you suggest to handle that bool ?
- keepmsg->lengthas it is
- in sub function__ssp_do_transfer(data, msg), should we pass additional parameter to bool for further execution?
Pass in any additional parameters you need. If it becomes too long then this was a bad idea and you should ignore me ;)
J
Quoted 9 lines
Or any better alternative to handle both ?
Thanks,
Sanjay ChitrodaQuoted 3 lines
Then we only have a simple check on return value from that to decide to increment the counter and exit on error.
Re: [PATCH v7 2/9] iio: ssp_sensors: factor out pending list add/remove helper(s)
Quoted 5 lines · Jonathan Cameron
Quoted 3 lines · On Sun, 03 May 2026 16:53:27 +0530 Sanjay Chitroda…
Quoted 2 lines · Jonathan Cameron
On Sun, 26 Apr 2026 14:47:03 +0530
Sanjay Chitroda <[email protected]> wrote:
...
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (msg->length == 0) + return;I know Andy suggested your bring these into the helpers, but to me it's obscuring flow as it looks at the caller like it was added to the pending list when it wasn't.. And we end up with multiple checks on
msg_lengthwhere we had one before.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
One option would be to have it return a bool to indicate whether it was added to the pending list or not.
Andy, would that work for you?
I don't remember if I answered anything to this, but returning bool is fine...
...
Quoted 7 lines
Quoted 5 lines
If we convert this change to sub-function then suggested
use_irqwould be shifted to sub-function; then how would you suggest to handle that bool ?
- keepmsg->lengthas it is
- in sub function__ssp_do_transfer(data, msg), should we pass additional parameter to bool for further execution?Pass in any additional parameters you need. If it becomes too long then this was a bad idea and you should ignore me ;)
...however, the coding style (or some documentation) suggests against bool parameters to the functions.
Quoted 4 lines
Quoted 4 lines
Or any better alternative to handle both ?
Quoted 2 lines
Then we only have a simple check on return value from that to decide to increment the counter and exit on error.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v7 2/9] iio: ssp_sensors: factor out pending list add/remove helper(s)
Quoted 31 lines · On Wed, 6 May 2026 10:37:23 +0300 Andy Shevchenko…
Quoted 5 lines · Jonathan Cameron
Quoted 3 lines · On Sun, 03 May 2026 16:53:27 +0530 Sanjay Chitroda…
Quoted 2 lines · Jonathan Cameron
On Sun, 26 Apr 2026 14:47:03 +0530
Sanjay Chitroda <[email protected]> wrote:...
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (msg->length == 0) + return;I know Andy suggested your bring these into the helpers, but to me it's obscuring flow as it looks at the caller like it was added to the pending list when it wasn't.. And we end up with multiple checks on
msg_lengthwhere we had one before.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
One option would be to have it return a bool to indicate whether it was added to the pending list or not.
Andy, would that work for you?
I don't remember if I answered anything to this, but returning bool is fine...
...
Quoted 5 lines
Quoted 5 lines
If we convert this change to sub-function then suggested
use_irqwould be shifted to sub-function; then how would you suggest to handle that bool ?
- keepmsg->lengthas it is
- in sub function__ssp_do_transfer(data, msg), should we pass additional parameter to bool for further execution?
Quoted 6 lines
Quoted 2 lines
Pass in any additional parameters you need. If it becomes too long then this was a bad idea and you should ignore me ;)
...however, the coding style (or some documentation) suggests against bool parameters to the functions.
How much duplication do we actually get if we split it? So have totally seperate functions for what would otherwise have been true / false values of that parameter and pick at the caller?
Maybe that ends up cleaner. To be honest this needs someone to play around and see what works out as least hideous.
Jonathan
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Or any better alternative to handle both ?
Quoted 2 lines
Then we only have a simple check on return value from that to decide to increment the counter and exit on error.
PATCH v7 3/9 iio: ssp_sensors: cancel delayed work_refresh on remove
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
The work_refresh may still be pending or running when the device is removed, cancel the delayed work_refresh in remove path.
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/common/ssp_sensors/ssp_dev.c +1 -0
@@ -590,6 +590,7 @@ static void ssp_remove(struct spi_device *spi)ssp_clean_pending_list (data);free_irq (data->spi->irq, data); +cancel_delayed_work_sync (&data->work_refresh);timer_delete_sync (&data->wdt_timer);cancel_work_sync (&data->work_wdt);
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v7 3/9] iio: ssp_sensors: cancel delayed work_refresh on remove
Quoted 6 lines · On Sun, 26 Apr 2026 14:47:04 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
The
work_refreshmay still be pending or running when the device is removed, cancel the delayedwork_refreshin remove path.Fixes 50dd64d57eee ("iio: common: ssp_sensors: Add sensorhub driver")
Fixes at start of patch series not after some refactors of unrelated code.
Quoted 17 lines
Signed-off-by Sanjay Chitroda <[email protected]>--- drivers/iio/common/ssp_sensors/ssp_dev.c | 1 + 1 file changed, 1 insertion(+)drivers/iio/common/ssp_sensors/ssp_dev.c +1
-0@@ -590,6 +590,7 @@ static void ssp_remove(struct spi_device *spi)ssp_clean_pending_list (data);free_irq (data->spi->irq, data); +cancel_delayed_work_sync (&data->work_refresh);timer_delete_sync (&data->wdt_timer);cancel_work_sync (&data->work_wdt);
Re: [PATCH v7 3/9] iio: ssp_sensors: cancel delayed work_refresh on remove
Quoted 5 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 26 Apr 2026 14:47:04 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Quoted 7 lines
Quoted 4 lines
The
work_refreshmay still be pending or running when the device is removed, cancel the delayedwork_refreshin remove path.Fixes 50dd64d57eee ("iio: common: ssp_sensors: Add sensorhub driver")Fixes at start of patch series not after some refactors of unrelated code.
Hi Jonathan,
Thank you for input, I will make sure to take care of this in future.
Additionally, this change is independent to the initial two changes. If this change is good for the iio subtree then this would help to reduce overhead in next series.
Quoted 19 lines
Quoted 18 lines
Signed-off-by Sanjay Chitroda <[email protected]>--- drivers/iio/common/ssp_sensors/ssp_dev.c | 1 + 1 file changed, 1 insertion(+)drivers/iio/common/ssp_sensors/ssp_dev.c +1
-0@@ -590,6 +590,7 @@ static void ssp_remove(struct spi_device *spi)ssp_clean_pending_list (data);free_irq (data->spi->irq, data); +cancel_delayed_work_sync (&data->work_refresh);timer_delete_sync (&data->wdt_timer);cancel_work_sync (&data->work_wdt);
Jonathan Cameron
maintainerRe: [PATCH v7 3/9] iio: ssp_sensors: cancel delayed work_refresh on remove
Quoted 11 lines · On Wed, 29 Apr 2026 23:36:24 +0530 Sanjay Chitroda…
Quoted 10 lines · Jonathan Cameron
Quoted 6 lines · On Sun, 26 Apr 2026 14:47:04 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
The
work_refreshmay still be pending or running when the device is removed, cancel the delayedwork_refreshin remove path.Fixes 50dd64d57eee ("iio: common: ssp_sensors: Add sensorhub driver")
Quoted 8 lines
Quoted 2 lines
Fixes at start of patch series not after some refactors of unrelated code.
Hi Jonathan,
Thank you for input, I will make sure to take care of this in future.
Additionally, this change is independent to the initial two changes. If this change is good for the iio subtree then this would help to reduce overhead in next series.
Fair enough. Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks,
Jonathan
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Signed-off-by Sanjay Chitroda <[email protected]>--- drivers/iio/common/ssp_sensors/ssp_dev.c | 1 + 1 file changed, 1 insertion(+)drivers/iio/common/ssp_sensors/ssp_dev.c +1
-0@@ -590,6 +590,7 @@ static void ssp_remove(struct spi_device *spi)ssp_clean_pending_list (data);free_irq (data->spi->irq, data); +cancel_delayed_work_sync (&data->work_refresh);timer_delete_sync (&data->wdt_timer);cancel_work_sync (&data->work_wdt);
PATCH v7 4/9 iio: ssp_sensors: factor out mcu enable/disable helper(s)
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Re-factor the enable and disable MCU logic into small helper functions this simplify transfer flow to follow.
No functional change intended.
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/iio/common/ssp_sensors/ssp_dev.c +14 -4
@@ -89,7 +89,7 @@ static void ssp_sync_available_sensors(struct ssp_data *data) "SSP_MSG2SSP_AP_MCU_SET_DUMPMODE failed\n"); } -static void ssp_enable_mcu (struct ssp_data *data,bool enable) +static void ssp_set_mcu (struct ssp_data *data,bool enable) {dev_info (&data->spi->dev,"current shutdown = %d, old = %d\n" , enable, data->shut_down);
@@ -108,6 +108,16 @@ static void ssp_enable_mcu(struct ssp_data *data, bool enable) } } +static inline void ssp_enable_mcu (struct ssp_data *data) +{ +ssp_set_mcu (data, true); +} + +static inline void ssp_disable_mcu (struct ssp_data *data) +{ +ssp_set_mcu (data, false); +} +/* * This function is the first one which communicates with the mcu so it is * possible that the first attempt will fail
@@ -146,10 +156,10 @@ static int ssp_check_fwbl(struct ssp_data *data)static void ssp_reset_mcu (struct ssp_data *data) { -ssp_enable_mcu (data, false); +ssp_disable_mcu (data);ssp_clean_pending_list (data);ssp_toggle_mcu_reset_gpio (data); -ssp_enable_mcu (data, true); +ssp_enable_mcu (data); }static void ssp_wdt_work_func (struct work_struct *work)
@@ -584,7 +594,7 @@ static void ssp_remove(struct spi_device *spi)dev_err (&data->spi->dev,"SSP_MSG2SSP_AP_STATUS_SHUTDOWN failed\n" ); -ssp_enable_mcu (data, false); +ssp_disable_mcu (data);ssp_disable_wdt_timer (data);ssp_clean_pending_list (data);
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v7 4/9] iio: ssp_sensors: factor out mcu enable/disable helper(s)
Quoted 28 lines · On Sun, 26 Apr 2026 14:47:05 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Re-factor the enable and disable MCU logic into small helper functions this simplify transfer flow to follow.
No functional change intended.
Signed-off-by Sanjay Chitroda <[email protected]>--- drivers/iio/common/ssp_sensors/ssp_dev.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)drivers/iio/common/ssp_sensors/ssp_dev.c +1
-1@@ -89,7 +89,7 @@ static void ssp_sync_available_sensors(struct ssp_data *data) "SSP_MSG2SSP_AP_MCU_SET_DUMPMODE failed\n"); } -static void ssp_enable_mcu (struct ssp_data *data,bool enable) +static void ssp_set_mcu (struct ssp_data *data,bool enable) {dev_info (&data->spi->dev,"current shutdown = %d, old = %d\n" , enable, data->shut_down);@@ -108,6 +108,16 @@ static void ssp_enable_mcu(struct ssp_data *data, bool enable) } }
drivers/iio/common/ssp_sensors/ssp_dev.c static void ssp_enable_mcu(struct ssp_data *data, bool enable) · line 119
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +9
-0+static inline void ssp_enable_mcu (struct ssp_data *data) +{ +ssp_set_mcu (data, true); +} + +static inline void ssp_disable_mcu (struct ssp_data *data) +{ +ssp_set_mcu (data, false); +}
There is no significant shared code in ssp_set_mcu() for true vs false. Also never add inlines in c files without very strong perf data to back them up.
So something like:
static void ssp_enable_mcu(struct ssp_data *data)
{
dev_info(&data->spi->dev, "current shutdown = %d, old = %d\n", enable,
data->shut_down);
if (!data->shutdown) {
dev_warn(&data->spi->dev, "current shutdown = %d, old = %d\n",
enable, data->shut_down);// I think this is debug only. So I'd drop the print as something that shouldn't // be in code after development is done.
return; } data->shut_down = false; enable_irq(data->spi->irq); enable_irq_wake(data->spi->irq); }
and similar for disable_mcu()
FWIW I don't like having a dev_info() print there. So demote that to dev_dbg().
Quoted 26 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +4
-3+/* * This function is the first one which communicates with the mcu so it is * possible that the first attempt will fail @@ -146,10 +156,10 @@ static int ssp_check_fwbl(struct ssp_data *data)static void ssp_reset_mcu (struct ssp_data *data) { -ssp_enable_mcu (data, false); +ssp_disable_mcu (data);ssp_clean_pending_list (data);ssp_toggle_mcu_reset_gpio (data); -ssp_enable_mcu (data, true); +ssp_enable_mcu (data); }static void ssp_wdt_work_func (struct work_struct *work)@@ -584,7 +594,7 @@ static void ssp_remove(struct spi_device *spi)dev_err (&data->spi->dev,"SSP_MSG2SSP_AP_STATUS_SHUTDOWN failed\n" ); -ssp_enable_mcu (data, false); +ssp_disable_mcu (data);ssp_disable_wdt_timer (data);ssp_clean_pending_list (data);
PATCH v7 5/9 iio: ssp_sensors: use local struct device
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Introduce a struct device *dev derived from &spi->dev to improve readability and reorder variable(s) to follow reversed xmas tree style.
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/iio/common/ssp_sensors/ssp_dev.c +12 -11
@@ -492,27 +492,28 @@ EXPORT_SYMBOL_NS(ssp_register_consumer, "IIO_SSP_SENSORS");static int ssp_probe (struct spi_device *spi) { -int ret, i; +struct device *dev = &spi->dev;struct ssp_data *data; +int ret, i; - data =ssp_parse_dt (&spi->dev); + data =ssp_parse_dt (dev);if (!data) { -dev_err (&spi->dev,"Failed to find platform data\n" ); +dev_err (dev,"Failed to find platform data\n" );return -ENODEV ; } - ret =mfd_add_devices (&spi->dev,PLATFORM_DEVID_NONE , + ret =mfd_add_devices (dev,PLATFORM_DEVID_NONE , sensorhub_sensor_devs,ARRAY_SIZE (sensorhub_sensor_devs),NULL ,0 ,NULL );if (ret <0 ) { -dev_err (&spi->dev,"mfd add devices fail\n" ); +dev_err (dev,"mfd add devices fail\n" );return ret; } spi->mode =SPI_MODE_1 ; ret =spi_setup (spi);if (ret <0 ) { -dev_err (&spi->dev,"Failed to setup spi\n" ); +dev_err (dev,"Failed to setup spi\n" ); goto err_setup_spi; }
@@ -548,7 +549,7 @@ static int ssp_probe(struct spi_device *spi)IRQF_TRIGGER_FALLING |IRQF_ONESHOT , "SSP_Int", data);if (ret <0 ) { -dev_err (&spi->dev,"Irq request fail\n" ); +dev_err (dev,"Irq request fail\n" ); goto err_setup_irq; }
@@ -562,11 +563,11 @@ static int ssp_probe(struct spi_device *spi)if (data->fw_dl_state ==SSP_FW_DL_STATE_NONE ) { ret =ssp_initialize_mcu (data);if (ret <0 ) { -dev_err (&spi->dev,"Initialize_mcu failed\n" ); +dev_err (dev,"Initialize_mcu failed\n" ); goto err_read_reg; } }else { -dev_err (&spi->dev,"Firmware version not supported\n" ); +dev_err (dev,"Firmware version not supported\n" ); ret = -EPERM ; goto err_read_reg; }
@@ -579,9 +580,9 @@ static int ssp_probe(struct spi_device *spi)mutex_destroy (&data->pending_lock);mutex_destroy (&data->comm_lock); err_setup_spi: -mfd_remove_devices (&spi->dev); +mfd_remove_devices (dev); -dev_err (&spi->dev,"Probe failed!\n" ); +dev_err (dev,"Probe failed!\n" );return ret; }
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v7 5/9] iio: ssp_sensors: use local struct device
Quoted 4 lines · On Sun, 26 Apr 2026 14:47:06 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Introduce a struct device *dev derived from
&spi->devto improve readability and reorder variable(s) to follow reversed xmas tree style.
It's really minor reordering but generally I'd not do that in a patch that does anything else. So here I'd have put the new variables in as close to correct location as possible, then followed with a reorder if it was worth the churn that results. I'm not sure it is in this particular case.
drivers/iio/common/ssp_sensors/ssp_dev.c static int ssp_probe(struct spi_device *spi) · line 585
Quoted 12 lines
Signed-off-by Sanjay Chitroda <[email protected]>drivers/iio/common/ssp_sensors/ssp_dev.c +2
-2@@ -579,9 +580,9 @@ static int ssp_probe(struct spi_device *spi)mutex_destroy (&data->pending_lock);mutex_destroy (&data->comm_lock); err_setup_spi: -mfd_remove_devices (&spi->dev); +mfd_remove_devices (dev); -dev_err (&spi->dev,"Probe failed!\n" ); +dev_err (dev,"Probe failed!\n" );
Drop this one. It's easy to find out if a driver probe succeeded so we don't need a print for it given meaningful errors generated messages anyway.
Quoted 3 lines
(quoted diff) +0
-0return ret; }
Re: [PATCH v7 5/9] iio: ssp_sensors: use local struct device
Quoted 2 lines · Jonathan Cameron
On Sun, 26 Apr 2026 14:47:06 +0530
Sanjay Chitroda <[email protected]> wrote:
...
Quoted 7 lines
Quoted 2 lines
Introduce a struct device *dev derived from
&spi->devto improve readability and reorder variable(s) to follow reversed xmas tree style.It's really minor reordering but generally I'd not do that in a patch that does anything else. So here I'd have put the new variables in as close to correct location as possible, then followed with a reorder if it was worth the churn that results. I'm not sure it is in this particular case.
+1. And ideally that 'i' has to be converted to unsigned type.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 5/9] iio: ssp_sensors: use local struct device
Quoted 8 lines · Andy Shevchenko
Quoted 2 lines · Jonathan Cameron
On Sun, 26 Apr 2026 14:47:06 +0530
Sanjay Chitroda <[email protected]> wrote:...
Quoted 2 lines
Quoted 2 lines
Introduce a struct device *dev derived from
&spi->devto improve readability and reorder variable(s) to follow reversed xmas tree style.
Quoted 7 lines
Quoted 5 lines
It's really minor reordering but generally I'd not do that in a patch that does anything else. So here I'd have put the new variables in as close to correct location as possible, then followed with a reorder if it was worth the churn that results. I'm not sure it is in this particular case.
+1. And ideally that 'i' has to be converted to unsigned type.
Thank you Jonathan and Andy for review.
I will keep this change specific to dev and drop redundant probe failure log.
Also, as a follow-up change will do re-order variables and have unsigned type change.
Quoted 1 line
PATCH v7 6/9 iio: ssp_sensors: Drop duplicated wdt timer and work cleanup
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
The SSP remove path cleans up the watchdog timer and associated work both via ssp_disable_wdt_timer() and through explicit timer and work teardown.
ssp_disable_wdt_timer() already performs a synchronous teardown of the watchdog timer and watchdog work, guaranteeing that no timer callbacks or watchdog work can be running or requeued once it returns.
In addition, the remove path disables interrupts and frees IRQ handler using ssp_disable_mcu() and free_irq(). The refresh work is also cancelled, preventing wdt_timer being re-armed before teardown. This ensures that no new refresh or watchdog activity can be triggered from the IRQ thread and refresh workqueue.
As a result, the additional timer and work cancellation is redundant and does not provide additional ordering or race protection. Remove the duplicated cleanup and rely on the centralized watchdog disable helper.
---
Changes in v7:
- Following comment from Andy, Study the timer, work and IRQ
relationship and how it would work internally for ssp_sensors and
changes looks correct; updated the commit message to explain the
race condition and information on resource release during teardown.
- v6 change: https://lore.kernel.org/all/[email protected]/
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/iio/common/ssp_sensors/ssp_dev.c +1 -4
@@ -596,15 +596,12 @@ static void ssp_remove(struct spi_device *spi) "SSP_MSG2SSP_AP_STATUS_SHUTDOWN failed\n");ssp_disable_mcu (data); -ssp_disable_wdt_timer (data); -ssp_clean_pending_list (data);free_irq (data->spi->irq, data);cancel_delayed_work_sync (&data->work_refresh); -timer_delete_sync (&data->wdt_timer); -cancel_work_sync (&data->work_wdt); +ssp_disable_wdt_timer (data);mutex_destroy (&data->comm_lock);mutex_destroy (&data->pending_lock);
Signature · 1 line
2.34.1
Re: [PATCH v7 6/9] iio: ssp_sensors: Drop duplicated wdt timer and work cleanup
Quoted 14 lines · Sanjay Chitroda
The SSP remove path cleans up the watchdog timer and associated work both via
ssp_disable_wdt_timer()and through explicit timer and work teardown.
ssp_disable_wdt_timer()already performs a synchronous teardown of the watchdog timer and watchdog work, guaranteeing that no timer callbacks or watchdog work can be running or requeued once it returns.In addition, the remove path disables interrupts and frees IRQ handler using
ssp_disable_mcu()andfree_irq(). The refresh work is also cancelled, preventingwdt_timerbeing re-armed before teardown. This ensures that no new refresh or watchdog activity can be triggered from the IRQ thread and refresh workqueue.
Quoted 3 lines
As a result, the additional timer and work cancellation is redundant and does not provide additional ordering or race protection. Remove the duplicated cleanup and rely on the centralized watchdog disable helper.
Nice...
...
drivers/iio/common/ssp_sensors/ssp_dev.c static void ssp_remove(struct spi_device *spi) · line 600
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +0
-2ssp_disable_mcu (data); -ssp_disable_wdt_timer (data); -
...but this is left unexplained. The commit message as I read it relies on the fact of this call to be present here and not being moved below.
drivers/iio/common/ssp_sensors/ssp_dev.c static void ssp_remove(struct spi_device *spi) · line 604
Quoted 8 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +1
-2ssp_clean_pending_list (data);free_irq (data->spi->irq, data);cancel_delayed_work_sync (&data->work_refresh); -timer_delete_sync (&data->wdt_timer); -cancel_work_sync (&data->work_wdt); +ssp_disable_wdt_timer (data);
Now it's still possible that watchdog will fire and we might have a callback run while the IRQs are already being disabled. Which means that if WDT callback needs the HW to be able to generate IRQs, it won't happen.
Note, that IRQ can be still fired in between ssp_disable_mcu() and free_irq(). Only the latter call makes sure you want see any IRQs from HW.
Quoted 2 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +0
-0mutex_destroy (&data->comm_lock);mutex_destroy (&data->pending_lock);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 6/9] iio: ssp_sensors: Drop duplicated wdt timer and work cleanup
Quoted 10 lines · Andy Shevchenko
Quoted 8 lines · Sanjay Chitroda
The SSP remove path cleans up the watchdog timer and associated work both via
ssp_disable_wdt_timer()and through explicit timer and work teardown.
ssp_disable_wdt_timer()already performs a synchronous teardown of the watchdog timer and watchdog work, guaranteeing that no timer callbacks or watchdog work can be running or requeued once it returns.
Quoted 6 lines
Quoted 6 lines
In addition, the remove path disables interrupts and frees IRQ handler using
ssp_disable_mcu()andfree_irq(). The refresh work is also cancelled, preventingwdt_timerbeing re-armed before teardown. This ensures that no new refresh or watchdog activity can be triggered from the IRQ thread and refresh workqueue.
Calling ssp_disable_wdt_timer() after IRQ teardown is safe, as the watchdog disable helper does not depend on interrupt delivery and ensures all watchdog activity is fully synchronized before returning.
Quoted 20 lines
Quoted 3 lines
As a result, the additional timer and work cancellation is redundant and does not provide additional ordering or race protection. Remove the duplicated cleanup and rely on the centralized watchdog disable helper.
Nice...
...
drivers/iio/common/ssp_sensors/ssp_dev.c static void ssp_remove(struct spi_device *spi) · line 600
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +0
-2ssp_disable_mcu (data); -ssp_disable_wdt_timer (data); -...but this is left unexplained. The commit message as I read it relies on the fact of this call to be present here and not being moved below.
Quoted 5 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +0
-0ssp_clean_pending_list (data);free_irq (data->spi->irq, data);cancel_delayed_work_sync (&data->work_refresh);
Quoted 8 lines
drivers/iio/common/ssp_sensors/ssp_dev.c static void ssp_remove(struct spi_device *spi) · line 604
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +1
-2-timer_delete_sync (&data->wdt_timer); -cancel_work_sync (&data->work_wdt); +ssp_disable_wdt_timer (data);Now it's still possible that watchdog will fire and we might have a callback run while the IRQs are already being disabled. Which means that if WDT callback needs the HW to be able to generate IRQs, it won't happen.
Thank you for the review.
I will add a section in commit message as above to justify wdt cleanup shifted to specific position.
Quoted 6 lines
Note, that IRQ can be still fired in between
ssp_disable_mcu()andfree_irq(). Only the latter call makes sure you want see any IRQs from HW.Quoted 2 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +0
-0mutex_destroy (&data->comm_lock);mutex_destroy (&data->pending_lock);
PATCH v7 7/9 iio: ssp_sensors: convert probe and teardown to devm-managed resources
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Convert SSP driver resource management to use devm-managed helpers and devm actions, tying the lifetime of all resources to the device.
Mutex initialization, IRQ registration, work items, timers, and MFD resource are now managed using devm APIs. Cleanup logic previously handled explicitly in probe error paths and the remove callback is replaced with devm_add_action_or_reset(), ensuring correct teardown ordering and consistent behaviour on probe failure and device unbind.
This simplifies the probe path by removing goto-based error handling, eliminates the remove callback entirely.
No functional change intended.
---
Changes in v7:
- Following input from Jonathan, added comment to describe the managed action
- Keep it single line for devm_add_..() API definition
- v6 change: https://lore.kernel.org/all/[email protected]/
Changes in v6:
- Drop remove path completely using devm_action with review comment from David
- Convert MFD device to manage resource along with mutex and IRQ
- v5 change: https://lore.kernel.org/all/[email protected]/
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 117 +++++++++++++---------- 1 file changed, 65 insertions(+), 52 deletions(-)
drivers/iio/common/ssp_sensors/ssp_dev.c +65 -52
@@ -204,6 +204,26 @@ static void ssp_disable_wdt_timer(struct ssp_data *data)cancel_work_sync (&data->work_wdt); } +static void ssp_disable_work_timer (void *ptr) +{ +struct ssp_data *data = ptr; + +cancel_delayed_work_sync (&data->work_refresh); +ssp_disable_wdt_timer (data); +} + +static void ssp_shutdown_action (void *ptr) +{ +struct ssp_data *data = ptr; + +if (ssp_command (data,SSP_MSG2SSP_AP_STATUS_SHUTDOWN ,0 ) <0 ) +dev_err (&data->spi->dev, +"SSP_MSG2SSP_AP_STATUS_SHUTDOWN failed\n" ); + +ssp_disable_mcu (data); +ssp_clean_pending_list (data); +} +/** * ssp_get_sensor_delay() - gets sensor data acquisition period * @data: sensorhub structure
@@ -502,9 +522,9 @@ static int ssp_probe(struct spi_device *spi)return -ENODEV ; } - ret =mfd_add_devices (dev,PLATFORM_DEVID_NONE , - sensorhub_sensor_devs, -ARRAY_SIZE (sensorhub_sensor_devs),NULL ,0 ,NULL ); + ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , + sensorhub_sensor_devs, +ARRAY_SIZE (sensorhub_sensor_devs),NULL ,0 ,NULL );if (ret <0 ) {dev_err (dev,"mfd add devices fail\n" );return ret;
@@ -514,14 +534,16 @@ static int ssp_probe(struct spi_device *spi) ret =spi_setup (spi);if (ret <0 ) {dev_err (dev,"Failed to setup spi\n" ); - goto err_setup_spi; +return ret; } data->fw_dl_state =SSP_FW_DL_STATE_NONE ; data->spi = spi;spi_set_drvdata (spi, data); -mutex_init (&data->comm_lock); + ret =devm_mutex_init (dev, &data->comm_lock); +if (ret <0 ) +return ret;for (i =0 ; i <SSP_SENSOR_MAX ; ++i) { data->delay_buf[i] =SSP_DEFAULT_POLLING_DELAY ;
@@ -534,7 +556,9 @@ static int ssp_probe(struct spi_device *spi) data->time_syncing = true; -mutex_init (&data->pending_lock); + ret =devm_mutex_init (dev, &data->pending_lock); +if (ret <0 ) +return ret;INIT_LIST_HEAD (&data->pending_list);atomic_set (&data->enable_refcount,0 );
@@ -544,14 +568,23 @@ static int ssp_probe(struct spi_device *spi)timer_setup (&data->wdt_timer, ssp_wdt_timer_func,0 ); - ret =request_threaded_irq (data->spi->irq,NULL , - ssp_irq_thread_fn, -IRQF_TRIGGER_FALLING |IRQF_ONESHOT , -"SSP_Int" , data); -if (ret <0 ) { -dev_err (dev,"Irq request fail\n" ); - goto err_setup_irq; - } +/* +* Register deferred callback which disable timer and work after +* module unloaded. +* +* driver should cancel delayed refresh work, watchdog work and delete +* watchdog timer once interrupt is disabled and IRQ is freed. +*/ + ret =devm_add_action_or_reset (dev, ssp_disable_work_timer, data); +if (ret <0 ) +return ret; + + ret =devm_request_threaded_irq (dev, data->spi->irq,NULL , + ssp_irq_thread_fn, +IRQF_TRIGGER_FALLING |IRQF_ONESHOT , +"SSP_Int" , data); +if (ret <0 ) +return ret;/* Let's start with enabled one so irq balance could be ok */ data->shut_down = false;
@@ -564,49 +597,30 @@ static int ssp_probe(struct spi_device *spi) ret =ssp_initialize_mcu (data);if (ret <0 ) {dev_err (dev,"Initialize_mcu failed\n" ); - goto err_read_reg; +return ret; } }else {dev_err (dev,"Firmware version not supported\n" ); - ret = -EPERM ; - goto err_read_reg; +return -EPERM ; } -return 0 ; - -err_read_reg: -free_irq (data->spi->irq, data); -err_setup_irq: -mutex_destroy (&data->pending_lock); -mutex_destroy (&data->comm_lock); -err_setup_spi: -mfd_remove_devices (dev); - -dev_err (dev,"Probe failed!\n" ); - -return ret; -} - -static void ssp_remove (struct spi_device *spi) -{ -struct ssp_data *data =spi_get_drvdata (spi); - -if (ssp_command (data,SSP_MSG2SSP_AP_STATUS_SHUTDOWN ,0 ) <0 ) -dev_err (&data->spi->dev, -"SSP_MSG2SSP_AP_STATUS_SHUTDOWN failed\n" ); - -ssp_disable_mcu (data); -ssp_clean_pending_list (data); - -free_irq (data->spi->irq, data); -cancel_delayed_work_sync (&data->work_refresh); - -ssp_disable_wdt_timer (data); - -mutex_destroy (&data->comm_lock); -mutex_destroy (&data->pending_lock); +/* +* Managed shutdown action for the SSP device lifecycle. +* +* This action unwinds state by: +* - notifying the SSP firmware of AP shutdown, +* - disabling the MCU to prevent further IRQ activity, +* - cleaning up any pending command state. +* +* The action is registered once the MCU has been initialized so that +* both driver removal and probe failure after this point leave the +* device in a quiescent state. +*/ + ret =devm_add_action_or_reset (dev, ssp_shutdown_action, data); +if (ret <0 ) +return ret; -mfd_remove_devices (&spi->dev); +return 0 ; }static int ssp_suspend (struct device *dev)
@@ -662,7 +676,6 @@ static DEFINE_SIMPLE_DEV_PM_OPS(ssp_pm_ops, ssp_suspend, ssp_resume);static struct spi_driver ssp_driver = { .probe = ssp_probe, - .remove = ssp_remove, .driver = { .pm =pm_sleep_ptr (&ssp_pm_ops), .of_match_table = ssp_of_match,
Signature · 1 line
2.34.1
PATCH v7 8/9 iio: ssp_sensors: Use dev_err_probe
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
dev_err_probe() makes error code handling simpler and handle deferred probe nicely (avoid spamming logs).
---
changes in v7:
- Drop redundant else with refactor as guided by Andy
- Add new change in series for local dev variable with input from Andy
- v6 change: https://lore.kernel.org/all/[email protected]/
--- drivers/iio/common/ssp_sensors/ssp_dev.c | 38 +++++++++--------------- 1 file changed, 14 insertions(+), 24 deletions(-)
drivers/iio/common/ssp_sensors/ssp_dev.c +14 -24
@@ -517,25 +517,19 @@ static int ssp_probe(struct spi_device *spi)int ret, i; data =ssp_parse_dt (dev); -if (!data) { -dev_err (dev,"Failed to find platform data\n" ); -return -ENODEV ; - } +if (!data) +return dev_err_probe (dev, -ENODEV ,"Failed to find platform data\n" ); - ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , - sensorhub_sensor_devs, + ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , sensorhub_sensor_devs,ARRAY_SIZE (sensorhub_sensor_devs),NULL ,0 ,NULL ); -if (ret <0 ) { -dev_err (dev,"mfd add devices fail\n" ); -return ret; - } + +if (ret <0 ) +return dev_err_probe (dev, ret,"mfd add devices fail\n" ); spi->mode =SPI_MODE_1 ; ret =spi_setup (spi); -if (ret <0 ) { -dev_err (dev,"Failed to setup spi\n" ); -return ret; - } +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to setup spi\n" ); data->fw_dl_state =SSP_FW_DL_STATE_NONE ; data->spi = spi;
@@ -593,16 +587,12 @@ static int ssp_probe(struct spi_device *spi)enable_irq_wake (data->spi->irq); data->fw_dl_state =ssp_check_fwbl (data); -if (data->fw_dl_state ==SSP_FW_DL_STATE_NONE ) { - ret =ssp_initialize_mcu (data); -if (ret <0 ) { -dev_err (dev,"Initialize_mcu failed\n" ); -return ret; - } - }else { -dev_err (dev,"Firmware version not supported\n" ); -return -EPERM ; - } +if (data->fw_dl_state !=SSP_FW_DL_STATE_NONE ) +return dev_err_probe (dev, -EPERM ,"Firmware version not supported\n" ); + + ret =ssp_initialize_mcu (data); +if (ret <0 ) +return dev_err_probe (dev, ret,"Initialize_mcu failed\n" );/* * Managed shutdown action for the SSP device lifecycle.
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v7 8/9] iio: ssp_sensors: Use dev_err_probe
Quoted 23 lines · On Sun, 26 Apr 2026 14:47:09 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
dev_err_probe()makes error code handling simpler and handle deferred probe nicely (avoid spamming logs).Signed-off-by Sanjay Chitroda <[email protected]>---
changes in v7:
- Drop redundant else with refactor as guided by Andy
- Add new change in series for local dev variable with input from Andy
- v6 change: https://lore.kernel.org/all/[email protected]/--- drivers/iio/common/ssp_sensors/ssp_dev.c | 38 +++++++++--------------- 1 file changed, 14 insertions(+), 24 deletions(-)drivers/iio/common/ssp_sensors/ssp_dev.c +0
-0@@ -517,25 +517,19 @@ static int ssp_probe(struct spi_device *spi)int ret, i; data =ssp_parse_dt (dev);
drivers/iio/common/ssp_sensors/ssp_dev.c static int ssp_probe(struct spi_device *spi) · line 523
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +3
-6-if (!data) { -dev_err (dev,"Failed to find platform data\n" ); -return -ENODEV ; - } +if (!data) +return dev_err_probe (dev, -ENODEV ,"Failed to find platform data\n" ); - ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, - sensorhub_sensor_devs, + ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, sensorhub_sensor_devs,
Unrelated change. Should not be in this patch.
drivers/iio/common/ssp_sensors/ssp_dev.c static int ssp_probe(struct spi_device *spi) · line 525
Quoted 6 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +1
-4ARRAY_SIZE(sensorhub_sensor_devs), NULL, 0, NULL); -if (ret <0 ) { -dev_err (dev,"mfd add devices fail\n" ); -return ret; - } +
Normal to not have a blank line between call and error check, so why one here?
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +2
-0+if (ret <0 ) +return dev_err_probe (dev, ret,"mfd add devices fail\n" );
Re: [PATCH v7 8/9] iio: ssp_sensors: Use dev_err_probe
Quoted 2 lines · Jonathan Cameron
On Sun, 26 Apr 2026 14:47:09 +0530
Sanjay Chitroda <[email protected]> wrote:
...
Quoted 15 lines
drivers/iio/common/ssp_sensors/ssp_dev.c static int ssp_probe(struct spi_device *spi) · line 523
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +1
-2- ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, - sensorhub_sensor_devs, + ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, sensorhub_sensor_devs,Unrelated change. Should not be in this patch.
drivers/iio/common/ssp_sensors/ssp_dev.c static int ssp_probe(struct spi_device *spi) · line 525
Quoted 6 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +1
-4ARRAY_SIZE(sensorhub_sensor_devs), NULL, 0, NULL); -if (ret <0 ) { -dev_err (dev,"mfd add devices fail\n" ); -return ret; - } +Normal to not have a blank line between call and error check, so why one here?
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_dev.c static int ssp_probe(struct spi_device *spi) · line 527
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +2
-0+if (ret <0 ) +return dev_err_probe (dev, ret,"mfd add devices fail\n" );
Ah, just replied with very same comments!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 8/9] iio: ssp_sensors: Use dev_err_probe
In reply to Sanjay ChitrodaQuoted 2 lines · Sanjay Chitroda
dev_err_probe()makes error code handling simpler and handle deferred probe nicely (avoid spamming logs).
...
drivers/iio/common/ssp_sensors/ssp_dev.c static int ssp_probe(struct spi_device *spi) · line 524
Quoted 4 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +1
-2- ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , - sensorhub_sensor_devs, + ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , sensorhub_sensor_devs,ARRAY_SIZE (sensorhub_sensor_devs),NULL ,0 ,NULL );
This change can be done when converting to devm, it doesn't belong here.
Quoted 1 line
+
This is stray blank line now...
Quoted 2 lines
drivers/iio/common/ssp_sensors/ssp_dev.c +2
-0+if (ret <0 ) +return dev_err_probe (dev, ret,"mfd add devices fail\n" );
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v7 9/9 iio: ssp_sensors: reuse embedded RX buffer for SPI transfers
In reply to Sanjay ChitrodaFrom: Sanjay Chitroda <[email protected]>
Avoid allocating a temporary DMA buffer in the interrupt context when handling hub-to-AP and AP-to-hub SPI write messages.
Replace the dynamically allocated RX buffer with a fixed-size, preallocated buffer embedded in the driver structure and reused for all SPI receive operations. This removes memory allocation from the IRQ path, simplifies lifetime management.
---
Changes in v6:
- Replace dynamically allocated RX buffer with embedded fixed-size buffer
- Fix struct layout to satisfy DMA alignment constraints comment from David
- v5 change: https://lore.kernel.org/all/[email protected]/
Changes in v5:
- Rebase change on top of latest v5 patch series.
Changes in v4:
- Use preallocated buffer and stash a buffer that gets reused each time instead of a fresh allocation.
- v3 change: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- prepare series to have all respective cleanup API support for the ssp_sensors following input from Andy Shevchenko
- v2 change: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- split series to individual patch
- address review comment from Andy Shevchenko
- v1 change: https://lore.kernel.org/all/[email protected]/
--- drivers/iio/common/ssp_sensors/ssp.h | 3 +++ drivers/iio/common/ssp_sensors/ssp_spi.c | 20 ++------------------ 2 files changed, 5 insertions(+), 18 deletions(-)
drivers/iio/common/ssp_sensors/ssp.h +3 -0
@@ -174,6 +174,7 @@ struct ssp_sensorhub_info {* @pending_list: pending list for messages queued to be sent/read * @sensor_devs: registered IIO devices table * @enable_refcount: enable reference count for wdt (watchdog timer) +* @rx_buf: buffer to receive SPI data * @header_buffer: cache aligned buffer for packet header */ struct ssp_data {
@@ -221,6 +222,8 @@ struct ssp_data {struct iio_dev *sensor_devs[SSP_SENSOR_MAX ];atomic_t enable_refcount; +u8 rx_buf[SSP_DATA_PACKET_SIZE ]; +__le16 header_buffer[SSP_HEADER_BUFFER_SIZE /sizeof (__le16)]__aligned(IIO_DMA_MINALIGN) ; };
drivers/iio/common/ssp_sensors/ssp_spi.c +2 -18
@@ -339,7 +339,7 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)/* threaded irq */ int ssp_irq_msg (struct ssp_data *data) { -char *buffer; +char *buffer = data->rx_buf;u8 msg_type;int ret;u16 length, msg_options;
@@ -383,19 +383,12 @@ int ssp_irq_msg(struct ssp_data *data)* but the slave should not send such ones - it is to * check but let's handle this */ - buffer =kmalloc (length,GFP_KERNEL |GFP_DMA ); -if (!buffer) { - ret = -ENOMEM ; - goto _unlock; - }/* got dead packet so it is always an error */ ret =spi_read (data->spi, buffer, length);if (ret >=0 ) ret = -EPROTO ; -kfree (buffer); -dev_err (SSP_DEV ,"No match error %x\n" , msg_options);
@@ -428,22 +421,13 @@ int ssp_irq_msg(struct ssp_data *data)mutex_unlock (&data->pending_lock);break ;case SSP_HUB2AP_WRITE : - buffer =kzalloc (length,GFP_KERNEL |GFP_DMA ); -if (!buffer) -return -ENOMEM ; - ret =spi_read (data->spi, buffer, length);if (ret <0 ) {dev_err (SSP_DEV ,"spi read fail\n" ); -kfree (buffer);break ; } - ret =ssp_parse_dataframe (data, buffer, length); - -kfree (buffer); -break ; - +return ssp_parse_dataframe (data, buffer, length);default :dev_err (SSP_DEV ,"unknown msg type\n" );return -EPROTO ;
Signature · 1 line
2.34.1
Jonathan Cameron
maintainerRe: [PATCH v7 9/9] iio: ssp_sensors: reuse embedded RX buffer for SPI transfers
Quoted 46 lines · On Sun, 26 Apr 2026 14:47:10 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Avoid allocating a temporary DMA buffer in the interrupt context when handling hub-to-AP and AP-to-hub SPI write messages.
Replace the dynamically allocated RX buffer with a fixed-size, preallocated buffer embedded in the driver structure and reused for all SPI receive operations. This removes memory allocation from the IRQ path, simplifies lifetime management.
Signed-off-by Sanjay Chitroda <[email protected]>---
Changes in v6:
- Replace dynamically allocated RX buffer with embedded fixed-size buffer
- Fix struct layout to satisfy DMA alignment constraints comment from David
- v5 change: https://lore.kernel.org/all/[email protected]/
Changes in v5:
- Rebase change on top of latest v5 patch series.
Changes in v4:
- Use preallocated buffer and stash a buffer that gets reused each time instead of a fresh allocation.
- v3 change: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- prepare series to have all respective cleanup API support for thessp_sensorsfollowing input from Andy Shevchenko
- v2 change: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- split series to individual patch
- address review comment from Andy Shevchenko
- v1 change: https://lore.kernel.org/all/[email protected]/--- drivers/iio/common/ssp_sensors/ssp.h | 3 +++ drivers/iio/common/ssp_sensors/ssp_spi.c | 20 ++------------------ 2 files changed, 5 insertions(+), 18 deletions(-)drivers/iio/common/ssp_sensors/ssp.h +1
-0@@ -174,6 +174,7 @@ struct ssp_sensorhub_info {* @pending_list: pending list for messages queued to be sent/read * @sensor_devs: registered IIO devices table * @enable_refcount: enable reference count for wdt (watchdog timer) +* @rx_buf: buffer to receive SPI data * @header_buffer: cache aligned buffer for packet header */ struct ssp_data {
drivers/iio/common/ssp_sensors/ssp.h struct ssp_data { · line 225
Quoted 4 lines
drivers/iio/common/ssp_sensors/ssp.h +1
-0@@ -221,6 +222,8 @@ struct ssp_data {struct iio_dev *sensor_devs[SSP_SENSOR_MAX ];atomic_t enable_refcount; +u8 rx_buf[SSP_DATA_PACKET_SIZE ];
Whilst the define exists for this size, do we have anything to confirm it is right? It wasn't previously used for anything so is a bit high risk.
Also, why doesn't it need to be DMA safe? I'd expect it either after the following buffer or with a __aligned(IIO_DMA_MINALIGN) marking in which case the one below isn't used.
Quoted 9 lines
drivers/iio/common/ssp_sensors/ssp.h +1
-0+__le16 header_buffer[SSP_HEADER_BUFFER_SIZE /sizeof (__le16)]__aligned(IIO_DMA_MINALIGN) ; };drivers/iio/common/ssp_sensors/ssp_spi.c +0
-0
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len) · line 342
Quoted 5 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-1@@ -339,7 +339,7 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)/* threaded irq */ int ssp_irq_msg (struct ssp_data *data) { -char *buffer; +char *buffer = data->rx_buf;
Put this in inline. The local variable may reduce code churn but it also hides the important info that this is not locally allocated.
Quoted 34 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-11u8 msg_type;int ret;u16 length, msg_options;@@ -383,19 +383,12 @@ int ssp_irq_msg(struct ssp_data *data)* but the slave should not send such ones - it is to * check but let's handle this */ - buffer =kmalloc (length,GFP_KERNEL |GFP_DMA ); -if (!buffer) { - ret = -ENOMEM ; - goto _unlock; - }/* got dead packet so it is always an error */ ret =spi_read (data->spi, buffer, length);if (ret >=0 ) ret = -EPROTO ; -kfree (buffer); -dev_err (SSP_DEV ,"No match error %x\n" , msg_options);@@ -428,22 +421,13 @@ int ssp_irq_msg(struct ssp_data *data)mutex_unlock (&data->pending_lock);break ;case SSP_HUB2AP_WRITE : - buffer =kzalloc (length,GFP_KERNEL |GFP_DMA ); -if (!buffer) -return -ENOMEM ; - ret =spi_read (data->spi, buffer, length);if (ret <0 ) {dev_err (SSP_DEV ,"spi read fail\n" );
drivers/iio/common/ssp_sensors/ssp_spi.c int ssp_irq_msg(struct ssp_data *data) · line 430
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-6-kfree (buffer);break ; } - ret =ssp_parse_dataframe (data, buffer, length); - -kfree (buffer); -break ; - +return ssp_parse_dataframe (data, buffer, length);
This now makes this path different from the other switch legs. I would precede this patch with one doing direct returns from all the legs in here. Then this just becomes an obvious update in this patch.
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-0default :dev_err (SSP_DEV ,"unknown msg type\n" );return -EPROTO ;
Re: [PATCH v7 9/9] iio: ssp_sensors: reuse embedded RX buffer for SPI transfers
Quoted 52 lines · Jonathan Cameron
Quoted 49 lines · On Sun, 26 Apr 2026 14:47:10 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Avoid allocating a temporary DMA buffer in the interrupt context when handling hub-to-AP and AP-to-hub SPI write messages.
Replace the dynamically allocated RX buffer with a fixed-size, preallocated buffer embedded in the driver structure and reused for all SPI receive operations. This removes memory allocation from the IRQ path, simplifies lifetime management.
Signed-off-by Sanjay Chitroda <[email protected]>---
Changes in v6:
- Replace dynamically allocated RX buffer with embedded fixed-size buffer
- Fix struct layout to satisfy DMA alignment constraints comment from David
- v5 change: https://lore.kernel.org/all/[email protected]/
Changes in v5:
- Rebase change on top of latest v5 patch series.
Changes in v4:
- Use preallocated buffer and stash a buffer that gets reused each time instead of a fresh allocation.
- v3 change: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- prepare series to have all respective cleanup API support for thessp_sensorsfollowing input from Andy Shevchenko
- v2 change: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- split series to individual patch
- address review comment from Andy Shevchenko
- v1 change: https://lore.kernel.org/all/[email protected]/--- drivers/iio/common/ssp_sensors/ssp.h | 3 +++ drivers/iio/common/ssp_sensors/ssp_spi.c | 20 ++------------------ 2 files changed, 5 insertions(+), 18 deletions(-)drivers/iio/common/ssp_sensors/ssp.h +1
-0@@ -174,6 +174,7 @@ struct ssp_sensorhub_info {* @pending_list: pending list for messages queued to be sent/read * @sensor_devs: registered IIO devices table * @enable_refcount: enable reference count for wdt (watchdog timer) +* @rx_buf: buffer to receive SPI data * @header_buffer: cache aligned buffer for packet header */ struct ssp_data {@@ -221,6 +222,8 @@ struct ssp_data {struct iio_dev *sensor_devs[SSP_SENSOR_MAX ];atomic_t enable_refcount;
Quoted 5 lines
drivers/iio/common/ssp_sensors/ssp.h struct ssp_data { · line 225
Quoted 1 line
drivers/iio/common/ssp_sensors/ssp.h +1
-0+u8 rx_buf[SSP_DATA_PACKET_SIZE ];Whilst the define exists for this size, do we have anything to confirm it is right? It wasn't previously used for anything so is a bit high risk.
Nothing specific to confirm, I'm assuming this macro and value is added during development so must be specificing as per technical or reference manual for the SSP firmware protocol.
Although, we can plan to add check as pre-change like below:
if (length -> sizeof(data->rx_buf)
return -EINVAL;
Quoted 3 lines
Also, why doesn't it need to be DMA safe? I'd expect it either after the following buffer or with a
__aligned(IIO_DMA_MINALIGN)marking in which case the one below isn't used.
I will make it
u8 rx_buf[SSP_DATA_PACKET_SIZE] __aligned(IIO_DMA_MINALIGN);
Quoted 5 lines
Quoted 5 lines
drivers/iio/common/ssp_sensors/ssp.h +1
-0+__le16 header_buffer[SSP_HEADER_BUFFER_SIZE /sizeof (__le16)]__aligned(IIO_DMA_MINALIGN) ; };
Quoted 14 lines
drivers/iio/common/ssp_sensors/ssp_spi.c static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len) · line 342
Quoted 10 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-1@@ -339,7 +339,7 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)/* threaded irq */ int ssp_irq_msg (struct ssp_data *data) { -char *buffer; +char *buffer = data->rx_buf;Put this in inline. The local variable may reduce code churn but it also hides the important info that this is not locally allocated.
Agree, will update.
Quoted 38 lines
Quoted 38 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-12u8 msg_type;int ret;u16 length, msg_options;@@ -383,19 +383,12 @@ int ssp_irq_msg(struct ssp_data *data)* but the slave should not send such ones - it is to * check but let's handle this */ - buffer =kmalloc (length,GFP_KERNEL |GFP_DMA ); -if (!buffer) { - ret = -ENOMEM ; - goto _unlock; - }/* got dead packet so it is always an error */ ret =spi_read (data->spi, buffer, length);if (ret >=0 ) ret = -EPROTO ; -kfree (buffer); -dev_err (SSP_DEV ,"No match error %x\n" , msg_options);@@ -428,22 +421,13 @@ int ssp_irq_msg(struct ssp_data *data)mutex_unlock (&data->pending_lock);break ;case SSP_HUB2AP_WRITE : - buffer =kzalloc (length,GFP_KERNEL |GFP_DMA ); -if (!buffer) -return -ENOMEM ; - ret =spi_read (data->spi, buffer, length);if (ret <0 ) {dev_err (SSP_DEV ,"spi read fail\n" ); -kfree (buffer);break ; }
Quoted 12 lines
drivers/iio/common/ssp_sensors/ssp_spi.c int ssp_irq_msg(struct ssp_data *data) · line 430
Quoted 6 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +1
-5- ret =ssp_parse_dataframe (data, buffer, length); - -kfree (buffer); -break ; - +return ssp_parse_dataframe (data, buffer, length);This now makes this path different from the other switch legs. I would precede this patch with one doing direct returns from all the legs in here. Then this just becomes an obvious update in this patch.
I will precede a patch to update all the legs in switch.
Quoted 4 lines
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-0default :dev_err (SSP_DEV ,"unknown msg type\n" );return -EPROTO ;
Jonathan Cameron
maintainerRe: [PATCH v7 9/9] iio: ssp_sensors: reuse embedded RX buffer for SPI transfers
In reply to Sanjay ChitrodaQuoted 26 lines · On Sun, 26 Apr 2026 14:47:10 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Avoid allocating a temporary DMA buffer in the interrupt context when handling hub-to-AP and AP-to-hub SPI write messages.
Replace the dynamically allocated RX buffer with a fixed-size, preallocated buffer embedded in the driver structure and reused for all SPI receive operations. This removes memory allocation from the IRQ path, simplifies lifetime management.
Signed-off-by Sanjay Chitroda <[email protected]>drivers/iio/common/ssp_sensors/ssp_spi.c +1
-1@@ -339,7 +339,7 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)/* threaded irq */ int ssp_irq_msg (struct ssp_data *data) { -char *buffer; +char *buffer = data->rx_buf;u8 msg_type;int ret;u16 length, msg_options;
drivers/iio/common/ssp_sensors/ssp_spi.c int ssp_irq_msg(struct ssp_data *data) · line 386
Quoted 4 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-1@@ -383,19 +383,12 @@ int ssp_irq_msg(struct ssp_data *data)* but the slave should not send such ones - it is to * check but let's handle this */ - buffer =kmalloc (length,GFP_KERNEL |GFP_DMA );
As bellow.
Quoted 16 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-6-if (!buffer) { - ret = -ENOMEM ; - goto _unlock; - }/* got dead packet so it is always an error */ ret =spi_read (data->spi, buffer, length);if (ret >=0 ) ret = -EPROTO ; -kfree (buffer); -dev_err (SSP_DEV ,"No match error %x\n" , msg_options);
drivers/iio/common/ssp_sensors/ssp_spi.c int ssp_irq_msg(struct ssp_data *data) · line 431
Quoted 4 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-1@@ -428,22 +421,13 @@ int ssp_irq_msg(struct ssp_data *data)mutex_unlock (&data->pending_lock);break ;case SSP_HUB2AP_WRITE : - buffer =kzalloc (length,GFP_KERNEL |GFP_DMA );
Is there any chance that GFP_DMA marking is needed?
Quoted 2 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-2-if (!buffer) -return -ENOMEM ;
Re: [PATCH v7 9/9] iio: ssp_sensors: reuse embedded RX buffer for SPI transfers
Quoted 50 lines · Jonathan Cameron
Quoted 26 lines · On Sun, 26 Apr 2026 14:47:10 +0530 Sanjay Chitroda…
From: Sanjay Chitroda <[email protected]>
Avoid allocating a temporary DMA buffer in the interrupt context when handling hub-to-AP and AP-to-hub SPI write messages.
Replace the dynamically allocated RX buffer with a fixed-size, preallocated buffer embedded in the driver structure and reused for all SPI receive operations. This removes memory allocation from the IRQ path, simplifies lifetime management.
Signed-off-by Sanjay Chitroda <[email protected]>drivers/iio/common/ssp_sensors/ssp_spi.c +1
-1@@ -339,7 +339,7 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)/* threaded irq */ int ssp_irq_msg (struct ssp_data *data) { -char *buffer; +char *buffer = data->rx_buf;u8 msg_type;int ret;u16 length, msg_options;drivers/iio/common/ssp_sensors/ssp_spi.c int ssp_irq_msg(struct ssp_data *data) · line 386
Quoted 4 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-1@@ -383,19 +383,12 @@ int ssp_irq_msg(struct ssp_data *data)* but the slave should not send such ones - it is to * check but let's handle this */ - buffer =kmalloc (length,GFP_KERNEL |GFP_DMA );As bellow.
Quoted 15 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-6-if (!buffer) { - ret = -ENOMEM ; - goto _unlock; - }/* got dead packet so it is always an error */ ret =spi_read (data->spi, buffer, length);if (ret >=0 ) ret = -EPROTO ; -kfree (buffer); -dev_err (SSP_DEV ,"No match error %x\n" , msg_options);
Quoted 7 lines
drivers/iio/common/ssp_sensors/ssp_spi.c int ssp_irq_msg(struct ssp_data *data) · line 431
Quoted 5 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-1@@ -428,22 +421,13 @@ int ssp_irq_msg(struct ssp_data *data)mutex_unlock (&data->pending_lock);break ;case SSP_HUB2AP_WRITE : - buffer =kzalloc (length,GFP_KERNEL |GFP_DMA );Is there any chance that
GFP_DMAmarking is needed?
As per my understanding, this must be legacy flag as there is no direct use of any dma_* API. marking should be redundant and safe to drop.
Quoted 2 lines
Quoted 2 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-2-if (!buffer) -return -ENOMEM ;
Re: [PATCH v7 9/9] iio: ssp_sensors: reuse embedded RX buffer for SPI transfers
Quoted 3 lines · Sanjay Chitroda
Quoted 2 lines · Jonathan Cameron
On Sun, 26 Apr 2026 14:47:10 +0530
Sanjay Chitroda <[email protected]> wrote:
...
Quoted 6 lines
Quoted 3 lines
drivers/iio/common/ssp_sensors/ssp_spi.c int ssp_irq_msg(struct ssp_data *data) · line 431
Quoted 2 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-1case SSP_HUB2AP_WRITE : - buffer =kzalloc (length,GFP_KERNEL |GFP_DMA );Is there any chance that
GFP_DMAmarking is needed?As per my understanding, this must be legacy flag as there is no direct use of any dma_* API. marking should be redundant and safe to drop.
But what does this case with HW? It seems the use of this memory is in spi_read() and SPI framework for sure does dma_*() APIs. Would it be problematic?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/iio/common/ssp_sensors/ssp_spi.c +0
-2-if (!buffer) -return -ENOMEM ;
Signature · 2 lines
With Best Regards, Andy Shevchenko