* [PATCH] staging: most: dim2: use atomic_t for channel state counters
@ 2026-11-08 3:14 DelaySystem via B4 Relay
2026-11-08 13:53 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: DelaySystem via B4 Relay @ 2026-11-08 3:14 UTC (permalink / raw)
To: christian.gromm, rajveer.chaudhari.linux, gregkh, error27,
parthiban.veerasooran, shyamsunderreddypadira, marusik.adamenko
Cc: linux-staging, linux-kernel, DelaySystem
From: DelaySystem <DelaySystem@tubot.lat>
Replace the volatile int channel state counters with atomic_t and
convert all access sites to the atomic API.
request_counter is incremented in the AHB interrupt handler
(channel_service_interrupt) and read from task context
(channel_service), while service_counter is updated in task context.
Plain volatile provides neither atomicity nor ordering for such
cross-context sharing, see
Documentation/process/volatile-considered-harmful.rst.
Use atomic_set() at init, atomic_inc() for updates and atomic_read()
for the comparison in channel_service(). No functional change is
intended. Unlike the earlier attempt that only dropped the
qualifier, this converts the access sites as well.
Compile-tested only; I don't have this hardware, so testing on real
hardware would be appreciated.
Link: https://lore.kernel.org/linux-staging/2026072515-domestic-cardboard-f657@gregkh/
Signed-off-by: DelaySystem <DelaySystem@tubot.lat>
---
drivers/staging/most/dim2/hal.c | 11 ++++++-----
drivers/staging/most/dim2/hal.h | 5 +++--
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/most/dim2/hal.c b/drivers/staging/most/dim2/hal.c
index 4f137ef846a3..ca931782b06c 100644
--- a/drivers/staging/most/dim2/hal.c
+++ b/drivers/staging/most/dim2/hal.c
@@ -419,8 +419,8 @@ u16 dim_dbr_space(struct dim_channel *ch)
static void state_init(struct int_ch_state *state)
{
- state->request_counter = 0;
- state->service_counter = 0;
+ atomic_set(&state->request_counter, 0);
+ atomic_set(&state->service_counter, 0);
state->idx1 = 0;
state->idx2 = 0;
@@ -634,7 +634,7 @@ static bool channel_service_interrupt(struct dim_channel *ch)
return false;
state->idx2 ^= 1;
- state->request_counter++;
+ atomic_inc(&state->request_counter);
return true;
}
@@ -682,8 +682,9 @@ static u8 channel_service(struct dim_channel *ch)
{
struct int_ch_state *const state = &ch->state;
- if (state->service_counter != state->request_counter) {
- state->service_counter++;
+ if (atomic_read(&state->service_counter) !=
+ atomic_read(&state->request_counter)) {
+ atomic_inc(&state->service_counter);
if (state->level == 0)
return DIM_ERR_UNDERFLOW;
diff --git a/drivers/staging/most/dim2/hal.h b/drivers/staging/most/dim2/hal.h
index 5d69a5e7d299..70b10793cf84 100644
--- a/drivers/staging/most/dim2/hal.h
+++ b/drivers/staging/most/dim2/hal.h
@@ -9,6 +9,7 @@
#ifndef _DIM2_HAL_H
#define _DIM2_HAL_H
+#include <linux/atomic.h>
#include <linux/types.h>
#include "reg.h"
@@ -34,10 +35,10 @@ struct dim_ch_state {
struct int_ch_state {
/* changed only in interrupt context */
- volatile int request_counter;
+ atomic_t request_counter;
/* changed only in task context */
- volatile int service_counter;
+ atomic_t service_counter;
u8 idx1;
u8 idx2;
---
base-commit: a41e364995bbcfa627418a70fe913c35b7510728
change-id: 20261107-staging-dim2-atomic-68a85f8feaf6
Best regards,
--
DelaySystem <DelaySystem@tubot.lat>
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] staging: most: dim2: use atomic_t for channel state counters
2026-11-08 3:14 [PATCH] staging: most: dim2: use atomic_t for channel state counters DelaySystem via B4 Relay
@ 2026-11-08 13:53 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-11-08 13:53 UTC (permalink / raw)
To: DelaySystem
Cc: christian.gromm, rajveer.chaudhari.linux, error27,
parthiban.veerasooran, shyamsunderreddypadira, marusik.adamenko,
linux-staging, linux-kernel
On Sat, Nov 07, 2026 at 07:14:42PM -0800, DelaySystem via B4 Relay wrote:
> From: DelaySystem <DelaySystem@tubot.lat>
THis isn't going to work, please fix all of these...
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-08 13:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 3:14 [PATCH] staging: most: dim2: use atomic_t for channel state counters DelaySystem via B4 Relay
2026-11-08 13:53 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®