public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Anas Iqbal <mohd.abd.6602@gmail.com>
To: iyappan@os.amperecomputing.com
Cc: keyur@os.amperecomputing.com, quan@os.amperecomputing.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	edumazet@google.com, andrew+netdev@lunn.ch,
	Anas Iqbal <mohd.abd.6602@gmail.com>
Subject: [PATCH] net: xgene: fix signedness bug in xgene_enet_get_fpsel()
Date: Thu, 19 Mar 2026 09:11:06 +0000	[thread overview]
Message-ID: <20260319091106.1662-1-mohd.abd.6602@gmail.com> (raw)

xgene_enet_get_fpsel() returns a u8 but can compute a negative
value when xgene_enet_ring_bufnum(id) is less than
RING_BUFNUM_BUFPOOL. This leads to an implicit conversion of a
negative value to u8, resulting in a large unintended value.

This can cause incorrect behavior when the result is used in
bit operations such as BIT(), potentially leading to undefined
behavior.

Fix this by validating the value before subtraction to avoid
underflow.

Fixes: 2c839337520b ("drivers: net: xgene: Add helper function")
Signed-off-by: Anas Iqbal <mohd.abd.6602@gmail.com>
---
 drivers/net/ethernet/apm/xgene/xgene_enet_hw.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h
index 2f534f9d4416..fe563c396773 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h
@@ -405,10 +405,16 @@ static inline bool xgene_enet_is_bufpool(u16 id)
 
 static inline u8 xgene_enet_get_fpsel(u16 id)
 {
-	if (xgene_enet_is_bufpool(id))
-		return xgene_enet_ring_bufnum(id) - RING_BUFNUM_BUFPOOL;
+	u16 val;
 
-	return 0;
+	if (!xgene_enet_is_bufpool(id))
+		return 0;
+
+	val = xgene_enet_ring_bufnum(id);
+	if (val < RING_BUFNUM_BUFPOOL)
+		return 0;
+
+	return val - RING_BUFNUM_BUFPOOL;
 }
 
 static inline u16 xgene_enet_get_numslots(u16 id, u32 size)
-- 
2.43.0


             reply	other threads:[~2026-03-19  9:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19  9:11 Anas Iqbal [this message]
2026-03-20 16:21 ` [PATCH] net: xgene: fix signedness bug in xgene_enet_get_fpsel() Simon Horman
2026-03-21 12:45   ` Anas Iqbal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260319091106.1662-1-mohd.abd.6602@gmail.com \
    --to=mohd.abd.6602@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=iyappan@os.amperecomputing.com \
    --cc=keyur@os.amperecomputing.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=quan@os.amperecomputing.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox