Skip to content

Commit e8aa209

Browse files
committed
drivers: firmware: scmi: add msg_type validation in callback
In the SCMI core layer, add msg_type validation before dispatch (e.g. RESP vs NOTIFY vs CMD). Messages with an unexpected or invalid type for the current context are logged Signed-off-by: Yongxu Wang <[email protected]>
1 parent 3df3ed3 commit e8aa209

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

drivers/firmware/scmi/core.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,23 @@ int scmi_status_to_errno(int scmi_status)
4343
}
4444
}
4545

46-
static void scmi_core_reply_cb(struct scmi_channel *chan)
46+
static void scmi_core_reply_cb(struct scmi_channel *chan, int hdr)
4747
{
48+
int msg_type;
49+
50+
msg_type = SCMI_MESSAGE_HDR_TAKE_TYPE(hdr);
51+
52+
switch (msg_type) {
53+
case SCMI_COMMAND:
54+
break;
55+
case SCMI_DELAYED_REPLY:
56+
break;
57+
case SCMI_NOTIFICATION:
58+
break;
59+
default:
60+
LOG_WRN("Unexpected message type %u", msg_type);
61+
}
62+
4863
if (!k_is_pre_kernel()) {
4964
k_sem_give(&chan->sem);
5065
}

drivers/firmware/scmi/mailbox.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void scmi_mbox_tx_reply_cb(const struct device *mbox,
4141
scmi_mbox_get_pending_msg(scmi_chan, &msg);
4242

4343
if (scmi_chan->cb) {
44-
scmi_chan->cb(scmi_chan);
44+
scmi_chan->cb(scmi_chan, msg.hdr);
4545
}
4646
}
4747

@@ -58,7 +58,7 @@ static void scmi_mbox_rx_notify_cb(const struct device *mbox,
5858
scmi_mbox_get_pending_msg(scmi_chan, &msg);
5959

6060
if (scmi_chan->cb) {
61-
scmi_chan->cb(scmi_chan);
61+
scmi_chan->cb(scmi_chan, msg.hdr);
6262
scmi_shmem_clear_channel_status(shmem);
6363
}
6464
}

include/zephyr/drivers/firmware/scmi/transport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ struct scmi_channel;
3131
*
3232
* @param chan pointer to SCMI channel on which the reply
3333
* arrived
34+
* @param hdr is the share memory Message header
3435
*/
35-
typedef void (*scmi_channel_cb)(struct scmi_channel *chan);
36+
typedef void (*scmi_channel_cb)(struct scmi_channel *chan, int hdr);
3637

3738
/**
3839
* @struct scmi_channel

0 commit comments

Comments
 (0)