]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
eth: fbnic: Fix counter roll-over issue
authorMohsin Bashir <mohsin.bashr@gmail.com>
Tue, 25 Nov 2025 21:17:04 +0000 (13:17 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 6 Dec 2025 21:24:55 +0000 (06:24 +0900)
[ Upstream commit 6d66e093e0740d39a36ef742c60eec247df26f41 ]

Fix a potential counter roll-over issue in fbnic_mbx_alloc_rx_msgs()
when calculating descriptor slots. The issue occurs when head - tail
results in a large positive value (unsigned) and the compiler interprets
head - tail - 1 as a signed value.

Since FBNIC_IPC_MBX_DESC_LEN is a power of two, use a masking operation,
which is a common way of avoiding this problem when dealing with these
sort of ring space calculations.

Fixes: da3cde08209e ("eth: fbnic: Add FW communication mechanism")
Signed-off-by: Mohsin Bashir <mohsin.bashr@gmail.com>
Link: https://patch.msgid.link/20251125211704.3222413-1-mohsin.bashr@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/meta/fbnic/fbnic_fw.c

index d6cf97ecf3276601bdcf34a416ac446ef067cc91..6f606bdfd229618cb17f4cc532c4fc5bce2916b2 100644 (file)
@@ -198,7 +198,7 @@ static int fbnic_mbx_alloc_rx_msgs(struct fbnic_dev *fbd)
                return -ENODEV;
 
        /* Fill all but 1 unused descriptors in the Rx queue. */
-       count = (head - tail - 1) % FBNIC_IPC_MBX_DESC_LEN;
+       count = (head - tail - 1) & (FBNIC_IPC_MBX_DESC_LEN - 1);
        while (!err && count--) {
                struct fbnic_tlv_msg *msg;