From: Jack Morgenstein Date: Thu, 12 Dec 2013 07:34:10 +0000 (+0200) Subject: ib_core: Check that caches exist before accessing them X-Git-Tag: v4.1.12-92~293^2~1^2~52 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=7758067d71d16e898c076073328f3be416189ff6;p=users%2Fjedix%2Flinux-maple.git ib_core: Check that caches exist before accessing them 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 (Ported from Mellanox OFED 2.4) Signed-off-by: Mukesh Kacker --- diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c index e269a01e871f5..d11e7c2a88f7f 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c @@ -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;