ethtool: trim policy tables
Since ethtool uses strict attribute validation there's no need to initialize all attributes in policy tables. 0 is NLA_UNSPEC which is going to be rejected. Remove the NLA_REJECTs. Similarly attributes above maxattrs are rejected, so there's no need to always size the policy tables to ETHTOOL_A_..._MAX. v2: - new patch Suggested-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
5028588b62
commit
ff419afa43
@@ -9,8 +9,7 @@ static struct genl_family ethtool_genl_family;
|
||||
static bool ethnl_ok __read_mostly;
|
||||
static u32 ethnl_bcast_seq;
|
||||
|
||||
static const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_MAX + 1] = {
|
||||
[ETHTOOL_A_HEADER_UNSPEC] = { .type = NLA_REJECT },
|
||||
static const struct nla_policy ethnl_header_policy[] = {
|
||||
[ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 },
|
||||
[ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING,
|
||||
.len = ALTIFNAMSIZ - 1 },
|
||||
@@ -37,7 +36,7 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
|
||||
const struct nlattr *header, struct net *net,
|
||||
struct netlink_ext_ack *extack, bool require_dev)
|
||||
{
|
||||
struct nlattr *tb[ETHTOOL_A_HEADER_MAX + 1];
|
||||
struct nlattr *tb[ARRAY_SIZE(ethnl_header_policy)];
|
||||
const struct nlattr *devname_attr;
|
||||
struct net_device *dev = NULL;
|
||||
u32 flags = 0;
|
||||
@@ -47,7 +46,7 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
|
||||
NL_SET_ERR_MSG(extack, "request header missing");
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = nla_parse_nested(tb, ETHTOOL_A_HEADER_MAX, header,
|
||||
ret = nla_parse_nested(tb, ARRAY_SIZE(ethnl_header_policy) - 1, header,
|
||||
ethnl_header_policy, extack);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user