Skip to contentSkip to conversation

net/nfp: fix wrong argument order in nfp_encode_basic

PATCH Superseded Bulatov Mark 2 participants 2 messages Nov 13 – Nov 15 Network drivers

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/nfp: fix wrong argument order in nfp_encode_basic

The function nfp_encode_basic_qdr() takes cpp_tgt as its second argument and dest_island as its third. However, the implementation of this function implies the opposite: dest_island should be the second argument, and cpp_tgt the third.

Furthermore, the implementation compares the second argument against a negative value, whereas the cpp_tgt parameter — as defined in the nfp_target.h header file—consists of a set of values ​​that does not include any negative numbers. The situation is exactly the reverse for the nfp_decode_basic() function, which receives a value for which these definitions are not entirely appropriate.

Fix this by swapping the arguments.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes e6858e7e7c ("net/nfp: move shared target logic to own file")
---
 drivers/net/nfp/nfpcore/nfp_target.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/nfp/nfpcore/nfp_target.c +4 -4
index 0e7a5cbb05..239ffff869 100644
@@ -728,7 +728,7 @@ nfp_encode_basic(uint64_t *addr,
 			 * address but we can verify if the existing contents
 			 * will point to a valid island.
 			 */
-			return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island,
+			return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt,
 					mode, addr40, isld1, isld0);
 		}
 
@@ -741,7 +741,7 @@ nfp_encode_basic(uint64_t *addr,
 		return 0;
 	case 1:
 		if (cpp_tgt == NFP_CPP_TARGET_QDR && addr40 == 0) {
-			return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island,
+			return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt,
 					mode, addr40, isld1, isld0);
 		}
 
@@ -763,7 +763,7 @@ nfp_encode_basic(uint64_t *addr,
 		if (cpp_tgt == NFP_CPP_TARGET_QDR && addr40 == 0) {
 			/* iid<0> = addr<30> = channel<0> */
 			/* channel<1> = addr<31> = Index */
-			return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island,
+			return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt,
 					mode, addr40, isld1, isld0);
 		}
 
@@ -786,7 +786,7 @@ nfp_encode_basic(uint64_t *addr,
 			 * iid<1> = addr<30> = channel<0>
 			 * channel<1> = addr<31> = Index
 			 */
-			return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island,
+			return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt,
 					mode, addr40, isld1, isld0);
 		}
 
Signature · 1 line
2.39.5
#1 lore raw
Quoted 14 lines · On Fri, 13 Nov 2026 17:28:23 +0300 Bulatov Mark <[email protected]> wrote:

The function nfp_encode_basic_qdr() takes cpp_tgt as its second argument and dest_island as its third. However, the implementation of this function implies the opposite: dest_island should be the second argument, and cpp_tgt the third.

Furthermore, the implementation compares the second argument against a negative value, whereas the cpp_tgt parameter — as defined in the nfp_target.h header file—consists of a set of values ​​that does not include any negative numbers. The situation is exactly the reverse for the nfp_decode_basic() function, which receives a value for which these definitions are not entirely appropriate.

Fix this by swapping the arguments.

Quoted 7 lines

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes e6858e7e7c ("net/nfp: move shared target logic to own file")

---

Several issues need fixing from AI review.

[PATCH] net/nfp: fix wrong argument order in nfp_encode_basic

The fix is correct. nfp_encode_basic_qdr() is declared as (addr, dest_island, cpp_tgt, ...) and all four callers pass (addr, cpp_tgt, dest_island, ...). With the swap, decode skipped the MU/CT_XPB guard on the real target and the final compare checked the decoded island against NFP_CPP_TARGET_QDR (2) instead of dest_island, so QDR encoding failed with -EINVAL unless the island happened to be 2.

Warning: Author does not match Signed-off-by.

The patch has no "From: Mark Bulatov" line in the body, so git am records the author as "Bulatov Mark" while the Signed-off-by is "Mark Bulatov". The first patch has the body From: line; this one needs it too, or fix user.name so the header is right.

Warning: Commit message contains non-ASCII characters: two em-dashes and two zero-width spaces (U+200B) in "values that". The second paragraph is also hard to follow. Suggest:

nfp_encode_basic_qdr() takes dest_island as its second argument and cpp_tgt as its third, but all callers in nfp_encode_basic() pass them in the opposite order. As a result nfp_decode_basic() gets the island ID as the target, and the island check compares against NFP_CPP_TARGET_QDR instead of the requested island.

Swap the arguments.

Warning: Fixes tag needs a 12 character hash:

Fixes e6858e7e7cd3 ("net/nfp: move shared target logic to own file")