From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Doug Ledford <dledford@redhat.com>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: Re: [PATCH] IB/core: Use sizeof_field() helper
Date: Wed, 27 May 2020 12:04:47 -0500 [thread overview]
Message-ID: <20200527170447.GA18738@embeddedor> (raw)
In-Reply-To: <20200527164452.GQ744@ziepe.ca>
On Wed, May 27, 2020 at 01:44:52PM -0300, Jason Gunthorpe wrote:
> On Wed, May 27, 2020 at 09:41:52AM -0500, Gustavo A. R. Silva wrote:
> > Make use of the sizeof_field() helper instead of an open-coded version.
> >
> > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> > ---
> > drivers/infiniband/core/sa_query.c | 8 ++++----
> > drivers/infiniband/core/uverbs_cmd.c | 2 +-
> > drivers/infiniband/core/uverbs_ioctl.c | 2 +-
> > 3 files changed, 6 insertions(+), 6 deletions(-)
>
> What kind of tool are you using for this? It seems to miss a lot, I
> added in a few others to this patch and applied it, thanks:
>
Hi Jason,
I was just doing a "terrain recognition" with grep. I certainly
wasn't expecting spaces between the sizeof operator and the opening
parenthesis: "sizeof ((struct ib_sa_mcmember_rec *) 0)->field".
Also, I was just running grep in drivers/infiniband/
I'll run a cocci script next time...
Thanks for your feedback. :)
--
Gustavo
> diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
> index 8f70c5c38ab7c3..a2ed09a3c714a9 100644
> --- a/drivers/infiniband/core/sa_query.c
> +++ b/drivers/infiniband/core/sa_query.c
> @@ -420,7 +420,7 @@ static const struct ib_field opa_path_rec_table[] = {
>
> #define MCMEMBER_REC_FIELD(field) \
> .struct_offset_bytes = offsetof(struct ib_sa_mcmember_rec, field), \
> - .struct_size_bytes = sizeof ((struct ib_sa_mcmember_rec *) 0)->field, \
> + .struct_size_bytes = sizeof_field(struct ib_sa_mcmember_rec, field), \
> .field_name = "sa_mcmember_rec:" #field
>
> static const struct ib_field mcmember_rec_table[] = {
> @@ -504,7 +504,7 @@ static const struct ib_field mcmember_rec_table[] = {
>
> #define SERVICE_REC_FIELD(field) \
> .struct_offset_bytes = offsetof(struct ib_sa_service_rec, field), \
> - .struct_size_bytes = sizeof ((struct ib_sa_service_rec *) 0)->field, \
> + .struct_size_bytes = sizeof_field(struct ib_sa_service_rec, field), \
> .field_name = "sa_service_rec:" #field
>
> static const struct ib_field service_rec_table[] = {
> @@ -710,7 +710,7 @@ static const struct ib_field opa_classport_info_rec_table[] = {
>
> #define GUIDINFO_REC_FIELD(field) \
> .struct_offset_bytes = offsetof(struct ib_sa_guidinfo_rec, field), \
> - .struct_size_bytes = sizeof((struct ib_sa_guidinfo_rec *) 0)->field, \
> + .struct_size_bytes = sizeof_field(struct ib_sa_guidinfo_rec, field), \
> .field_name = "sa_guidinfo_rec:" #field
>
> static const struct ib_field guidinfo_rec_table[] = {
> diff --git a/drivers/infiniband/core/ud_header.c b/drivers/infiniband/core/ud_header.c
> index 29a45d2f8898e1..d65d541b9a2587 100644
> --- a/drivers/infiniband/core/ud_header.c
> +++ b/drivers/infiniband/core/ud_header.c
> @@ -41,7 +41,7 @@
>
> #define STRUCT_FIELD(header, field) \
> .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \
> - .struct_size_bytes = sizeof ((struct ib_unpacked_ ## header *) 0)->field, \
> + .struct_size_bytes = sizeof_field(struct ib_unpacked_ ## header, field), \
> .field_name = #header ":" #field
>
> static const struct ib_field lrh_table[] = {
> diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h
> index 5bd2b037e9147c..0418d7bddf3e0c 100644
> --- a/include/rdma/uverbs_ioctl.h
> +++ b/include/rdma/uverbs_ioctl.h
> @@ -420,9 +420,9 @@ struct uapi_definition {
> .scope = UAPI_SCOPE_OBJECT, \
> .needs_fn_offset = \
> offsetof(struct ib_device_ops, ibdev_fn) + \
> - BUILD_BUG_ON_ZERO( \
> - sizeof(((struct ib_device_ops *)0)->ibdev_fn) != \
> - sizeof(void *)), \
> + BUILD_BUG_ON_ZERO(sizeof_field(struct ib_device_ops, \
> + ibdev_fn) != \
> + sizeof(void *)), \
> }
>
> /*
> @@ -435,9 +435,9 @@ struct uapi_definition {
> .scope = UAPI_SCOPE_METHOD, \
> .needs_fn_offset = \
> offsetof(struct ib_device_ops, ibdev_fn) + \
> - BUILD_BUG_ON_ZERO( \
> - sizeof(((struct ib_device_ops *)0)->ibdev_fn) != \
> - sizeof(void *)), \
> + BUILD_BUG_ON_ZERO(sizeof_field(struct ib_device_ops, \
> + ibdev_fn) != \
> + sizeof(void *)), \
> }
>
> /* Call a function to determine if the entire object is supported or not */
prev parent reply other threads:[~2020-05-27 16:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-27 14:41 [PATCH] IB/core: Use sizeof_field() helper Gustavo A. R. Silva
2020-05-27 16:44 ` Jason Gunthorpe
2020-05-27 17:04 ` Gustavo A. R. Silva [this message]
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=20200527170447.GA18738@embeddedor \
--to=gustavoars@kernel.org \
--cc=dledford@redhat.com \
--cc=gustavo@embeddedor.com \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).