[PATCH] cxgb4: fix undefined behavior in mem.c

From: Shaobo He
Date: Thu Feb 28 2019 - 17:38:55 EST


In function `c4iw_dealloc_mw`, variable mhp's value is printed after
freed, which triggers undefined behavior according to this post:
https://trust-in-soft.com/dangling-pointer-indeterminate/.

This commit fixes it by swapping the order of `kfree` and `pr_debug`.

Signed-off-by: Shaobo He <shaobo@xxxxxxxxxxx>
---
drivers/infiniband/hw/cxgb4/mem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
index 7b76e6f..bb8e0bc 100644
--- a/drivers/infiniband/hw/cxgb4/mem.c
+++ b/drivers/infiniband/hw/cxgb4/mem.c
@@ -684,8 +684,8 @@ int c4iw_dealloc_mw(struct ib_mw *mw)
mhp->wr_waitp);
kfree_skb(mhp->dereg_skb);
c4iw_put_wr_wait(mhp->wr_waitp);
- kfree(mhp);
pr_debug("ib_mw %p mmid 0x%x ptr %p\n", mw, mmid, mhp);
+ kfree(mhp);
return 0;
}

--
2.7.4