xdp: check device pointer before clearing
authorIlya Maximets <i.maximets@samsung.com>
Fri, 7 Jun 2019 17:27:32 +0000 (20:27 +0300)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 12 Jun 2019 14:41:47 +0000 (16:41 +0200)
We should not call 'ndo_bpf()' or 'dev_put()' with NULL argument.

Fixes: c9b47cc1fabc ("xsk: fix bug when trying to use both copy and zero-copy on one queue id")
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
net/xdp/xdp_umem.c

index 2b18223e7eb8cd3691290b4d0e7bdf17843bd683..9c6de4f114f84cc17b442294a2049d8a8cd87002 100644 (file)
@@ -143,6 +143,9 @@ static void xdp_umem_clear_dev(struct xdp_umem *umem)
        struct netdev_bpf bpf;
        int err;
 
+       if (!umem->dev)
+               return;
+
        if (umem->zc) {
                bpf.command = XDP_SETUP_XSK_UMEM;
                bpf.xsk.umem = NULL;
@@ -156,11 +159,9 @@ static void xdp_umem_clear_dev(struct xdp_umem *umem)
                        WARN(1, "failed to disable umem!\n");
        }
 
-       if (umem->dev) {
-               rtnl_lock();
-               xdp_clear_umem_at_qid(umem->dev, umem->queue_id);
-               rtnl_unlock();
-       }
+       rtnl_lock();
+       xdp_clear_umem_at_qid(umem->dev, umem->queue_id);
+       rtnl_unlock();
 
        if (umem->zc) {
                dev_put(umem->dev);