Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp973372ybi; Wed, 3 Jul 2019 07:26:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyn61YQ+JM67lY4RUbt3de6UmwxKPBUufpYTTpJlbyNQy5D+ME8oU6TO67CxyhGvX8OA2TN X-Received: by 2002:a17:902:7043:: with SMTP id h3mr44383380plt.10.1562163970689; Wed, 03 Jul 2019 07:26:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562163970; cv=none; d=google.com; s=arc-20160816; b=WWKvoLj9DxgB9guxlZCSlqEaavWETfP70MO+8RnPpk171dIudYXIqCMyRcTnrMN4So QpLgmbP8iKZqjILwu0J+pYGd2M+2McmbL2/atAW2tyV++1JXL0xsp4QC62sI5fhQECeA odpKu2T5DRkqz20tm1liOjus6Din6v2tGYvzcKFdkLFOzWNSTfi+5mcOR09QCC96wUGw +KjfRZBT2qA1dvnqnu8k2ctaqe+ZJssC3paE/oBW0aQppXIJXgbBvRZYRn9cXEcAXm5G DZvgAUZbdAsjrFmzYk6BbqJ44VYfCd+qQ0MYn/bq1+AqurhcjjHFGazTyDaRUk2+TP66 hyfg== 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:dkim-signature; bh=WCpt10uw8DLCQZQfrha1g8E3xDCVMpXiGVz3py0tkzQ=; b=zrQsN+tzcrXyb0XiCSPt4/GLXAyjcVZRI3+/QdQ5uay49CEvt5ty3gpkNExMDoBkqi j+3NWj1i3lOTlfAZfW0+ukUucBVK2a+ipqdC1hB8oC4xi3zhVdnB6Hm9EJKv/mxgNGwJ Tf9MNzRk6BTgxK6cbEtEXRU+qNCIHHe8VInhsN3NBwaj38ekwwq2HI45pSvqK2R7EeuY bzNdpLIFqcNxCzAbw8Fh1lVLp7+foMbOWLdRYh65GE9gZ0JmhJ8GMOe8Q8JNCzE0amqz r146zQKtHKg3AIX/kQVjZX6ynMyxVhbB8dYR8PRYAbubuPsFgeCq8l9+BF90R/a+Nx08 MTvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=Ot7tq8Ac; 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 f21si2411019pgh.345.2019.07.03.07.25.56; Wed, 03 Jul 2019 07:26:10 -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; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=Ot7tq8Ac; 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 S1727142AbfGCOZO (ORCPT + 99 others); Wed, 3 Jul 2019 10:25:14 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55244 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726918AbfGCOZN (ORCPT ); Wed, 3 Jul 2019 10:25:13 -0400 Received: by mail-wm1-f66.google.com with SMTP id g135so2434357wme.4 for ; Wed, 03 Jul 2019 07:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=WCpt10uw8DLCQZQfrha1g8E3xDCVMpXiGVz3py0tkzQ=; b=Ot7tq8AckH4F2GHhKkP9FKJ7Irnag8ZUN00G04CPW7G185BbY2Z/2IfcuyenSJXniE u000E5EhCOsOxT8QswW4YWBnvJCB2qqqnPReBouJI+m7kZ0W8hBlg9yr/g0dwthO5mC7 ZS9OMbasaUGOZxXmuGQTQsZ6WnRmPC4rl5Ejn2SDK/PDsPnVVGdQ08fsHyWwhtQjM5mQ DwIkjrBcXS2umXJPFxv1HhBZBrl6OfTaZkQaVRdF+C+cixf1d+tO57tXrs0k0CfX1RW2 tuIfGP/rDMRCUy1biYfUIwEO93FN76v3FCDSbe95gR5D1o39WpdAjWU/hJFdKM1096AK Wv+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=WCpt10uw8DLCQZQfrha1g8E3xDCVMpXiGVz3py0tkzQ=; b=fTpihU7F9gpX3mi6/TECpgWUcUU4QszQcM0gpREQBiZYYNcpVtSzzDdJlos+UasXYN wd4XxMam0NNR9ZUcBQVqNDfj3qBt6RIbeC+vhak3AJ29ttxAmTofYHTR2Gu8xpgl9D6b ce5Mwn5azYInk7hD3jDDzDd2DMAs1FiGlham2UoXXuEu1UUCzesuYBsAPmI0EwM0IF44 yaP2a3MyxMC/1fvghDhi9OwjCB8rjcBYpBXE73RzvDa2LkecHVB/FB4yRtxA/x2l1ITM MdGjZYqyxZjxXUX+F69Tdncm7LPcQwjK0ejmsFb3YPIOZ5UJea949Knx2SVymOZ/PrSJ AySg== X-Gm-Message-State: APjAAAXZtKBBp0+b2BJLT0P427J29OsRug0LpLzV51bM/96naL50ivn8 1Zq/39rd99wES+/AWWeaLOo= X-Received: by 2002:a7b:c84c:: with SMTP id c12mr8117801wml.70.1562163911314; Wed, 03 Jul 2019 07:25:11 -0700 (PDT) Received: from localhost (ip-213-220-235-213.net.upcbroadband.cz. [213.220.235.213]) by smtp.gmail.com with ESMTPSA id l11sm2522584wrw.97.2019.07.03.07.25.10 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 03 Jul 2019 07:25:10 -0700 (PDT) Date: Wed, 3 Jul 2019 16:25:10 +0200 From: Jiri Pirko To: Michal Kubecek Cc: David Miller , netdev@vger.kernel.org, Jakub Kicinski , Andrew Lunn , Florian Fainelli , John Linville , Stephen Hemminger , Johannes Berg , linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v6 09/15] ethtool: generic handlers for GET requests Message-ID: <20190703142510.GA2250@nanopsycho> References: <4faa0ce52dfe02c9cde5a46012b16c9af6764c5e.1562067622.git.mkubecek@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4faa0ce52dfe02c9cde5a46012b16c9af6764c5e.1562067622.git.mkubecek@suse.cz> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tue, Jul 02, 2019 at 01:50:24PM CEST, mkubecek@suse.cz wrote: [...] >+/* generic ->doit() handler for GET type requests */ >+static int ethnl_get_doit(struct sk_buff *skb, struct genl_info *info) It is very unfortunate for review to introduce function in a patch and don't use it. In general, this approach is frowned upon. You should use whatever you introduce in the same patch. I understand it is sometimes hard. IIUC, you have one ethnl_get_doit for all possible commands, and you have this ops to do cmd-specific tasks. That is quite unusual. Plus if you consider the complicated datastructures connected with this, I'm lost from the beginning :( Any particular reason form this indirection? I don't think any other generic netlink code does that (correct me if I'm wrong). The nice thing about generic netlink is the fact that you have separate handlers per cmd. I don't think you need these ops and indirections. For the common parts, just have a set of common helpers, as the other generic netlink users are doing. The code would be much easier to read and follow then. >+{ >+ const u8 cmd = info->genlhdr->cmd; >+ const struct get_request_ops *ops; >+ struct ethnl_req_info *req_info; >+ struct sk_buff *rskb; >+ void *reply_payload; >+ int reply_len; >+ int ret; >+ >+ ops = get_requests[cmd]; >+ if (WARN_ONCE(!ops, "cmd %u has no get_request_ops\n", cmd)) >+ return -EOPNOTSUPP; >+ req_info = ethnl_alloc_get_data(ops); >+ if (!req_info) >+ return -ENOMEM; >+ ret = ethnl_std_parse(req_info, info->nlhdr, genl_info_net(info), ops, >+ info->extack, !ops->allow_nodev_do); >+ if (ret < 0) >+ goto err_dev; >+ req_info->privileged = ethnl_is_privileged(skb); >+ ethnl_init_reply_data(req_info, ops, req_info->dev); >+ >+ rtnl_lock(); >+ ret = ops->prepare_data(req_info, info); >+ if (ret < 0) >+ goto err_rtnl; >+ reply_len = ops->reply_size(req_info); >+ if (ret < 0) >+ goto err_cleanup; >+ ret = -ENOMEM; >+ rskb = ethnl_reply_init(reply_len, req_info->dev, ops->reply_cmd, >+ ops->hdr_attr, info, &reply_payload); >+ if (!rskb) >+ goto err_cleanup; >+ ret = ops->fill_reply(rskb, req_info); >+ if (ret < 0) >+ goto err_msg; >+ rtnl_unlock(); >+ >+ genlmsg_end(rskb, reply_payload); >+ if (req_info->dev) >+ dev_put(req_info->dev); >+ ethnl_free_get_data(ops, req_info); >+ return genlmsg_reply(rskb, info); >+ >+err_msg: >+ WARN_ONCE(ret == -EMSGSIZE, >+ "calculated message payload length (%d) not sufficient\n", >+ reply_len); >+ nlmsg_free(rskb); >+err_cleanup: >+ ethnl_free_get_data(ops, req_info); >+err_rtnl: >+ rtnl_unlock(); >+err_dev: >+ if (req_info->dev) >+ dev_put(req_info->dev); >+ return ret; >+} [...]