netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, jakub.kicinski@netronome.com,
	alex.aring@gmail.com, stefan@datenfreihafen.org,
	jon.maloy@ericsson.com, ying.xue@windriver.com,
	johannes.berg@intel.com, mkubecek@suse.cz, yuehaibing@huawei.com,
	mlxsw@mellanox.com
Subject: [patch net-next 10/10] devlink: have genetlink code to parse the attrs during dumpit
Date: Sat,  5 Oct 2019 20:04:42 +0200	[thread overview]
Message-ID: <20191005180442.11788-11-jiri@resnulli.us> (raw)
In-Reply-To: <20191005180442.11788-1-jiri@resnulli.us>

From: Jiri Pirko <jiri@mellanox.com>

Benefit from the fact that the generic netlink code can parse the attrs
for dumpit op and avoid need to parse it in the op callback.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
 net/core/devlink.c | 38 ++++++--------------------------------
 1 file changed, 6 insertions(+), 32 deletions(-)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index 6d16908f34b0..ae07ddb65f34 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -3935,29 +3935,19 @@ static int devlink_nl_region_read_snapshot_fill(struct sk_buff *skb,
 static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
 					     struct netlink_callback *cb)
 {
+	const struct genl_dumpit_info *info = genl_dumpit_info(cb);
 	u64 ret_offset, start_offset, end_offset = 0;
+	struct nlattr **attrs = info->attrs;
 	struct devlink_region *region;
 	struct nlattr *chunks_attr;
 	const char *region_name;
 	struct devlink *devlink;
-	struct nlattr **attrs;
 	bool dump = true;
 	void *hdr;
 	int err;
 
 	start_offset = *((u64 *)&cb->args[0]);
 
-	attrs = kmalloc_array(DEVLINK_ATTR_MAX + 1, sizeof(*attrs), GFP_KERNEL);
-	if (!attrs)
-		return -ENOMEM;
-
-	err = nlmsg_parse_deprecated(cb->nlh,
-				     GENL_HDRLEN + devlink_nl_family.hdrsize,
-				     attrs, DEVLINK_ATTR_MAX,
-				     devlink_nl_family.policy, cb->extack);
-	if (err)
-		goto out_free;
-
 	mutex_lock(&devlink_mutex);
 	devlink = devlink_get_from_attrs(sock_net(cb->skb->sk), attrs);
 	if (IS_ERR(devlink)) {
@@ -4034,7 +4024,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
 	genlmsg_end(skb, hdr);
 	mutex_unlock(&devlink->lock);
 	mutex_unlock(&devlink_mutex);
-	kfree(attrs);
 
 	return skb->len;
 
@@ -4044,8 +4033,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
 	mutex_unlock(&devlink->lock);
 out_dev:
 	mutex_unlock(&devlink_mutex);
-out_free:
-	kfree(attrs);
 	return err;
 }
 
@@ -4987,21 +4974,10 @@ devlink_health_reporter_get_from_info(struct devlink *devlink,
 static struct devlink_health_reporter *
 devlink_health_reporter_get_from_cb(struct netlink_callback *cb)
 {
+	const struct genl_dumpit_info *info = genl_dumpit_info(cb);
 	struct devlink_health_reporter *reporter;
+	struct nlattr **attrs = info->attrs;
 	struct devlink *devlink;
-	struct nlattr **attrs;
-	int err;
-
-	attrs = kmalloc_array(DEVLINK_ATTR_MAX + 1, sizeof(*attrs), GFP_KERNEL);
-	if (!attrs)
-		return NULL;
-
-	err = nlmsg_parse_deprecated(cb->nlh,
-				     GENL_HDRLEN + devlink_nl_family.hdrsize,
-				     attrs, DEVLINK_ATTR_MAX,
-				     devlink_nl_family.policy, cb->extack);
-	if (err)
-		goto free;
 
 	mutex_lock(&devlink_mutex);
 	devlink = devlink_get_from_attrs(sock_net(cb->skb->sk), attrs);
@@ -5010,12 +4986,9 @@ devlink_health_reporter_get_from_cb(struct netlink_callback *cb)
 
 	reporter = devlink_health_reporter_get_from_attrs(devlink, attrs);
 	mutex_unlock(&devlink_mutex);
-	kfree(attrs);
 	return reporter;
 unlock:
 	mutex_unlock(&devlink_mutex);
-free:
-	kfree(attrs);
 	return NULL;
 }
 
@@ -6146,7 +6119,8 @@ static const struct genl_ops devlink_nl_ops[] = {
 	},
 	{
 		.cmd = DEVLINK_CMD_REGION_READ,
-		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.validate = GENL_DONT_VALIDATE_STRICT |
+			    GENL_DONT_VALIDATE_DUMP_STRICT,
 		.dumpit = devlink_nl_cmd_region_read_dumpit,
 		.flags = GENL_ADMIN_PERM,
 		.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
-- 
2.21.0


  parent reply	other threads:[~2019-10-05 18:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-05 18:04 [patch net-next 00/10] net: genetlink: parse attrs for dumpit() callback Jiri Pirko
2019-10-05 18:04 ` [patch net-next 01/10] net: genetlink: push doit/dumpit code from genl_family_rcv_msg Jiri Pirko
2019-10-05 18:04 ` [patch net-next 02/10] net: genetlink: introduce dump info struct to be available during dumpit op Jiri Pirko
2019-10-05 18:04 ` [patch net-next 03/10] net: genetlink: push attrbuf allocation and parsing to a separate function Jiri Pirko
2019-10-05 18:04 ` [patch net-next 04/10] net: genetlink: parse attrs and store in contect info struct during dumpit Jiri Pirko
2019-10-05 18:04 ` [patch net-next 05/10] net: ieee802154: have genetlink code to parse the attrs " Jiri Pirko
2019-10-05 18:04 ` [patch net-next 06/10] net: nfc: " Jiri Pirko
2019-10-05 18:04 ` [patch net-next 07/10] net: tipc: " Jiri Pirko
2021-04-15 21:24   ` Xin Long
2019-10-05 18:04 ` [patch net-next 08/10] net: tipc: allocate attrs locally instead of using genl_family_attrbuf in compat_dumpit() Jiri Pirko
2019-10-05 18:04 ` [patch net-next 09/10] net: genetlink: remove unused genl_family_attrbuf() Jiri Pirko
2019-10-05 18:04 ` Jiri Pirko [this message]
2019-10-06 13:45 ` [patch net-next 00/10] net: genetlink: parse attrs for dumpit() callback David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191005180442.11788-11-jiri@resnulli.us \
    --to=jiri@resnulli.us \
    --cc=alex.aring@gmail.com \
    --cc=davem@davemloft.net \
    --cc=jakub.kicinski@netronome.com \
    --cc=johannes.berg@intel.com \
    --cc=jon.maloy@ericsson.com \
    --cc=mkubecek@suse.cz \
    --cc=mlxsw@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=stefan@datenfreihafen.org \
    --cc=ying.xue@windriver.com \
    --cc=yuehaibing@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).