lkml.org 
[lkml]   [2019]   [Dec]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH net-next v8 02/14] ethtool: helper functions for netlink interface
From
Date


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@suse.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.

> +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.
--
Florian

\
 
 \ /
  Last update: 2019-12-24 05:09    [W:0.223 / U:0.424 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site