@@ -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) &&
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(-)