Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ipc/ipc4/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,8 @@ __cold void ipc_send_panic_notification(void)

#ifdef CONFIG_LOG_BACKEND_ADSP_MTRACE

static atomic_t mtrace_notify_counter;
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The atomic counter should be initialized explicitly to ensure a known starting state. Consider using ATOMIC_INIT(0) or an initialization function to set the initial value to 0.

Suggested change
static atomic_t mtrace_notify_counter;
static atomic_t mtrace_notify_counter = ATOMIC_INIT(0);

Copilot uses AI. Check for mistakes.

static bool is_notification_queued(struct ipc_msg *msg)
{
struct ipc *ipc = ipc_get();
Expand All @@ -1663,7 +1665,8 @@ void ipc_send_buffer_status_notify(void)
return;

msg_notify.header = SOF_IPC4_NOTIF_HEADER(SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS);
msg_notify.extension = 0;
atomic_add(&mtrace_notify_counter, 1);
msg_notify.extension = atomic_read(&mtrace_notify_counter);
Comment on lines +1668 to +1669
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using separate atomic_add() and atomic_read() operations creates a potential race condition. Between these two operations, another thread could modify the counter, causing the extension field to contain a different value than what was incremented. Use atomic_inc_return() or atomic_fetch_add() instead to atomically increment and read the value in a single operation.

Suggested change
atomic_add(&mtrace_notify_counter, 1);
msg_notify.extension = atomic_read(&mtrace_notify_counter);
msg_notify.extension = atomic_inc_return(&mtrace_notify_counter);

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack atomic_add() will return the current value which we should use in the extension.

Comment on lines 1667 to +1669
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the host need this? Has there been a situation where it received the same notification more than once?
I checked the documentation and there is no such iterator in this message. I think in the case of all notifications the extension field remains empty.

msg_notify.tx_size = 0;

tr_dbg(&ipc_tr, "tx-notify\t: %#x|%#x", msg_notify.header, msg_notify.extension);
Expand Down
Loading