[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87mtx36g4u.fsf@nvidia.com>
Date: Wed, 20 Jan 2021 11:45:37 +0100
From: Petr Machata <petrm@...dia.com>
To: David Ahern <dsahern@...il.com>
CC: Jakub Kicinski <kuba@...nel.org>, Petr Machata <petrm@...dia.com>,
<netdev@...r.kernel.org>, David Ahern <dsahern@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Ido Schimmel <idosch@...dia.com>
Subject: Re: [PATCH net-next 1/3] nexthop: Use a dedicated policy for
nh_valid_get_del_req()
David Ahern <dsahern@...il.com> writes:
> On 1/19/21 1:55 PM, Jakub Kicinski wrote:
>>> diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
>>> index e53e43aef785..d5d88f7c5c11 100644
>>> --- a/net/ipv4/nexthop.c
>>> +++ b/net/ipv4/nexthop.c
>>> @@ -36,6 +36,10 @@ static const struct nla_policy rtm_nh_policy[NHA_MAX + 1] = {
>>> [NHA_FDB] = { .type = NLA_FLAG },
>>> };
>>>
>>> +static const struct nla_policy rtm_nh_policy_get[NHA_MAX + 1] = {
>>
>> This is an unnecessary waste of memory if you ask me.
>>
>> NHA_ID is 1, so we're creating an array of 10 extra NULL elements.
>>
>> Can you leave the size to the compiler and use ARRAY_SIZE() below?
>
> interesting suggestion in general for netlink attributes.
>
>>
>>> + [NHA_ID] = { .type = NLA_U32 },
>>> +};
>>> +
>>> static bool nexthop_notifiers_is_empty(struct net *net)
>>> {
>>> return !net->nexthop.notifier_chain.head;
>>> @@ -1843,27 +1847,14 @@ static int nh_valid_get_del_req(struct nlmsghdr *nlh, u32 *id,
>>> {
>>> struct nhmsg *nhm = nlmsg_data(nlh);
>>> struct nlattr *tb[NHA_MAX + 1];
>
> This tb array too could be sized to just the highest indexed expected -
> NHA_ID in this case.
>
>>> - int err, i;
>>> + int err;
>>>
>>> - err = nlmsg_parse(nlh, sizeof(*nhm), tb, NHA_MAX, rtm_nh_policy,
>>> + err = nlmsg_parse(nlh, sizeof(*nhm), tb, NHA_MAX, rtm_nh_policy_get,
>>> extack);
OK, I'll send a v2 that uses ARRAY_SIZE instead of hard-coding the max
and size.
Powered by blists - more mailing lists