[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20191225110726.GJ21614@unicorn.suse.cz>
Date: Wed, 25 Dec 2019 12:07:26 +0100
From: Michal Kubecek <mkubecek@...e.cz>
To: netdev@...r.kernel.org
Cc: Florian Fainelli <f.fainelli@...il.com>,
David Miller <davem@...emloft.net>,
Jakub Kicinski <jakub.kicinski@...ronome.com>,
Jiri Pirko <jiri@...nulli.us>, Andrew Lunn <andrew@...n.ch>,
John Linville <linville@...driver.com>,
Stephen Hemminger <stephen@...workplumber.org>,
Johannes Berg <johannes@...solutions.net>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next v8 02/14] ethtool: helper functions for netlink
interface
On Mon, Dec 23, 2019 at 08:08:55PM -0800, Florian Fainelli wrote:
>
>
> On 12/22/2019 3:45 PM, Michal Kubecek wrote:
> > Add common request/reply header definition and helpers to parse request
> > header and fill reply header. Provide ethnl_update_* helpers to update
> > structure members from request attributes (to be used for *_SET requests).
> >
> > Signed-off-by: Michal Kubecek <mkubecek@...e.cz>
> > ---
>
> [snip]
>
> > +/**
> > + * ethnl_update_u32() - update u32 value from NLA_U32 attribute
> > + * @dst: value to update
> > + * @attr: netlink attribute with new value or null
> > + * @mod: pointer to bool for modification tracking
> > + *
> > + * Copy the u32 value from NLA_U32 netlink attribute @attr into variable
> > + * pointed to by @dst; do nothing if @attr is null. Bool pointed to by @mod
> > + * is set to true if this function changed the value of *dst, otherwise it
> > + * is left as is.
> > + */
>
> I would find it more intuitive if an integer was returned: < 0 in case
> of error, 0 if no change and 1 if something changed.
This trick allows simpler code on caller side when we update multiple
values in a structure - we don't have to check each return value
separately (most update helpers cannot fail). It was a suggestion from
Jiri Pirko in one of earlier discussions.
> > +static inline void ethnl_update_u32(u32 *dst, const struct nlattr *attr,
> > + bool *mod)
> > +{
> > + u32 val;
> > +
> > + if (!attr)
> > + return;
> > + val = nla_get_u32(attr);
> > + if (*dst == val)
> > + return;
> > +
> > + *dst = val;
> > + *mod = true;
> > +}
> > +
> > +/**
> > + * ethnl_update_u8() - update u8 value from NLA_U8 attribute
> > + * @dst: value to update
> > + * @attr: netlink attribute with new value or null
> > + * @mod: pointer to bool for modification tracking
> > + *
> > + * Copy the u8 value from NLA_U8 netlink attribute @attr into variable
> > + * pointed to by @dst; do nothing if @attr is null. Bool pointed to by @mod
> > + * is set to true if this function changed the value of *dst, otherwise it
> > + * is left as is.
> > + */
> > +static inline void ethnl_update_u8(u8 *dst, const struct nlattr *attr,
> > + bool *mod)
> > +{
> > + u8 val;
> > +
> > + if (!attr)
> > + return;
> > + val = nla_get_u32(attr);
>
> Should not this be nla_get_u8() here? This sounds like it is going to
> break on BE machines.
Good catch, thank you. I originally wanted to use NLA_U32 for all
numeric values (as NLA_U8 and NLA_U16 don't save any space anyway) but
then changed those in LINKINFO_GET request to NLA_U8 and forgot to fix
the helper function.
I'll fix this in v9.
Michal
Powered by blists - more mailing lists