Thread (15 messages) 15 messages, 2 authors, 2026-01-06

Re: [PATCH net-next v08 1/9] hinic3: Add PF framework

From: Jakub Kicinski <kuba@kernel.org>
Date: 2026-01-06 01:39:18
Also in: linux-doc, lkml

AI code review points out the following.
Please address or add a relevant comment explaining why the code 
is fine.
quoted hunk ↗ jump to hunk
diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c b/drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c
index cf67e26acece..1cb0d88911a2 100644
--- a/drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c
+++ b/drivers/net/ethernet/huawei/hinic3/hinic3_mbox.c
@@ -82,10 +82,19 @@ static struct hinic3_msg_desc *get_mbox_msg_desc(struct hinic3_mbox *mbox,
 						 enum mbox_msg_direction_type dir,
 						 u16 src_func_id)
 {
+	struct hinic3_hwdev *hwdev = mbox->hwdev;
 	struct hinic3_msg_channel *msg_ch;

-	msg_ch = (src_func_id == MBOX_MGMT_FUNC_ID) ?
-		&mbox->mgmt_msg : mbox->func_msg;
+	if (src_func_id == MBOX_MGMT_FUNC_ID) {
+		msg_ch = &mbox->mgmt_msg;
+	} else if (HINIC3_IS_VF(hwdev)) {
+		/* message from pf */
+		msg_ch = mbox->func_msg;
+		if (src_func_id != hinic3_pf_id_of_vf(hwdev) || !msg_ch)
+			return NULL;
+	} else {
+		return NULL;
+	}
Can this return NULL for PF when src_func_id is not MBOX_MGMT_FUNC_ID?

Looking at hinic3_mbox_func_aeqe_handler(), the caller of get_mbox_msg_desc():

    msg_desc = get_mbox_msg_desc(mbox, dir, src_func_id);
    recv_mbox_handler(mbox, header, msg_desc);

The return value is passed directly to recv_mbox_handler() without a
NULL check. Inside recv_mbox_handler():

    if (!mbox_segment_valid(mbox, msg_desc, mbox_header)) {
        msg_desc->seq_id = MBOX_SEQ_ID_MAX_VAL;

And mbox_segment_valid() dereferences msg_desc unconditionally:

    msg_desc->seq_id = seq_id;

If a PF receives a mailbox message from any source other than management
(for example, from a VF), get_mbox_msg_desc() returns NULL, and then
mbox_segment_valid() will dereference the NULL pointer causing a kernel
crash.

Should hinic3_mbox_func_aeqe_handler() check for NULL before calling
recv_mbox_handler()?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help