Skip to content

Commit 4078c56

Browse files
akodanevkuba-moo
authored andcommitted
nfp: fix swapped arguments in nfp_encode_basic_qdr() calls
There is a mismatch between the passed arguments and the actual nfp_encode_basic_qdr() function parameter names: static int nfp_encode_basic_qdr(u64 addr, int dest_island, int cpp_tgt, int mode, bool addr40, int isld1, int isld0) { ... But "dest_island" and "cpp_tgt" are swapped at every call-site. For example: return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island, mode, addr40, isld1, isld0); As a result, nfp_encode_basic_qdr() receives "dest_island" as CPP target type, which is always NFP_CPP_TARGET_QDR(2) for these calls, and "cpp_tgt" as the destination island ID, which can accidentally match or be outside the valid NFP_CPP_TARGET_* types (e.g. '-1' for any destination). Since code already worked for years, also add extra pr_warn() to error paths in nfp_encode_basic_qdr() to help identify any potential address verification failures. Detected using the static analysis tool - Svace. Fixes: 4cb584e ("nfp: add CPP access core") Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com> Link: https://patch.msgid.link/20260422160536.61855-1-aleksei.kodanev@bell-sw.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 5a8db80 commit 4078c56

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

drivers/net/ethernet/netronome/nfp/nfpcore/nfp_target.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,17 @@ static int nfp_encode_basic_qdr(u64 addr, int dest_island, int cpp_tgt,
435435

436436
/* Full Island ID and channel bits overlap? */
437437
ret = nfp_decode_basic(addr, &v, cpp_tgt, mode, addr40, isld1, isld0);
438-
if (ret)
438+
if (ret) {
439+
pr_warn("%s: decode dest_island failed: %d\n", __func__, ret);
439440
return ret;
441+
}
440442

441443
/* The current address won't go where expected? */
442-
if (dest_island != -1 && dest_island != v)
444+
if (dest_island != -1 && dest_island != v) {
445+
pr_warn("%s: dest_island mismatch: current (%d) != decoded (%d)\n",
446+
__func__, dest_island, v);
443447
return -EINVAL;
448+
}
444449

445450
/* If dest_island was -1, we don't care where it goes. */
446451
return 0;
@@ -493,7 +498,7 @@ static int nfp_encode_basic(u64 *addr, int dest_island, int cpp_tgt,
493498
* the address but we can verify if the existing
494499
* contents will point to a valid island.
495500
*/
496-
return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island,
501+
return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt,
497502
mode, addr40, isld1, isld0);
498503

499504
iid_lsb = addr40 ? 34 : 26;
@@ -504,7 +509,7 @@ static int nfp_encode_basic(u64 *addr, int dest_island, int cpp_tgt,
504509
return 0;
505510
case 1:
506511
if (cpp_tgt == NFP_CPP_TARGET_QDR && !addr40)
507-
return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island,
512+
return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt,
508513
mode, addr40, isld1, isld0);
509514

510515
idx_lsb = addr40 ? 39 : 31;
@@ -530,7 +535,7 @@ static int nfp_encode_basic(u64 *addr, int dest_island, int cpp_tgt,
530535
* be set before hand and with them select an island.
531536
* So we need to confirm that it's at least plausible.
532537
*/
533-
return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island,
538+
return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt,
534539
mode, addr40, isld1, isld0);
535540

536541
/* Make sure we compare against isldN values
@@ -551,7 +556,7 @@ static int nfp_encode_basic(u64 *addr, int dest_island, int cpp_tgt,
551556
* iid<1> = addr<30> = channel<0>
552557
* channel<1> = addr<31> = Index
553558
*/
554-
return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island,
559+
return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt,
555560
mode, addr40, isld1, isld0);
556561

557562
isld[0] &= ~3;

0 commit comments

Comments
 (0)