All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] staging: most: dim2: drop volatile from state counters
@ 2026-11-18 18:24 ` Maximo Manriquez Lizarraga via B4 Relay
  0 siblings, 0 replies; 3+ messages in thread
From: Maximo Manriquez Lizarraga @ 2026-11-18 18:24 UTC (permalink / raw)
  To: shyamsunderreddypadira, marusik.adamenko, error27, gregkh,
	christian.gromm, parthiban.veerasooran, rajveer.chaudhari.linux
  Cc: linux-kernel, linux-staging, Maximo Manriquez Lizarraga

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@tubot.lat>
---
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@tubot.lat

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@tubot.lat
---
 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@tubot.lat>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-20  7:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 18:24 [PATCH v3] staging: most: dim2: drop volatile from state counters Maximo Manriquez Lizarraga
2026-11-18 18:24 ` Maximo Manriquez Lizarraga via B4 Relay
2026-11-20  7:15 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.