qedr: return -EINVAL if pd is null and avoid null ptr dereference
authorColin Ian King <colin.king@canonical.com>
Tue, 18 Oct 2016 18:39:28 +0000 (19:39 +0100)
committerDoug Ledford <dledford@redhat.com>
Wed, 14 Dec 2016 16:18:17 +0000 (11:18 -0500)
Currently, if pd is null then we hit a null pointer derference
on accessing pd->pd_id.  Instead of just printing an error message
we should also return -EINVAL immediately.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/qedr/verbs.c

index a61514296767dacf531b6a964ee25c272b861eb6..b2a0eb8f73d2bf18a28976bb4d1983e6f3488c18 100644 (file)
@@ -511,8 +511,10 @@ int qedr_dealloc_pd(struct ib_pd *ibpd)
        struct qedr_dev *dev = get_qedr_dev(ibpd->device);
        struct qedr_pd *pd = get_qedr_pd(ibpd);
 
-       if (!pd)
+       if (!pd) {
                pr_err("Invalid PD received in dealloc_pd\n");
+               return -EINVAL;
+       }
 
        DP_DEBUG(dev, QEDR_MSG_INIT, "Deallocating PD %d\n", pd->pd_id);
        dev->ops->rdma_dealloc_pd(dev->rdma_ctx, pd->pd_id);