RE: [PATCH net-next 2/2] net: socket: change MSG_CMSG_COMPAT to BIT(21)

From: David Laight
Date: Mon Mar 22 2021 - 04:58:59 EST


From: Herbert Xu
> Sent: 21 March 2021 12:49
>
> On Sun, Mar 21, 2021 at 08:39:29PM +0800, menglong8.dong@xxxxxxxxx wrote:
> >
> > diff --git a/include/linux/socket.h b/include/linux/socket.h
> > index d5ebfe30d96b..317b2933f499 100644
> > --- a/include/linux/socket.h
> > +++ b/include/linux/socket.h
> > @@ -312,17 +312,18 @@ struct ucred {
> > * plain text and require encryption
> > */
> >
> > +#if defined(CONFIG_COMPAT)
> > +#define MSG_CMSG_COMPAT BIT(21) /* This message needs 32 bit fixups */
> > +#else
> > +#define MSG_CMSG_COMPAT 0 /* We never have 32 bit fixups */
> > +#endif
> > +
> > #define MSG_ZEROCOPY BIT(26) /* Use user data in kernel path */
> > #define MSG_FASTOPEN BIT(29) /* Send data in TCP SYN */
> > #define MSG_CMSG_CLOEXEC BIT(30) /* Set close_on_exec for file
> > * descriptor received through
> > * SCM_RIGHTS
> > */
> > -#if defined(CONFIG_COMPAT)
> > -#define MSG_CMSG_COMPAT BIT(31) /* This message needs 32 bit fixups */
> > -#else
> > -#define MSG_CMSG_COMPAT 0 /* We never have 32 bit fixups */
> > -#endif
>
> Shouldn't you add some comment here to stop people from trying to
> use BIT(31) in the future?

You'd also be better using BIT(30) - ie the other end of the
free space from the user-visible bits.

It has to be said that the entire impossibility of writing BIT(n)
safely almost makes it worse that just defining appropriate constants.

Personally I like the hex constants.
The make it much easier to work out which bits are set in a diagnostic
print (or memory hexdump).

The only time I've really found BIT() type macros useful is when
defining values that have to match hardware specs that define bit
numbers backwards starting from 1.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)