diff mbox

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

Message ID CAJ3xEMjPZYgLhDi_6Jxkx_dg_RaehD=3SchMt_noLzQEChPrxQ@mail.gmail.com (mailing list archive)
State Awaiting Upstream
Headers show

Commit Message

Or Gerlitz Dec. 8, 2016, 9:26 a.m. UTC
On Tue, Dec 6, 2016 at 3:19 AM, Bart Van Assche
<bart.vanassche@sandisk.com> wrote:
> This patch does not change any functionality.

Hi Bart,

Matan came up with a fix (below) which solves all these sparse
complaints in both drivers (mlx5 IB and core)
while basically not touching the code, we will be going with that fix
to 4.11, thanks, I will add reported
by pointing to you.

Doug, in case you picked that, I guess you have to drop it.

Or.

iff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h
index 9f48936..0abdc66 100644
 } while (0)
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Bart Van Assche Dec. 8, 2016, 5:52 p.m. UTC | #1
On 12/08/2016 01:26 AM, Or Gerlitz wrote:
> Matan came up with a fix (below) which solves all these sparse
> complaints in both drivers (mlx5 IB and core)
> while basically not touching the code, we will be going with that fix
> to 4.11, thanks, I will add reported
> by pointing to you.

Hello Or,

Please consider to keep the following change:

-	MLX5_SET(mkc, mkc, en_rinval, !!((type == IB_MW_TYPE_2)));
+	MLX5_SET(mkc, mkc, en_rinval, type == IB_MW_TYPE_2);

I don't think that specifying two boolean not (!) operators in front of 
a boolean expression is useful :-)

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jason Gunthorpe Dec. 8, 2016, 5:53 p.m. UTC | #2
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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Doug Ledford Dec. 14, 2016, 6:46 p.m. UTC | #3
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@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

Patch

--- a/include/linux/mlx5/device.h
+++ b/include/linux/mlx5/device.h
@@ -67,10 +67,11 @@ 

 /* 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))); \