Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 4cb584e0ee7d ("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>

authored by

Alexey Kodanev and committed by
Jakub Kicinski
4078c561 5a8db80f

+11 -6
+11 -6
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_target.c
··· 435 435 436 436 /* Full Island ID and channel bits overlap? */ 437 437 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); 439 440 return ret; 441 + } 440 442 441 443 /* 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); 443 447 return -EINVAL; 448 + } 444 449 445 450 /* If dest_island was -1, we don't care where it goes. */ 446 451 return 0; ··· 498 493 * the address but we can verify if the existing 499 494 * contents will point to a valid island. 500 495 */ 501 - return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island, 496 + return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt, 502 497 mode, addr40, isld1, isld0); 503 498 504 499 iid_lsb = addr40 ? 34 : 26; ··· 509 504 return 0; 510 505 case 1: 511 506 if (cpp_tgt == NFP_CPP_TARGET_QDR && !addr40) 512 - return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island, 507 + return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt, 513 508 mode, addr40, isld1, isld0); 514 509 515 510 idx_lsb = addr40 ? 39 : 31; ··· 535 530 * be set before hand and with them select an island. 536 531 * So we need to confirm that it's at least plausible. 537 532 */ 538 - return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island, 533 + return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt, 539 534 mode, addr40, isld1, isld0); 540 535 541 536 /* Make sure we compare against isldN values ··· 556 551 * iid<1> = addr<30> = channel<0> 557 552 * channel<1> = addr<31> = Index 558 553 */ 559 - return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island, 554 + return nfp_encode_basic_qdr(*addr, dest_island, cpp_tgt, 560 555 mode, addr40, isld1, isld0); 561 556 562 557 isld[0] &= ~3;