]> git.openfabrics.org - ~shefty/rdma-win.git/commitdiff
[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@1498 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

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

index 5b81935896f6d8900d9586c64dcafd72450be79a..c41e9ae628191d6de58f30012db4e586838991e9 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 6b2feb8566e73b56a48f5cc6cb514e6d03ff771c..c68ae40ee1405883c7f714dd8e9f2c2b3da7f496 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 b5e8b27f37651aaec8d6978bc1e66d07cb0bd344..5a7d9367f1c375b6e91874f9f2c1d7adfa79b0f7 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 );