Skip to content

Commit a670c4d

Browse files
kuba-mooNipaLocal
authored andcommitted
net: ethtool: dynamically allocate full req size req
In preparation for using req_info to carry parameters between SET and NTF allocate a full request into struct. Since the size depends on the subcommand we need to allocate it on the heap. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent fcc933d commit a670c4d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

net/ethtool/netlink.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,8 @@ static int ethnl_default_done(struct netlink_callback *cb)
863863
static int ethnl_default_set_doit(struct sk_buff *skb, struct genl_info *info)
864864
{
865865
const struct ethnl_request_ops *ops;
866-
struct ethnl_req_info req_info = {};
867866
const u8 cmd = info->genlhdr->cmd;
867+
struct ethnl_req_info *req_info;
868868
struct net_device *dev;
869869
int ret;
870870

@@ -874,20 +874,24 @@ static int ethnl_default_set_doit(struct sk_buff *skb, struct genl_info *info)
874874
if (GENL_REQ_ATTR_CHECK(info, ops->hdr_attr))
875875
return -EINVAL;
876876

877-
ret = ethnl_parse_header_dev_get(&req_info, info->attrs[ops->hdr_attr],
877+
req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
878+
if (!req_info)
879+
return -ENOMEM;
880+
881+
ret = ethnl_parse_header_dev_get(req_info, info->attrs[ops->hdr_attr],
878882
genl_info_net(info), info->extack,
879883
true);
880884
if (ret < 0)
881-
return ret;
885+
goto out_free_req;
882886

883887
if (ops->set_validate) {
884-
ret = ops->set_validate(&req_info, info);
888+
ret = ops->set_validate(req_info, info);
885889
/* 0 means nothing to do */
886890
if (ret <= 0)
887891
goto out_dev;
888892
}
889893

890-
dev = req_info.dev;
894+
dev = req_info->dev;
891895

892896
rtnl_lock();
893897
netdev_lock_ops(dev);
@@ -902,7 +906,7 @@ static int ethnl_default_set_doit(struct sk_buff *skb, struct genl_info *info)
902906
if (ret < 0)
903907
goto out_free_cfg;
904908

905-
ret = ops->set(&req_info, info);
909+
ret = ops->set(req_info, info);
906910
if (ret < 0)
907911
goto out_ops;
908912

@@ -921,7 +925,9 @@ static int ethnl_default_set_doit(struct sk_buff *skb, struct genl_info *info)
921925
netdev_unlock_ops(dev);
922926
rtnl_unlock();
923927
out_dev:
924-
ethnl_parse_header_dev_put(&req_info);
928+
ethnl_parse_header_dev_put(req_info);
929+
out_free_req:
930+
kfree(req_info);
925931
return ret;
926932
}
927933

0 commit comments

Comments
 (0)