diff mbox

infiniband: hw: ehca: ehca_mrmw.c: Fix for possible null pointer dereference

Message ID 1400346926-25235-1-git-send-email-rickard_strandqvist@spectrumdigital.se (mailing list archive)
State Rejected
Headers show

Commit Message

Rickard Strandqvist May 17, 2014, 5:15 p.m. UTC
There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 drivers/infiniband/hw/ehca/ehca_mrmw.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/drivers/infiniband/hw/ehca/ehca_mrmw.c b/drivers/infiniband/hw/ehca/ehca_mrmw.c
index 3488e8c..1fe4344 100644
--- a/drivers/infiniband/hw/ehca/ehca_mrmw.c
+++ b/drivers/infiniband/hw/ehca/ehca_mrmw.c
@@ -316,9 +316,8 @@  struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
 {
 	struct ib_mr *ib_mr;
 	struct ehca_mr *e_mr;
-	struct ehca_shca *shca =
-		container_of(pd->device, struct ehca_shca, ib_device);
-	struct ehca_pd *e_pd = container_of(pd, struct ehca_pd, ib_pd);
+	struct ehca_shca *shca;
+	struct ehca_pd *e_pd;
 	struct ehca_mr_pginfo pginfo;
 	int ret, page_shift;
 	u32 num_kpages;
@@ -330,6 +329,9 @@  struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
 		return ERR_PTR(-EFAULT);
 	}
 
+	shca = container_of(pd->device, struct ehca_shca, ib_device);
+	e_pd = container_of(pd, struct ehca_pd, ib_pd);
+
 	if (((mr_access_flags & IB_ACCESS_REMOTE_WRITE) &&
 	     !(mr_access_flags & IB_ACCESS_LOCAL_WRITE)) ||
 	    ((mr_access_flags & IB_ACCESS_REMOTE_ATOMIC) &&