From: Jakub Kicinski <kuba@kernel•org>
To: David Lamparter <equinox@diac24•net>
Cc: netdev@vger•kernel.org, "David S. Miller" <davem@davemloft•net>,
Eric Dumazet <edumazet@google•com>,
Nikolay Aleksandrov <razor@blackwall•org>,
David Ahern <dsahern@kernel•org>
Subject: Re: [PATCH net-next v5] net: ip6mr: add RTM_GETROUTE netlink op
Date: Fri, 8 Jul 2022 20:29:51 -0700 [thread overview]
Message-ID: <20220708202951.46d3454a@kernel.org> (raw)
In-Reply-To: <20220707093336.214658-1-equinox@diac24.net>
Few more nit picks, sorry..
On Thu, 7 Jul 2022 11:33:36 +0200 David Lamparter wrote:
> +static int ip6mr_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
> + struct netlink_ext_ack *extack)
> +{
> + struct net *net = sock_net(in_skb->sk);
> + struct in6_addr src = {}, grp = {};
> + struct nlattr *tb[RTA_MAX + 1];
> + struct sk_buff *skb = NULL;
Should be unnecessary if the code is right, let the compiler warn us
about uninitialized variables.
> + struct mfc6_cache *cache;
> + struct mr_table *mrt;
> + u32 tableid;
> + int err;
> +
> + err = ip6mr_rtm_valid_getroute_req(in_skb, nlh, tb, extack);
> + if (err < 0)
> + goto errout;
Can we:
return err;
? I don't know where the preference for jumping to the return statement
came from, old compilers? someone's "gut feeling"?
> + if (tb[RTA_SRC])
> + src = nla_get_in6_addr(tb[RTA_SRC]);
> + if (tb[RTA_DST])
> + grp = nla_get_in6_addr(tb[RTA_DST]);
> + tableid = tb[RTA_TABLE] ? nla_get_u32(tb[RTA_TABLE]) : 0;
> +
> + mrt = ip6mr_get_table(net, tableid ? tableid : RT_TABLE_DEFAULT);
tableid ? : RT_TABLE_DEFAULT
or
tableid ?: RT_TABLE_DEFAULT
the abbreviated version of the ternary operator is used quite commonly
in the kernel.
> + if (!mrt) {
> + NL_SET_ERR_MSG_MOD(extack, "MR table does not exist");
> + err = -ENOENT;
> + goto errout_free;
Ditto, just return, if not goto errout; there's nothing to free.
> + }
> +
> + /* entries are added/deleted only under RTNL */
> + rcu_read_lock();
> + cache = ip6mr_cache_find(mrt, &src, &grp);
> + rcu_read_unlock();
> + if (!cache) {
> + NL_SET_ERR_MSG_MOD(extack, "MR cache entry not found");
> + err = -ENOENT;
> + goto errout_free;
> + }
> +
> + skb = nlmsg_new(mr6_msgsize(false, mrt->maxvif), GFP_KERNEL);
> + if (!skb) {
> + err = -ENOBUFS;
> + goto errout_free;
> + }
> +
> + err = ip6mr_fill_mroute(mrt, skb, NETLINK_CB(in_skb).portid,
> + nlh->nlmsg_seq, cache, RTM_NEWROUTE, 0);
> + if (err < 0)
> + goto errout_free;
now this is the only case which actually needs to free the skb
> +
> + err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid);
> +
> +errout:
> + return err;
when the label is gone you can:
return rtnl_unicast(...
directly.
> +
> +errout_free:
> + kfree_skb(skb);
> + goto errout;
and no need to do the funky backwards jump here either, IMO
> +}
next prev parent reply other threads:[~2022-07-09 3:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-07 9:33 [PATCH net-next v5] net: ip6mr: add RTM_GETROUTE netlink op David Lamparter
2022-07-09 3:29 ` Jakub Kicinski [this message]
2022-07-09 12:45 ` David Lamparter
2022-07-09 19:23 ` Jakub Kicinski
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=20220708202951.46d3454a@kernel.org \
--to=kuba@kernel$(echo .)org \
--cc=davem@davemloft$(echo .)net \
--cc=dsahern@kernel$(echo .)org \
--cc=edumazet@google$(echo .)com \
--cc=equinox@diac24$(echo .)net \
--cc=netdev@vger$(echo .)kernel.org \
--cc=razor@blackwall$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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