From: tzachid Date: Mon, 25 Aug 2008 12:57:47 +0000 (+0000) Subject: [mlx4] Fixed improper zero-memory allocation. X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=919b935970452c6a68b86149aaaeb030d057ee08;p=~shefty%2Frdma-win.git [mlx4] Fixed improper zero-memory allocation. signed-off by: xalex (Alexander Naslednikov) git-svn-id: svn://openib.tc.cornell.edu/gen1@1498 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- diff --git a/trunk/hw/mlx4/kernel/bus/core/cache.c b/trunk/hw/mlx4/kernel/bus/core/cache.c index 5b819358..c41e9ae6 100644 --- a/trunk/hw/mlx4/kernel/bus/core/cache.c +++ b/trunk/hw/mlx4/kernel/bus/core/cache.c @@ -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))); diff --git a/trunk/hw/mlx4/kernel/bus/core/device.c b/trunk/hw/mlx4/kernel/bus/core/device.c index 6b2feb85..c68ae40e 100644 --- a/trunk/hw/mlx4/kernel/bus/core/device.c +++ b/trunk/hw/mlx4/kernel/bus/core/device.c @@ -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); diff --git a/trunk/hw/mlx4/kernel/inc/l2w_memory.h b/trunk/hw/mlx4/kernel/inc/l2w_memory.h index b5e8b27f..5a7d9367 100644 --- a/trunk/hw/mlx4/kernel/inc/l2w_memory.h +++ b/trunk/hw/mlx4/kernel/inc/l2w_memory.h @@ -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 );