Skip to content

Commit dd61b55

Browse files
yghannambp3tk0v
authored andcommitted
RAS/AMD/ATL: Fix bit overflow in denorm_addr_df4_np2()
The hash_pa8 and hashed_bit values in denorm_addr_df4_np2() are currently defined as u8 types. These variables represent single bits. 'hash_pa8' is set based on logical AND operations using masks with more than 8 bits. So the calculated value will not fit in this variable. It will always be '0'. The 'hash_pa8' check later in the function will fail which produces incorrect results for some cases. Change these variables to bool type. This clarifies that they are single bit values. Also, this allows the compiler to ensure they hold the proper results. Remove an unnecessary shift operation. [ bp: Remove the unnecessary brackets in the else-branch of the hash_pa8 assignment. ] Fixes: 3f31749 ("RAS: Introduce AMD Address Translation Library") Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20240222165449.23582-1-yazen.ghannam@amd.com
1 parent 6f15e61 commit dd61b55

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/ras/amd/atl/denormalize.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ static int denorm_addr_df4_np2(struct addr_ctx *ctx)
545545
unsigned int mod_value, shift_value;
546546
u16 mask = df_cfg.component_id_mask;
547547
u64 temp_addr_a, temp_addr_b;
548-
u8 hash_pa8, hashed_bit;
548+
bool hash_pa8, hashed_bit;
549549

550550
switch (ctx->map.intlv_mode) {
551551
case DF4_NPS4_3CHAN_HASH:
@@ -577,8 +577,7 @@ static int denorm_addr_df4_np2(struct addr_ctx *ctx)
577577
hash_pa8 = BIT_ULL(shift_value) & ctx->ret_addr;
578578
temp_addr_a = remove_bits(shift_value, shift_value, ctx->ret_addr);
579579
} else {
580-
hash_pa8 = (ctx->coh_st_fabric_id & df_cfg.socket_id_mask);
581-
hash_pa8 >>= df_cfg.socket_id_shift;
580+
hash_pa8 = ctx->coh_st_fabric_id & df_cfg.socket_id_mask;
582581
temp_addr_a = ctx->ret_addr;
583582
}
584583

0 commit comments

Comments
 (0)