RE: [PATCH v14 4/6] firmware: imx: add driver for NXP EdgeLock Enclave

From: Pankaj Gupta
Date: Wed Apr 02 2025 - 02:14:41 EST


>> diff --git a/drivers/firmware/imx/ele_common.c
...
>> + *
>> + * Return:
>> + * 0: if the input length is not 4 byte aligned, or num of words < 5.
>> + * chksum: calculated word by word.
>> + */
>> +u32 se_add_msg_chksum(u32 *msg, u32 msg_len) {
>> + u32 nb_words = msg_len / (u32)sizeof(u32);
>> + u32 chksum = 0;
>> + u32 i;
>> +
>> + if (nb_words < 5)
>> + return chksum;

For msg_length = 8 bytes or nb_words = 2, execution flow will never continue
after the above check.

>> +
>> + if (msg_len % SE_MSG_WORD_SZ) {
>> + pr_err("Msg-len is not 4-byte aligned.");
>> + return chksum;
>> + }
>> +
>> + for (i = 0; i < nb_words - 1; i++)
>> + chksum ^= *(msg + i);

> if msg_len is 8, nv_words is 2,
For msg_length = 8 bytes or nb_words = 2, execution flow will never here.

> Only first *(msg + 0) is calcucate, is it what your expected? If yes,
> need comments said why *(msg + 1) needn't calcuate.

Since msg_len also includes the 4 bytes (or 1word) to store the checksum
value. Hence, *(msg + 1) needn't be calcuated
Will add that as a comment.

>> +
>> + return chksum;
>> +}
>> +


>> +int ele_msg_rcv(struct se_if_priv *priv,
>> + struct se_clbk_handle *se_clbk_hdl) {
>> + int err = 0;
>> +
>> + do {
>> + err = wait_for_completion_interruptible(&se_clbk_hdl->done);
>> + if (err == -ERESTARTSYS) {
>> + if (priv->waiting_rsp_clbk_hdl.rx_msg) {
>> + priv->waiting_rsp_clbk_hdl.signal_rcvd =
true;
>> + continue;

> Is possible dead loop here?
No. it will be the same condition with or without continue.
- With using ctrl + c, in case of no response from FW, it will continue to
wait indefinitely. There will be no impact of using ctrl + c on this.
- Without using ctrl + c, in case of no response from FW, it will continue
to wait indefinitely,

So, this code leg was implemented to handle the scenario, where the FW is
always responsive and "ctrl + c", is pressed to stop an ongoing task.
It will gracefully exits after completing the full exchange.

>> + }

Attachment: smime.p7s
Description: S/MIME cryptographic signature