Re: [PATCH net-next v10 6/8] hinic3: Mailbox framework

From: Simon Horman
Date: Wed Jul 23 2025 - 06:36:09 EST


On Tue, Jul 22, 2025 at 03:18:45PM +0800, Fan Gong wrote:

...

> +static void recv_mbox_handler(struct hinic3_mbox *mbox,
> + u64 *header, struct hinic3_msg_desc *msg_desc)
> +{
> + void *mbox_body = MBOX_BODY_FROM_HDR(((void *)header));
> + u64 mbox_header = *header;
> + u8 seq_id, seg_len;
> + int pos;
> +
> + if (!mbox_segment_valid(mbox, msg_desc, mbox_header)) {
> + msg_desc->seq_id = MBOX_SEQ_ID_MAX_VAL;
> + return;
> + }
> +
> + seq_id = MBOX_MSG_HEADER_GET(mbox_header, SEQID);
> + seg_len = MBOX_MSG_HEADER_GET(mbox_header, SEG_LEN);
> +
> + pos = seq_id * MBOX_SEG_LEN;
> + memcpy((u8 *)msg_desc->msg + pos, mbox_body, seg_len);

It would be nice if msg_desc->msg and mbox_body had more meaningful types
than void *. If they are being treated as an array of bytes, then
maybe u8 *?

> +
> + if (!MBOX_MSG_HEADER_GET(mbox_header, LAST))
> + return;
> +
> + msg_desc->msg_len = MBOX_MSG_HEADER_GET(mbox_header, MSG_LEN);
> + msg_desc->msg_info.status = MBOX_MSG_HEADER_GET(mbox_header, STATUS);
> +
> + if (MBOX_MSG_HEADER_GET(mbox_header, DIRECTION) == MBOX_MSG_RESP)
> + resp_mbox_handler(mbox, msg_desc);
> +}
> +
> +void hinic3_mbox_func_aeqe_handler(struct hinic3_hwdev *hwdev, u8 *header,
> + u8 size)
> +{
> + u64 mbox_header = *((u64 *)header);
> + enum mbox_msg_direction_type dir;
> + struct hinic3_msg_desc *msg_desc;
> + struct hinic3_mbox *mbox;
> + u16 src_func_id;
> +
> + mbox = hwdev->mbox;
> + dir = MBOX_MSG_HEADER_GET(mbox_header, DIRECTION);
> + src_func_id = MBOX_MSG_HEADER_GET(mbox_header, SRC_GLB_FUNC_IDX);
> + msg_desc = get_mbox_msg_desc(mbox, dir, src_func_id);
> + recv_mbox_handler(mbox, (u64 *)header, msg_desc);

I would suggest dropping the cast and changing recv_mbox_handler()
to expect header to be a u8 *. I think you can then drop the cast above,
the one at of the argument passed to MBOX_BODY_FROM_HDR()
and the one inside MBOX_BODY_FROM_HDR().

I'd also suggest that MBOX_BODY_FROM_HDR be changed to a
static function so there is some type checking of the argument.

> +}

...