Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8635748ybl; Wed, 25 Dec 2019 03:09:16 -0800 (PST) X-Google-Smtp-Source: APXvYqzLQ98baEIoYApJvRrA6HEjLKQGC3n5dlphrEpVV4QP87oxM2Hiu2eR42YGp+dJmkT83iyd X-Received: by 2002:a9d:5c8a:: with SMTP id a10mr11845091oti.95.1577272156516; Wed, 25 Dec 2019 03:09:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577272156; cv=none; d=google.com; s=arc-20160816; b=sySUIlDw6jBoXYj7+yBkosLxOUdkEDQJx8NcxJVc2m0E3oUKG0XgdJgwTsclXnmGye 4/vhMdKz2YLAatQabiDIFPfI6A0NfTmCxxm1uI8U8Zyy8KG74MlIYwDXh0fpy2LPceJo me84k8/JkdSQYsHRNizCV1RsqHuTmSY7BpGOLOS77XlyUgXTM5Is8zChA0XJiRLtJRgw 97HpEULTlgEK59ZRXJ7KliVVUEWlOKfF1fq62fJ4Jrwbr+CoKFbAbv09/iKua8mtfqG7 v5zD1V8s6AFTONPUEzCDLbf3f1TqbJo9+qbLk0Kx7HHtBbqwXbQ7m65oTv454IEAHzpD Yepw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=n5qiCXIY14IKQpD1LfYci+wcStsDnOthLLfDP3nQ71E=; b=gnc99P0u6euGZwJuDIXg4sKPcpxY65ZuNvXMKXkGMqPB3v+x8ExSx3schiBPgEsftw /R9w9DaMT9/Jg6M9crAsJSnH1UThR282ja1rNy+NxX/zDwLQE78DuJEh7sQp9vH5n9De 0v4/ds24LxpgWSVNt50DJNRuO5E9xC+gOf+s4VO9fyerAuxxU/3yj1IgsHejQ01/WmX9 9Uy2V7GYrrk4xkGxeuJ87PsjlrW8vIa4y+c9ycFgnlaRDKCbAq5/XHIDT0P3VmwTNxAi hsrEjY+QTNP3kBiOECWVR/sFW0Xw4aRbpBXzDOoW6NffY8PJSknlagz5HJq62N6p4KjY HVkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z24si6371788otm.101.2019.12.25.03.09.05; Wed, 25 Dec 2019 03:09:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727049AbfLYLHp (ORCPT + 99 others); Wed, 25 Dec 2019 06:07:45 -0500 Received: from mx2.suse.de ([195.135.220.15]:60808 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbfLYLHb (ORCPT ); Wed, 25 Dec 2019 06:07:31 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4B01AB269; Wed, 25 Dec 2019 11:07:29 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 3FE15E008B; Wed, 25 Dec 2019 12:07:26 +0100 (CET) Date: Wed, 25 Dec 2019 12:07:26 +0100 From: Michal Kubecek To: netdev@vger.kernel.org Cc: Florian Fainelli , David Miller , Jakub Kicinski , Jiri Pirko , Andrew Lunn , John Linville , Stephen Hemminger , Johannes Berg , linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v8 02/14] ethtool: helper functions for netlink interface Message-ID: <20191225110726.GJ21614@unicorn.suse.cz> References: <8cbb9c250caf021f600032ad4aa32c44adf0b8e9.1577052887.git.mkubecek@suse.cz> <921763be-9f8d-5f2d-18a3-400c9ac98797@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <921763be-9f8d-5f2d-18a3-400c9ac98797@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > --- > > [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