[PATCH] net/netvsc: fix bogus sizeof calculation

longli at linuxonhyperv.com longli at linuxonhyperv.com
Thu Jun 29 02:29:57 CEST 2023


From: Stephen Hemminger <stephen at networkplumber.org>

Found by cppcheck.

drivers/net/netvsc/hn_rndis.c:332:21: warning: Found calculation inside sizeof(). [sizeofCalculation]  if (len < sizeof(3 * sizeof(uint32_t))) {

Fixes: 4e9c73e96e83 ("net/netvsc: add Hyper-V network device")
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Signed-off-by: Long Li <longli at microsoft.com>
---
 drivers/net/netvsc/hn_rndis.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/netvsc/hn_rndis.c b/drivers/net/netvsc/hn_rndis.c
index e6f1f28768..29c6009b2c 100644
--- a/drivers/net/netvsc/hn_rndis.c
+++ b/drivers/net/netvsc/hn_rndis.c
@@ -329,7 +329,8 @@ void hn_rndis_receive_response(struct hn_data *hv,
 
 	hn_rndis_dump(data);
 
-	if (len < sizeof(3 * sizeof(uint32_t))) {
+	/* Check we can read first three data fields from RNDIS header */
+	if (len < 3 * sizeof(uint32_t)) {
 		PMD_DRV_LOG(ERR,
 			    "missing RNDIS header %u", len);
 		return;
-- 
2.17.1



More information about the dev mailing list