IB/core: Fix dereference before check
authorMatan Barak <matanb@mellanox.com>
Wed, 30 Dec 2015 14:14:18 +0000 (16:14 +0200)
committerDoug Ledford <dledford@redhat.com>
Tue, 19 Jan 2016 20:26:54 +0000 (15:26 -0500)
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>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/addr.c

index 0b5f24533ac17cfca6cd17a2e0e5b71ed3a598cb..791cc98475bb67d7cce9c9840cc043c604d146c1 100644 (file)
@@ -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);
 }