mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-14 15:54:15 +08:00
xsk: refactor xdp_umem_assign_dev()
Return early and only take the ref on dev once there is no possibility of failing. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Acked-by: Björn Töpel <bjorn.topel@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
c29c2ebd2a
commit
f734607e81
@ -56,41 +56,34 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev,
|
|||||||
if (force_copy)
|
if (force_copy)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (!dev->netdev_ops->ndo_bpf || !dev->netdev_ops->ndo_xsk_async_xmit)
|
||||||
|
return force_zc ? -ENOTSUPP : 0; /* fail or fallback */
|
||||||
|
|
||||||
|
bpf.command = XDP_QUERY_XSK_UMEM;
|
||||||
|
|
||||||
|
rtnl_lock();
|
||||||
|
err = dev->netdev_ops->ndo_bpf(dev, &bpf);
|
||||||
|
rtnl_unlock();
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
return force_zc ? -ENOTSUPP : 0;
|
||||||
|
|
||||||
|
bpf.command = XDP_SETUP_XSK_UMEM;
|
||||||
|
bpf.xsk.umem = umem;
|
||||||
|
bpf.xsk.queue_id = queue_id;
|
||||||
|
|
||||||
|
rtnl_lock();
|
||||||
|
err = dev->netdev_ops->ndo_bpf(dev, &bpf);
|
||||||
|
rtnl_unlock();
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
return force_zc ? err : 0; /* fail or fallback */
|
||||||
|
|
||||||
dev_hold(dev);
|
dev_hold(dev);
|
||||||
|
umem->dev = dev;
|
||||||
if (dev->netdev_ops->ndo_bpf && dev->netdev_ops->ndo_xsk_async_xmit) {
|
umem->queue_id = queue_id;
|
||||||
bpf.command = XDP_QUERY_XSK_UMEM;
|
umem->zc = true;
|
||||||
|
return 0;
|
||||||
rtnl_lock();
|
|
||||||
err = dev->netdev_ops->ndo_bpf(dev, &bpf);
|
|
||||||
rtnl_unlock();
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
dev_put(dev);
|
|
||||||
return force_zc ? -ENOTSUPP : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bpf.command = XDP_SETUP_XSK_UMEM;
|
|
||||||
bpf.xsk.umem = umem;
|
|
||||||
bpf.xsk.queue_id = queue_id;
|
|
||||||
|
|
||||||
rtnl_lock();
|
|
||||||
err = dev->netdev_ops->ndo_bpf(dev, &bpf);
|
|
||||||
rtnl_unlock();
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
dev_put(dev);
|
|
||||||
return force_zc ? err : 0; /* fail or fallback */
|
|
||||||
}
|
|
||||||
|
|
||||||
umem->dev = dev;
|
|
||||||
umem->queue_id = queue_id;
|
|
||||||
umem->zc = true;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
dev_put(dev);
|
|
||||||
return force_zc ? -ENOTSUPP : 0; /* fail or fallback */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xdp_umem_clear_dev(struct xdp_umem *umem)
|
static void xdp_umem_clear_dev(struct xdp_umem *umem)
|
||||||
|
Loading…
Reference in New Issue
Block a user