Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

RDMA/core: Allocate the pkey cache only if the pkey_tbl_len is set

Allocate the pkey cache only if the pkey_tbl_len is set by the provider,
also add checks to avoid accessing the pkey cache when it not initialized.

Link: https://lore.kernel.org/r/20200714183414.61069-3-kamalheib1@gmail.com
Signed-off-by: Kamal Heib <kamalheib1@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Kamal Heib and committed by
Jason Gunthorpe
6f38efca 90efc8b2

+30 -17
+30 -17
drivers/infiniband/core/cache.c
··· 1054 1054 1055 1055 cache = device->port_data[port_num].cache.pkey; 1056 1056 1057 - if (index < 0 || index >= cache->table_len) 1057 + if (!cache || index < 0 || index >= cache->table_len) 1058 1058 ret = -EINVAL; 1059 1059 else 1060 1060 *pkey = cache->table[index]; ··· 1099 1099 read_lock_irqsave(&device->cache_lock, flags); 1100 1100 1101 1101 cache = device->port_data[port_num].cache.pkey; 1102 + if (!cache) { 1103 + ret = -EINVAL; 1104 + goto err; 1105 + } 1102 1106 1103 1107 *index = -1; 1104 1108 ··· 1121 1117 ret = 0; 1122 1118 } 1123 1119 1120 + err: 1124 1121 read_unlock_irqrestore(&device->cache_lock, flags); 1125 1122 1126 1123 return ret; ··· 1144 1139 read_lock_irqsave(&device->cache_lock, flags); 1145 1140 1146 1141 cache = device->port_data[port_num].cache.pkey; 1142 + if (!cache) { 1143 + ret = -EINVAL; 1144 + goto err; 1145 + } 1147 1146 1148 1147 *index = -1; 1149 1148 ··· 1158 1149 break; 1159 1150 } 1160 1151 1152 + err: 1161 1153 read_unlock_irqrestore(&device->cache_lock, flags); 1162 1154 1163 1155 return ret; ··· 1435 1425 goto err; 1436 1426 } 1437 1427 1438 - pkey_cache = kmalloc(struct_size(pkey_cache, table, 1439 - tprops->pkey_tbl_len), 1440 - GFP_KERNEL); 1441 - if (!pkey_cache) { 1442 - ret = -ENOMEM; 1443 - goto err; 1444 - } 1445 - 1446 - pkey_cache->table_len = tprops->pkey_tbl_len; 1447 - 1448 - for (i = 0; i < pkey_cache->table_len; ++i) { 1449 - ret = ib_query_pkey(device, port, i, pkey_cache->table + i); 1450 - if (ret) { 1451 - dev_warn(&device->dev, 1452 - "ib_query_pkey failed (%d) for index %d\n", 1453 - ret, i); 1428 + if (tprops->pkey_tbl_len) { 1429 + pkey_cache = kmalloc(struct_size(pkey_cache, table, 1430 + tprops->pkey_tbl_len), 1431 + GFP_KERNEL); 1432 + if (!pkey_cache) { 1433 + ret = -ENOMEM; 1454 1434 goto err; 1435 + } 1436 + 1437 + pkey_cache->table_len = tprops->pkey_tbl_len; 1438 + 1439 + for (i = 0; i < pkey_cache->table_len; ++i) { 1440 + ret = ib_query_pkey(device, port, i, 1441 + pkey_cache->table + i); 1442 + if (ret) { 1443 + dev_warn(&device->dev, 1444 + "ib_query_pkey failed (%d) for index %d\n", 1445 + ret, i); 1446 + goto err; 1447 + } 1455 1448 } 1456 1449 } 1457 1450