Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp759169ybi; Wed, 3 Jul 2019 04:15:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwP8B/1ach9XtvdFviICbDmfHCDRWtba6tbs/Hh6gjzA+RIpuQAhI59llq+crsfvb8xB6qA X-Received: by 2002:a17:902:28e9:: with SMTP id f96mr40017550plb.114.1562152545662; Wed, 03 Jul 2019 04:15:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562152545; cv=none; d=google.com; s=arc-20160816; b=r5iRjrZBvyqNGRY70eFmmeatwQcimtMeGP9UMmVW9/4l6Lzwcm0aVpDX700YdY7223 Agq57VX3fcG+MZVZG20f7GwBWtqlf/6CAtidKlNi7826vtTPGybtGBVHcx3UMYyNQ39V nS0neKfYmfqM4p5+eoktdWE3SgQIFAPl+lyKzgH9CuvSmCyezatQO/Vcxk+a2lMVaiYB 1nfb3fIu/l47mzdf/BYMHGgVZZKXLZ07zxog7g66ANPtPYrWmSxDbPEtxBYQskKd2SmM oLj2cnayfNPuRW8/vMvbLQL7hN8vX4CqnSjGNSGR/jMn1ufnOaeqS/V/ci/4iRbKJ2Fj HGLw== 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=L5r4P6BrPVMWeSoVRt1QhxJK1hjDtkIyRiiNX354FBI=; b=aWOwKCN8sSEv4u1NlOaKYDTecdxyowZd0D51MzkEyWPmtVyHpv0Q7137vH4ni3pvsl 8BKZ6DsihKBr8M8/0BoWkVaI+0lJ7m2/IQmIj/CCx20fU16sBTO1BUf2yd1O5x0RHXk8 AlLI036R+1v3j0d5qC2M9M3/6SG1DqRFfFISYNHHTsojzlXJTv6JVO8EFiZbn+HtQr0Q PAnJquRfojk7LodMnmdVT2JM7CS0foxQPjNYOkdwarnS7nZ27W5yUOLEVJjfKLCpTrWO 47K04pXwPz60QhiOhUfGKnhoJAmPBm1KrGcTBTiHcu8Vr3hhZpa3tJZF3CkcpI1eeM5L hGvQ== 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 x23si2014503plm.308.2019.07.03.04.15.29; Wed, 03 Jul 2019 04:15:45 -0700 (PDT) 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 S1727056AbfGCLNx (ORCPT + 99 others); Wed, 3 Jul 2019 07:13:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:55660 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726486AbfGCLNx (ORCPT ); Wed, 3 Jul 2019 07:13:53 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 080F8AD89; Wed, 3 Jul 2019 11:13:50 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 2C95EE0159; Wed, 3 Jul 2019 13:13:47 +0200 (CEST) Date: Wed, 3 Jul 2019 13:13:47 +0200 From: Michal Kubecek To: netdev@vger.kernel.org Cc: Jiri Pirko , David Miller , Jakub Kicinski , Andrew Lunn , Florian Fainelli , John Linville , Stephen Hemminger , Johannes Berg , linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v6 05/15] ethtool: helper functions for netlink interface Message-ID: <20190703111347.GK20101@unicorn.suse.cz> References: <44957b13e8edbced71aca893908d184eb9e57341.1562067622.git.mkubecek@suse.cz> <20190702130515.GO2250@nanopsycho> <20190702163437.GE20101@unicorn.suse.cz> <20190703100435.GS2250@nanopsycho> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190703100435.GS2250@nanopsycho> 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 Wed, Jul 03, 2019 at 12:04:35PM +0200, Jiri Pirko wrote: > Tue, Jul 02, 2019 at 06:34:37PM CEST, mkubecek@suse.cz wrote: > >On Tue, Jul 02, 2019 at 03:05:15PM +0200, Jiri Pirko wrote: > >> Tue, Jul 02, 2019 at 01:50:04PM CEST, mkubecek@suse.cz wrote: > >> >+ > >> >+ req_info->dev = dev; > >> >+ ethnl_update_u32(&req_info->req_mask, tb[ETHTOOL_A_HEADER_INFOMASK]); > >> >+ ethnl_update_u32(&req_info->global_flags, tb[ETHTOOL_A_HEADER_GFLAGS]); > >> >+ ethnl_update_u32(&req_info->req_flags, tb[ETHTOOL_A_HEADER_RFLAGS]); > >> > >> Just: > >> req_info->req_mask = nla_get_u32(tb[ETHTOOL_A_HEADER_INFOMASK]; > >> ... > >> > >> Not sure what ethnl_update_u32() is good for, but it is not needed here. > > > >That would result in null pointer dereference if the attribute is > >missing. So you would need at least > > > > if (tb[ETHTOOL_A_HEADER_INFOMASK]) > > req_info->req_mask = nla_get_u32(tb[ETHTOOL_A_HEADER_INFOMASK]); > > if (tb[ETHTOOL_A_HEADER_GFLAGS]) > > req_info->global_flags = > > nla_get_u32(tb[ETHTOOL_A_HEADER_GFLAGS]); > > if (tb[ETHTOOL_A_HEADER_RFLAGS]) > > req_info->req_flags = nla_get_u32(tb[ETHTOOL_A_HEADER_RFLAGS]); > > Yeah, sure. > > > > >I don't think it looks better. > > Better than hiding something inside a helper in my opinion - helper that > is there for different reason moreover. Much easier to read the code > and follow. OK, I'll use nla_get_u32() directly here. With the change below, use of ethnl_update_u32() would really look unnatural. > >> >+/* The ethnl_update_* helpers set value pointed to by @dst to the value of > >> >+ * netlink attribute @attr (if attr is not null). They return true if *dst > >> >+ * value was changed, false if not. > >> >+ */ > >> >+static inline bool ethnl_update_u32(u32 *dst, struct nlattr *attr) > >> > >> I'm still not sure I'm convinced about these "update helpers" :) > > > >Just imagine what would e.g. > > > > if (ethnl_update_u32(&data.rx_pending, tb[ETHTOOL_A_RING_RX_PENDING])) > > mod = true; > > if (ethnl_update_u32(&data.rx_mini_pending, > > tb[ETHTOOL_A_RING_RX_MINI_PENDING])) > > mod = true; > > if (ethnl_update_u32(&data.rx_jumbo_pending, > > tb[ETHTOOL_A_RING_RX_JUMBO_PENDING])) > > mod = true; > > if (ethnl_update_u32(&data.tx_pending, tb[ETHTOOL_A_RING_TX_PENDING])) > > mod = true; > > if (!mod) > > return 0; > > > >look like without them. And coalescing parameters would be much worse > >(22 attributes / struct members). > > No, I understand your motivation, don't get me wrong. I just wonder that > no other netlink implementation need such mechanism. Maybe I'm not > looking close enough. But if it does, should be rathe netlink helper. I'll check some existing interfaces to see how they handle "set" type requests. > Regarding the example code you have here. It is prefered to store > function result in a variable "if check" that variable. But in your, > code, couldn't this be done without ifs? > > bool mod = false; > > ethnl_update_u32(&mod, &data.rx_pending, tb[ETHTOOL_A_RING_RX_PENDING])) > ethnl_update_u32(&mod, &data.rx_mini_pending, > tb[ETHTOOL_A_RING_RX_MINI_PENDING])) > ethnl_update_u32(&mod, &data.rx_jumbo_pending, > tb[ETHTOOL_A_RING_RX_JUMBO_PENDING])) > ethnl_update_u32(&mod, &data.tx_pending, tb[ETHTOOL_A_RING_TX_PENDING])) > > if (!mod) > return 0; Ah, right. Somehow I completely missed the possibility that update helper can use "set of leave as it is" logic instead of "set to true or false". Thanks, I'll rewrite the update helpers to this style. Michal