Re: [RFC PATCH net-next 1/7] net: ethtool: netlink: introduce ethnl_update_bool()

Michal Kubecek
2022-08-17T12:06:13Z

[-- Attachment #1: Type: text/plain, Size: 1632 bytes --]

On Wed, Aug 17, 2022 at 12:00:37PM +0000, Vladimir Oltean wrote:
> On Wed, Aug 17, 2022 at 02:52:56PM +0300, Vladimir Oltean wrote:
> > On Wed, Aug 17, 2022 at 01:27:29PM +0200, Michal Kubecek wrote:
> > > On Wed, Aug 17, 2022 at 01:29:14AM +0300, Vladimir Oltean wrote:
> > > > For a reason I can't really understand, ethnl_update_bool32() exists,
> > > > but the plain function that operates on a boolean value kept in an
> > > > actual u8 netlink attribute doesn't.
> > >
> > > I can explain that: at the moment these helpers were introduced, only
> > > members of traditional structures shared with ioctl interface were
> > > updated and all attributes which were booleans logically were
> > > represented as u32 in them so that no other helper was needed back then.
> >
> > Thanks, but the internal data structures of the kernel did not
> > necessitate boolean netlink attributes to be promoted to u32 just
> > because the ioctl interface did it that way; or did they?
> >
> > Or otherwise said, is there a technical requirement that if a boolean is
> > passed to the kernel as u32 via ioctl, it should be passed as u32 via
> > netlink too?
>
> Ah, don't mind me... By the time I wrote this email, I forgot that
> ethnl_update_bool32() also calls nla_get_u8(). All clear now.

Yes, it expects a NLA_U8 attribute. But it does not really matter that
much as even NLA_U8 still occupies 4 bytes in the message because of the
padding. (Which is why I generally prefer using NLA_U32 attributes
unless the value is naturally 8- or 16-bit and we are absolutely sure we
will never need more.)

Michal

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]