]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ib_core: Check that caches exist before accessing them
authorJack Morgenstein <jackm@dev.mellanox.co.il>
Thu, 12 Dec 2013 07:34:10 +0000 (09:34 +0200)
committerMukesh Kacker <mukesh.kacker@oracle.com>
Tue, 7 Jul 2015 21:45:16 +0000 (14:45 -0700)
Check that the gid/pkey cache exists before trying to access
them (ib_find_cached_xxx and ib_cache_update).

Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
(Ported from Mellanox OFED 2.4)

Signed-off-by: Mukesh Kacker <mukesh.kacker@oracle.com>
drivers/infiniband/core/cache.c

index e269a01e871f556e0e4bfb46bbe9166cd6f3167c..d11e7c2a88f7f24d8afa788875450c7e1a59f9c5 100644 (file)
@@ -113,22 +113,24 @@ int ib_find_cached_gid(struct ib_device *device,
                *index = -1;
 
        read_lock_irqsave(&device->cache.lock, flags);
-
+       if (!device->cache.gid_cache)
+               goto out;
        for (p = 0; p <= end_port(device) - start_port(device); ++p) {
                cache = device->cache.gid_cache[p];
+               if (!cache)
+                       continue;
                for (i = 0; i < cache->table_len; ++i) {
                        if (!memcmp(gid, &cache->table[i], sizeof *gid)) {
                                *port_num = p + start_port(device);
                                if (index)
                                        *index = i;
                                ret = 0;
-                               goto found;
+                               goto out;
                        }
                }
        }
-found:
+out:
        read_unlock_irqrestore(&device->cache.lock, flags);
-
        return ret;
 }
 EXPORT_SYMBOL(ib_find_cached_gid);
@@ -176,11 +178,16 @@ int ib_find_cached_pkey(struct ib_device *device,
        if (port_num < start_port(device) || port_num > end_port(device))
                return -EINVAL;
 
+       *index = -1;
+
        read_lock_irqsave(&device->cache.lock, flags);
 
-       cache = device->cache.pkey_cache[port_num - start_port(device)];
+       if (!device->cache.pkey_cache)
+               goto out;
 
-       *index = -1;
+       cache = device->cache.pkey_cache[port_num - start_port(device)];
+       if (!cache)
+               goto out;
 
        for (i = 0; i < cache->table_len; ++i)
                if ((cache->table[i] & 0x7fff) == (pkey & 0x7fff)) {
@@ -196,9 +203,8 @@ int ib_find_cached_pkey(struct ib_device *device,
                *index = partial_ix;
                ret = 0;
        }
-
+out:
        read_unlock_irqrestore(&device->cache.lock, flags);
-
        return ret;
 }
 EXPORT_SYMBOL(ib_find_cached_pkey);
@@ -216,11 +222,16 @@ int ib_find_exact_cached_pkey(struct ib_device *device,
        if (port_num < start_port(device) || port_num > end_port(device))
                return -EINVAL;
 
+       *index = -1;
+
        read_lock_irqsave(&device->cache.lock, flags);
 
-       cache = device->cache.pkey_cache[port_num - start_port(device)];
+       if (!device->cache.pkey_cache)
+               goto out;
 
-       *index = -1;
+       cache = device->cache.pkey_cache[port_num - start_port(device)];
+       if (!cache)
+               goto out;
 
        for (i = 0; i < cache->table_len; ++i)
                if (cache->table[i] == pkey) {
@@ -228,9 +239,8 @@ int ib_find_exact_cached_pkey(struct ib_device *device,
                        ret = 0;
                        break;
                }
-
+out:
        read_unlock_irqrestore(&device->cache.lock, flags);
-
        return ret;
 }
 EXPORT_SYMBOL(ib_find_exact_cached_pkey);
@@ -265,6 +275,10 @@ static void ib_cache_update(struct ib_device *device,
        int                        i;
        int                        ret;
 
+       if (!(device->cache.pkey_cache && device->cache.gid_cache &&
+             device->cache.lmc_cache))
+               return;
+
        tprops = kmalloc(sizeof *tprops, GFP_KERNEL);
        if (!tprops)
                return;