All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
To: Or Gerlitz <gerlitz.or-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Bart Van Assche
	<bart.vanassche-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>,
	Saeed Mahameed <saeedm-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
	Eli Cohen <eli-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
	"linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Matan Barak <matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Subject: Re: [PATCH 3/5] mlx5: Avoid that sparse complains about dubious !x & y expressions
Date: Thu, 8 Dec 2016 10:53:22 -0700	[thread overview]
Message-ID: <20161208175322.GB11025@obsidianresearch.com> (raw)
In-Reply-To: <CAJ3xEMjPZYgLhDi_6Jxkx_dg_RaehD=3SchMt_noLzQEChPrxQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

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

  parent reply	other threads:[~2016-12-08 17:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06  1:17 [PATCH 0/5] mlx5 patches for kernel v4.10 Bart Van Assche
     [not found] ` <9ff07804-492c-c67a-e729-b31e0f863027-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-12-06  1:18   ` [PATCH 1/5] mlx5: Use NULL instead of 0 to represent a pointer Bart Van Assche
     [not found]     ` <16dc2a07-86f7-ce47-7b0c-1da03e58d99f-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-12-06 13:59       ` Leon Romanovsky
     [not found]         ` <20161206135917.GC2437-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2016-12-06 16:28           ` Jason Gunthorpe
2016-12-06 16:29           ` Bart Van Assche
     [not found]             ` <a8d3dbb7-aafa-c5af-5d06-78d1f4914c5d-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-12-07  8:21               ` Leon Romanovsky
     [not found]                 ` <20161207082110.GA11857-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2016-12-14 18:44                   ` Doug Ledford
2016-12-06  1:18   ` [PATCH 2/5] mlx5: Remove a set-but-not-used variable Bart Van Assche
     [not found]     ` <f1351e2c-915d-9883-838b-d3c50f27da17-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-12-06 14:24       ` Leon Romanovsky
     [not found]         ` <20161206142441.GA3437-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2016-12-14 18:45           ` Doug Ledford
2016-12-06  1:19   ` [PATCH 3/5] mlx5: Avoid that sparse complains about dubious !x & y expressions Bart Van Assche
     [not found]     ` <572c702f-589f-2d5a-9e13-45223191db85-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-12-08  9:26       ` Or Gerlitz
     [not found]         ` <CAJ3xEMjPZYgLhDi_6Jxkx_dg_RaehD=3SchMt_noLzQEChPrxQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-12-08 17:52           ` Bart Van Assche
2016-12-08 17:53           ` Jason Gunthorpe [this message]
     [not found]             ` <20161208175322.GB11025-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-12-14 18:46               ` Doug Ledford
2016-12-06  1:19   ` [PATCH 4/5] mlx5: Fix mlx5_srq_attr.pas endianness annotation Bart Van Assche
     [not found]     ` <3d4f5ffa-e9bf-cd28-d200-74c5dd3d68ce-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-12-06 13:55       ` Leon Romanovsky
2016-12-06  1:19   ` [PATCH 5/5] mlx5, calc_sq_size(): Make a debug message more informative Bart Van Assche
     [not found]     ` <4387aa0f-5097-d456-eee2-b480dfa5af87-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-12-06 14:31       ` Leon Romanovsky
     [not found]         ` <20161206143159.GB3437-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2016-12-14 18:46           ` Doug Ledford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161208175322.GB11025@obsidianresearch.com \
    --to=jgunthorpe-epgobjl8dl3ta4ec/59zmfatqe2ktcn/@public.gmane.org \
    --cc=bart.vanassche-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org \
    --cc=eli-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=gerlitz.or-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=saeedm-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.