static void ib_cache_setup_one(struct ib_device *device)
{
int p;
-
+ int port_num;
+
rwlock_init(&device->cache.lock);
-
- device->cache.pkey_cache =
- kmalloc(sizeof *device->cache.pkey_cache *
- (end_port(device) - start_port(device) + 1), GFP_KERNEL);
- device->cache.gid_cache =
- kmalloc(sizeof *device->cache.gid_cache *
- (end_port(device) - start_port(device) + 1), GFP_KERNEL);
-
- device->cache.lmc_cache = kmalloc(sizeof *device->cache.lmc_cache *
- (end_port(device) -
- start_port(device) + 1),
- GFP_KERNEL);
-
- if (!device->cache.pkey_cache || !device->cache.gid_cache ||
- !device->cache.lmc_cache) {
- printk(KERN_WARNING "Couldn't allocate cache "
- "for %s\n", device->name);
- goto err;
+ port_num = end_port(device) - start_port(device) + 1;
+
+ if (port_num > 0 ) {
+ // if port_num ==0 ==> there are no IB ports
+ device->cache.pkey_cache =
+ kmalloc(sizeof *device->cache.pkey_cache * port_num, GFP_KERNEL);
+ device->cache.gid_cache =
+ kmalloc(sizeof *device->cache.gid_cache * port_num, GFP_KERNEL);
+
+ device->cache.lmc_cache = kmalloc(sizeof *device->cache.lmc_cache *
+ port_num, GFP_KERNEL);
+
+ if (!device->cache.pkey_cache || !device->cache.gid_cache ||
+ !device->cache.lmc_cache) {
+ printk(KERN_WARNING "Couldn't allocate cache "
+ "for %s\n", device->name);
+ goto err;
+ }
}
shutter_init( &device->cache.x.work_thread );
- for (p = 0; p <= end_port(device) - start_port(device); ++p) {
+ for (p = 0; p < port_num; ++p) {
device->cache.pkey_cache[p] = NULL;
device->cache.gid_cache [p] = NULL;
ib_cache_update(device, (u8)(p + start_port(device)));