Skip to content

Commit 4af9939

Browse files
WangYulikuba-moo
authored andcommitted
mlxsw: spectrum_acl_bloom_filter: Workaround for some LLVM versions
This is a workaround to mitigate a compiler anomaly. During LLVM toolchain compilation of this driver on s390x architecture, an unreasonable __write_overflow_field warning occurs. Contextually, chunk_index is restricted to 0, 1 or 2. By expanding these possibilities, the compile warning is suppressed. Fix follow error with clang-19 when -Werror: In file included from drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c:5: In file included from ./include/linux/gfp.h:7: In file included from ./include/linux/mmzone.h:8: In file included from ./include/linux/spinlock.h:63: In file included from ./include/linux/lockdep.h:14: In file included from ./include/linux/smp.h:13: In file included from ./include/linux/cpumask.h:12: In file included from ./include/linux/bitmap.h:13: In file included from ./include/linux/string.h:392: ./include/linux/fortify-string.h:571:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning] 571 | __write_overflow_field(p_size_field, size); | ^ 1 error generated. According to the testing, we can be fairly certain that this is a clang compiler bug, impacting only clang-19 and below. Clang versions 20 and 21 do not exhibit this behavior. Link: https://lore.kernel.org/all/484364B641C901CD+20250311141025.1624528-1-wangyuli@uniontech.com/ Fixes: 7585cac ("mlxsw: spectrum_acl: Add Bloom filter handling") Co-developed-by: Zijian Chen <czj2441@163.com> Signed-off-by: Zijian Chen <czj2441@163.com> Co-developed-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: Wentao Guan <guanwentao@uniontech.com> Suggested-by: Paolo Abeni <pabeni@redhat.com> Co-developed-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Tested-by: Ido Schimmel <idosch@nvidia.com> Tested-by: WangYuli <wangyuli@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com> Link: https://patch.msgid.link/A1858F1D36E653E0+20250318103654.708077-1-wangyuli@uniontech.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 7a9536e commit 4af9939

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_bloom_filter.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,22 @@ static const u8 mlxsw_sp4_acl_bf_crc6_tab[256] = {
212212
* This array defines key offsets for easy access when copying key blocks from
213213
* entry key to Bloom filter chunk.
214214
*/
215-
static const u8 chunk_key_offsets[MLXSW_BLOOM_KEY_CHUNKS] = {2, 20, 38};
215+
static char *
216+
mlxsw_sp_acl_bf_enc_key_get(struct mlxsw_sp_acl_atcam_entry *aentry,
217+
u8 chunk_index)
218+
{
219+
switch (chunk_index) {
220+
case 0:
221+
return &aentry->ht_key.enc_key[2];
222+
case 1:
223+
return &aentry->ht_key.enc_key[20];
224+
case 2:
225+
return &aentry->ht_key.enc_key[38];
226+
default:
227+
WARN_ON_ONCE(1);
228+
return &aentry->ht_key.enc_key[0];
229+
}
230+
}
216231

217232
static u16 mlxsw_sp2_acl_bf_crc16_byte(u16 crc, u8 c)
218233
{
@@ -235,22 +250,24 @@ __mlxsw_sp_acl_bf_key_encode(struct mlxsw_sp_acl_atcam_region *aregion,
235250
u8 key_offset, u8 chunk_key_len, u8 chunk_len)
236251
{
237252
struct mlxsw_afk_key_info *key_info = aregion->region->key_info;
238-
u8 chunk_index, chunk_count, block_count;
253+
u8 chunk_index, chunk_count;
239254
char *chunk = output;
240255
__be16 erp_region_id;
256+
u32 block_count;
241257

242258
block_count = mlxsw_afk_key_info_blocks_count_get(key_info);
243259
chunk_count = 1 + ((block_count - 1) >> 2);
244260
erp_region_id = cpu_to_be16(aentry->ht_key.erp_id |
245261
(aregion->region->id << 4));
246262
for (chunk_index = max_chunks - chunk_count; chunk_index < max_chunks;
247263
chunk_index++) {
264+
char *enc_key;
265+
248266
memset(chunk, 0, pad_bytes);
249267
memcpy(chunk + pad_bytes, &erp_region_id,
250268
sizeof(erp_region_id));
251-
memcpy(chunk + key_offset,
252-
&aentry->ht_key.enc_key[chunk_key_offsets[chunk_index]],
253-
chunk_key_len);
269+
enc_key = mlxsw_sp_acl_bf_enc_key_get(aentry, chunk_index);
270+
memcpy(chunk + key_offset, enc_key, chunk_key_len);
254271
chunk += chunk_len;
255272
}
256273
*len = chunk_count * chunk_len;

0 commit comments

Comments
 (0)