[PATCH v3] staging: most: dim2: drop volatile from state counters

From: Maximo Manriquez Lizarraga via B4 Relay

Date: Wed Nov 18 2026 - 13:26:23 EST


From: Maximo Manriquez Lizarraga <DelaySystem@xxxxxxxxx>

The request_counter/service_counter pair is shared between the AHB
hard-IRQ handler and the threaded-IRQ service path, but every access
already runs under dim_lock with local interrupts disabled:
dim2_ahb_isr() holds it across dim_service_ahb_int_irq(),
dim2_task_irq() across dim_service_channel(), and configure_channel()
across the dim_init_*() calls that zero the counters. The spinlock
provides both the mutual exclusion and the memory barriers, so the
volatile qualifier adds nothing and wrongly suggests lockless
cross-context sharing (see
Documentation/process/volatile-considered-harmful.rst).

Converting to atomic_t is the wrong tool here: the service-side
check-and-increment cannot be a single atomic step when done as
separate atomic_read() calls, as Dan Carpenter pointed out on the
atomic_t attempt, and a lockless scheme would still need dim_lock for
the sibling channel state (level, indices, done-buffer count, MBO
lists) anyway.

Drop the qualifier and document the actual protection in place. No
functional change intended.

Compile-tested only (MOST=m, MOST_DIM2=m build clean); I don't have
this hardware, so testing on real hardware would be appreciated.

Signed-off-by: Maximo Manriquez Lizarraga <DelaySystem@xxxxxxxxx>
---
Changes in v3:
- New direction: drop the NAKed atomic_t conversion. An audit showed every counter access already runs under dim_lock, so drop volatile and document the lock instead (Dan Carpenter).
- Link to v2: https://patch.msgid.link/20261117-staging-dim2-atomic-v2-1-a550f0518043@xxxxxxxxx

Changes in v2:
- Resend under my real name (From/Signed-off-by: Maximo Manriquez Lizarraga).
- Apologies for the wasted cycle; if the objection was technical rather than the sender identity, please say what to change.
- Link to v1: https://patch.msgid.link/20261107-staging-dim2-atomic-v1-1-6eb4e8f1f63a@xxxxxxxxx
---
drivers/staging/most/dim2/hal.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/most/dim2/hal.h b/drivers/staging/most/dim2/hal.h
index 5d69a5e7d299..f857e6856a16 100644
--- a/drivers/staging/most/dim2/hal.h
+++ b/drivers/staging/most/dim2/hal.h
@@ -33,11 +33,11 @@ struct dim_ch_state {
};

struct int_ch_state {
- /* changed only in interrupt context */
- volatile int request_counter;
+ /* protected by dim_lock; incremented in interrupt context */
+ int request_counter;

- /* changed only in task context */
- volatile int service_counter;
+ /* protected by dim_lock; updated in task context */
+ int service_counter;

u8 idx1;
u8 idx2;

---
base-commit: a41e364995bbcfa627418a70fe913c35b7510728
change-id: 20261107-staging-dim2-atomic-68a85f8feaf6

Best regards,
--
Maximo Manriquez Lizarraga <DelaySystem@xxxxxxxxx>