[<prev] [next>] [day] [month] [year] [list]
Message-Id: <182b9d0235d044d69d7a57c1296cc6f46e395beb.1761039651.git.xiaopei01@kylinos.cn>
Date: Tue, 21 Oct 2025 17:42:27 +0800
From: Pei Xiao <xiaopei01@...inos.cn>
To: lkp@...el.com,
alexanderduyck@...com,
kernel-team@...a.com,
netdev@...r.kernel.org
Cc: horms@...nel.org,
kuba@...nel.org,
lee@...ger.us,
linux-kernel@...r.kernel.org,
oe-kbuild-all@...ts.linux.dev,
pabeni@...hat.com,
Pei Xiao <xiaopei01@...inos.cn>
Subject: [PATCH] eth: fbnic: fix integer overflow warning in TLV_MAX_DATA definition
The TLV_MAX_DATA macro calculates (PAGE_SIZE - 512) which can exceed
the maximum value of a 16-bit unsigned integer on architectures with
large page sizes, causing compiler warnings:
drivers/net/ethernet/meta/fbnic/fbnic_tlv.h:83:24: warning: conversion
from 'long unsigned int' to 'short unsigned int' changes value from
'261632' to '65024' [-Woverflow]
Fix this by explicitly masking the result to 16 bits using bitwise AND
with 0xFFFF, ensuring the value fits within the expected data type
while maintaining the intended behavior for normal page sizes.
This preserves the existing functionality while eliminating the
compiler warning and potential undefined behavior from integer
truncation.
Reported-by: kernel test robot <lkp@...el.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202510190832.3SQkTCHe-lkp@intel.com/
Signed-off-by: Pei Xiao <xiaopei01@...inos.cn>
---
drivers/net/ethernet/meta/fbnic/fbnic_tlv.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.h b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.h
index c34bf87eeec9..3508b46ebdd0 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.h
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.h
@@ -80,7 +80,7 @@ struct fbnic_tlv_index {
enum fbnic_tlv_type type;
};
-#define TLV_MAX_DATA (PAGE_SIZE - 512)
+#define TLV_MAX_DATA ((PAGE_SIZE - 512) & 0xFFFF)
#define FBNIC_TLV_ATTR_ID_UNKNOWN USHRT_MAX
#define FBNIC_TLV_ATTR_STRING(id, len) { id, len, FBNIC_TLV_STRING }
#define FBNIC_TLV_ATTR_FLAG(id) { id, 0, FBNIC_TLV_FLAG }
--
2.25.1
Powered by blists - more mailing lists