[mlx4] Fixed improper zero-memory allocation.
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 25 Aug 2008 12:57:47 +0000 (12:57 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 25 Aug 2008 12:57:47 +0000 (12:57 +0000)
signed-off by: xalex (Alexander Naslednikov)

git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@1498 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

hw/mlx4/kernel/bus/core/cache.c
hw/mlx4/kernel/bus/core/device.c
hw/mlx4/kernel/inc/l2w_memory.h

index 5b81935..c41e9ae 100644 (file)
@@ -363,31 +363,32 @@ static void ib_cache_event(struct ib_event_handler *handler,
 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)));
index 6b2feb8..c68ae40 100644 (file)
@@ -227,8 +227,13 @@ static int read_port_table_lengths(struct ib_device *device)
        tprops = kmalloc(sizeof *tprops, GFP_KERNEL);
        if (!tprops)
                goto out;
-
+       
        num_ports = end_port(device) - start_port(device) + 1;
+       if ( num_ports == 0 ){
+               //There are no IB ports, no need to update this tables
+               ret = 0;  
+               goto out;
+       }
 
        device->pkey_tbl_len = kmalloc(sizeof *device->pkey_tbl_len * num_ports,
                                       GFP_KERNEL);
index b5e8b27..5a7d936 100644 (file)
@@ -81,7 +81,8 @@ struct vm_area_struct {
 static inline void * kmalloc( SIZE_T bsize, gfp_t gfp_mask)
 {
        void *ptr;
-       ASSERT( KeGetCurrentIrql() <= DISPATCH_LEVEL );
+       ASSERT( KeGetCurrentIrql() <= DISPATCH_LEVEL);
+       ASSERT(bsize);
        switch (gfp_mask) {
                case GFP_ATOMIC:
                        ptr = ExAllocatePoolWithTag( NonPagedPool, bsize, MT_TAG_ATOMIC );