Skip to contentSkip to conversation

qed: Fix missing bar_id comparison in qed_hw_bar_size()

PATCH In review Ian Rogers 2 participants 2 messages Nov 19 – Nov 23

Subsystems (3)
lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 qed: Fix missing bar_id comparison in qed_hw_bar_size()

When PGLUE_B_REG_PF_BAR{0,1}_SIZE reads back as 0 on older management firmware with multi-hwfn devices, qed_hw_bar_size() logs that it assumes 256 KiB for GRC (BAR_ID_0) and 512 KiB for DB (BAR_ID_1), but evaluates:

return BAR_ID_0 ? 256 * 1024 : 512 * 1024;

Because BAR_ID_0 is enum constant 0, the ternary condition is always false and qed_hw_bar_size() unconditionally returns 512 KiB even for BAR_ID_0, doubling the computed GRC BAR offset for the second hardware function.

Compare bar_id == BAR_ID_0 as intended (matching the bar_reg selection at the top of qed_hw_bar_size()).

Found by enabling Clang's -Wunreachable-code on an x86_64 allyesconfig build, with AI coding assistant help to audit the warning and prepare the fix. Build-tested with Clang; not runtime-tested on QLogic hardware.

Fixes c2035eea3e9e ("qed: Correct BAR sizes for older MFW")
---
 drivers/net/ethernet/qlogic/qed/qed_dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_dev.c +2 -2
index dd75c47758e1..3e84f53dfb50 100644
@@ -1264,11 +1264,11 @@ static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn,
 	if (p_hwfn->cdev->num_hwfns > 1) {
 		DP_INFO(p_hwfn,
 			"BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
-			return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
+		return bar_id == BAR_ID_0 ? 256 * 1024 : 512 * 1024;
 	} else {
 		DP_INFO(p_hwfn,
 			"BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
-			return 512 * 1024;
+		return 512 * 1024;
 	}
 }
 
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines

When PGLUE_B_REG_PF_BAR{0,1}_SIZE reads back as 0 on older management firmware with multi-hwfn devices, qed_hw_bar_size() logs that it assumes 256 KiB for GRC (BAR_ID_0) and 512 KiB for DB (BAR_ID_1), but evaluates:

return BAR_ID_0 ? 256 * 1024 : 512 * 1024;

Because BAR_ID_0 is enum constant 0, the ternary condition is always false and qed_hw_bar_size() unconditionally returns 512 KiB even for BAR_ID_0, doubling the computed GRC BAR offset for the second hardware function.

Compare bar_id == BAR_ID_0 as intended (matching the bar_reg selection at the top of qed_hw_bar_size()).

Quoted 6 lines

Found by enabling Clang's -Wunreachable-code on an x86_64 allyesconfig build, with AI coding assistant help to audit the warning and prepare the fix. Build-tested with Clang; not runtime-tested on QLogic hardware.

Fixes c2035eea3e9e ("qed: Correct BAR sizes for older MFW")