diff mbox

IB/core: Fix dereference before check

Message ID 1451484858-1530-3-git-send-email-matanb@mellanox.com (mailing list archive)
State Accepted
Headers show

Commit Message

Matan Barak Dec. 30, 2015, 2:14 p.m. UTC
Sparse complains about dereference before check. Fixing this by
moving the check before the dereference.

Fixes: 200298326b27 ('IB/core: Validate route when we init ah')
Signed-off-by: Matan Barak <matanb@mellanox.com>
---
Hi Doug,

This patch eliminates a deference before check sparse false warning.
This was introduced in the RoCE v2 series.

Regards,
Matan

 drivers/infiniband/core/addr.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index 0b5f245..791cc98 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -497,13 +497,14 @@  int rdma_resolve_ip_route(struct sockaddr *src_addr,
 	struct sockaddr_storage ssrc_addr = {};
 	struct sockaddr *src_in = (struct sockaddr *)&ssrc_addr;
 
-	if (src_addr->sa_family != dst_addr->sa_family)
-		return -EINVAL;
+	if (src_addr) {
+		if (src_addr->sa_family != dst_addr->sa_family)
+			return -EINVAL;
 
-	if (src_addr)
 		memcpy(src_in, src_addr, rdma_addr_size(src_addr));
-	else
+	} else {
 		src_in->sa_family = dst_addr->sa_family;
+	}
 
 	return addr_resolve(src_in, dst_addr, addr, false);
 }