Skip to content

Commit

Permalink
RDMA/hns: Prevent le32 from being implicitly converted to u32
Browse files Browse the repository at this point in the history
Replace BUILD_BUG_ON_ZERO() with BUILD_BUG_ON() to avoid sparse
complaining "restricted __le32 degrades to integer".

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Lang Cheng <[email protected]>
Signed-off-by: Weihang Li <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
  • Loading branch information
larrch authored and jgunthorpe committed Apr 8, 2021
1 parent 782832f commit 69455df
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions drivers/infiniband/hw/hns/hns_roce_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
#define roce_set_field(origin, mask, shift, val) \
do { \
(origin) &= ~cpu_to_le32(mask); \
(origin) |= cpu_to_le32(((u32)(val) << (u32)(shift)) & (mask)); \
(origin) |= \
cpu_to_le32(((u32)(val) << (u32)(shift)) & (mask)); \
} while (0)

#define roce_set_bit(origin, shift, val) \
Expand All @@ -59,21 +60,19 @@
#define _hr_reg_enable(ptr, field_type, field_h, field_l) \
({ \
const field_type *_ptr = ptr; \
*((__le32 *)_ptr + (field_h) / 32) |= \
cpu_to_le32(BIT((field_l) % 32)) + \
BUILD_BUG_ON_ZERO((field_h) != (field_l)); \
*((__le32 *)_ptr + (field_h) / 32) |= cpu_to_le32( \
BIT((field_l) % 32) + \
BUILD_BUG_ON_ZERO((field_h) != (field_l))); \
})

#define hr_reg_enable(ptr, field) _hr_reg_enable(ptr, field)

#define _hr_reg_clear(ptr, field_type, field_h, field_l) \
({ \
const field_type *_ptr = ptr; \
BUILD_BUG_ON(((field_h) / 32) != ((field_l) / 32)); \
*((__le32 *)_ptr + (field_h) / 32) &= \
cpu_to_le32( \
~GENMASK((field_h) % 32, (field_l) % 32)) + \
BUILD_BUG_ON_ZERO(((field_h) / 32) != \
((field_l) / 32)); \
~cpu_to_le32(GENMASK((field_h) % 32, (field_l) % 32)); \
})

#define hr_reg_clear(ptr, field) _hr_reg_clear(ptr, field)
Expand Down

0 comments on commit 69455df

Please sign in to comment.