Re: [PATCH 3/5] mlx5: Avoid that sparse complains about dubious !x & y expressions

Doug Ledford
2016-12-14T18:46:12Z

[-- Attachment #1.1: Type: text/plain, Size: 1673 bytes --]

On 12/8/2016 12:53 PM, Jason Gunthorpe wrote:
> On Thu, Dec 08, 2016 at 11:26:32AM +0200, Or Gerlitz wrote:
>> /* insert a value to a struct */
>> #define MLX5_SET(typ, p, fld, v) do { \
>> + typeof( v ) _v = v; \
>> BUILD_BUG_ON(__mlx5_st_sz_bits(typ) % 32); \
>> *((__be32 *)(p) + __mlx5_dw_off(typ, fld)) = \
>> cpu_to_be32((be32_to_cpu(*((__be32 *)(p) + __mlx5_dw_off(typ, fld))) & \
>> - (~__mlx5_dw_mask(typ, fld))) | (((v) &
>> __mlx5_mask(typ, fld)) \
>> + (~__mlx5_dw_mask(typ, fld))) | (((_v) &
>> __mlx5_mask(typ, fld)) \
>> << __mlx5_dw_bit_off(typ, fld))); \
>> } while (0)
>
> Ugh, that is ugly.
>
> This is better, it has proper type safety :|
>
> static inline _mlx5_set(__be32 *p, u32 dw_mask,
> u32 mask, u32 dw_off,
> unsigned int bit_off, u32 val)
> {
> *(p + dw_off) = cpu_to_b32((be32_to_cpu_p(p + dw_off) &
> ~dw_mask) | ((val & mask) << bit_off));
> }
>
> #define MLX5_SET(typ, p, fld, v) \
> _mlx5_set(p, __mlx5_dw_mask(typ, fld),
> __mlx5_mask(typ, fld),
> __mlx5_dw_off(typ, fld),
> __mlx5_dw_bit_off(typ, fld), v)
>
> Jason
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

Dropped this patch and will wait for fixed up version from Mellanox.

--
Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
GPG Key ID: 0E572FDD

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 884 bytes --]