linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Desaulniers <ndesaulniers@google.com>
To: Pi-Hsun Shih <pihsun@chromium.org>
Cc: Joe Perches <joe@perches.com>,
	linux-wireless@vger.kernel.org,
	Johannes Berg <johannes@sipsolutions.net>,
	open list <linux-kernel@vger.kernel.org>,
	"open list:CLANG/LLVM BUILD SUPPORT" 
	<clang-built-linux@googlegroups.com>
Subject: Re: [PATCH RESEND] wireless: Use offsetof instead of custom macro.
Date: Mon, 2 Dec 2019 09:27:35 -0800	[thread overview]
Message-ID: <CAKwvOd=g36hxdU-pspCf78JhLTtxTk2dvStR3SQLhTPeCrELVQ@mail.gmail.com> (raw)
In-Reply-To: <CANdKZ0eYSdPC2y5QxN1B7FshewXumrETQohbXrnvbovXMkSe9Q@mail.gmail.com>

On Thu, Nov 28, 2019 at 8:05 PM Pi-Hsun Shih <pihsun@chromium.org> wrote:
>
> On Thu, Nov 28, 2019 at 11:54 AM Joe Perches <joe@perches.com> wrote:
> >
> > On Thu, 2019-11-28 at 11:39 +0800, Pi-Hsun Shih wrote:
> > > Use offsetof to calculate offset of a field to take advantage of
> > > compiler built-in version when possible, and avoid UBSAN warning when
> > > compiling with Clang:
> > []
> > > diff --git a/include/uapi/linux/wireless.h b/include/uapi/linux/wireless.h
> > []
> > > @@ -1090,8 +1090,7 @@ struct iw_event {
> > >  /* iw_point events are special. First, the payload (extra data) come at
> > >   * the end of the event, so they are bigger than IW_EV_POINT_LEN. Second,
> > >   * we omit the pointer, so start at an offset. */
> > > -#define IW_EV_POINT_OFF (((char *) &(((struct iw_point *) NULL)->length)) - \
> > > -                       (char *) NULL)
> > > +#define IW_EV_POINT_OFF offsetof(struct iw_point, length)
> > >  #define IW_EV_POINT_LEN      (IW_EV_LCP_LEN + sizeof(struct iw_point) - \
> > >                        IW_EV_POINT_OFF)
> >
> > This is uapi.  Is offsetof guaranteed to be available?
>
> offsetof is already used in other uapi headers
> (include/uapi/linux/fuse.h FUSE_NAME_OFFSET).
>
> Also offsetof is also defined back in C89 standard (in stddef.h), so
> it should be widely available and should be fine to use here?
> (Should I add a #ifndef __KERNEL__ #include <stddef.h> to the file?)

Yes, please, otherwise userspace could have a
-Wimplicit-function-definition warning from including this header,
since it would look like a function call to a previously undeclared
function.

Actually, it looks like include/uapi/linux/posix_types.h includes it
unconditionally, and many other headers under include/uapi/ include
include/uapi/linux/posix_types.h (unconditionally).  So it may be ok
to just include stddef.h unconditionally, but please do so in addition
to the current diff you have.

-- 
Thanks,
~Nick Desaulniers

      reply	other threads:[~2019-12-02 17:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-28  3:39 [PATCH RESEND] wireless: Use offsetof instead of custom macro Pi-Hsun Shih
2019-11-28  3:53 ` Joe Perches
2019-11-29  4:04   ` Pi-Hsun Shih
2019-12-02 17:27     ` Nick Desaulniers [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='CAKwvOd=g36hxdU-pspCf78JhLTtxTk2dvStR3SQLhTPeCrELVQ@mail.gmail.com' \
    --to=ndesaulniers@google.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=joe@perches.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=pihsun@chromium.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).