Skip to content

Commit 58a4ff5

Browse files
Eric Dumazetkuba-moo
authored andcommitted
phonet: no longer hold RTNL in route_dumpit()
route_dumpit() already relies on RCU, RTNL is not needed. Also change return value at the end of a dump. This allows NLMSG_DONE to be appended to the current skb at the end of a dump, saving a couple of recvmsg() system calls. Signed-off-by: Eric Dumazet <[email protected]> Cc: Remi Denis-Courmont <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8d8b1a4 commit 58a4ff5

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

net/phonet/pn_netlink.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static int fill_route(struct sk_buff *skb, struct net_device *dev, u8 dst,
178178
rtm->rtm_type = RTN_UNICAST;
179179
rtm->rtm_flags = 0;
180180
if (nla_put_u8(skb, RTA_DST, dst) ||
181-
nla_put_u32(skb, RTA_OIF, dev->ifindex))
181+
nla_put_u32(skb, RTA_OIF, READ_ONCE(dev->ifindex)))
182182
goto nla_put_failure;
183183
nlmsg_end(skb, nlh);
184184
return 0;
@@ -263,6 +263,7 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
263263
static int route_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
264264
{
265265
struct net *net = sock_net(skb->sk);
266+
int err = 0;
266267
u8 addr;
267268

268269
rcu_read_lock();
@@ -272,16 +273,16 @@ static int route_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
272273
if (!dev)
273274
continue;
274275

275-
if (fill_route(skb, dev, addr << 2, NETLINK_CB(cb->skb).portid,
276-
cb->nlh->nlmsg_seq, RTM_NEWROUTE) < 0)
277-
goto out;
276+
err = fill_route(skb, dev, addr << 2,
277+
NETLINK_CB(cb->skb).portid,
278+
cb->nlh->nlmsg_seq, RTM_NEWROUTE);
279+
if (err < 0)
280+
break;
278281
}
279-
280-
out:
281282
rcu_read_unlock();
282283
cb->args[0] = addr;
283284

284-
return skb->len;
285+
return err;
285286
}
286287

287288
int __init phonet_netlink_register(void)
@@ -301,6 +302,6 @@ int __init phonet_netlink_register(void)
301302
rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_DELROUTE,
302303
route_doit, NULL, 0);
303304
rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_GETROUTE,
304-
NULL, route_dumpit, 0);
305+
NULL, route_dumpit, RTNL_FLAG_DUMP_UNLOCKED);
305306
return 0;
306307
}

0 commit comments

Comments
 (0)