[ofa-general] [PATCH] libmlx4: doorbell allocator

Eli Cohen eli at mellanox.co.il
Mon Jun 4 07:16:35 PDT 2007


Use type of the constant 1 identical to the type of the
variable holding the bit mask to prevent using the same bit
twice.
For example, on 64 bit machines, int is 32 bits and long is
64 bits. So 1 << 0 is equal 1 << 32 whereas the correct usage
should be 1L << shift_val

Found by Dotan Barak at Mellanox
Signed-off-by: Eli Cohen <eli at mellanox.co.il>

---
Index: libmlx4/src/dbrec.c
===================================================================
--- libmlx4.orig/src/dbrec.c	2007-06-04 12:53:57.000000000 +0300
+++ libmlx4/src/dbrec.c	2007-06-04 16:53:31.000000000 +0300
@@ -110,7 +110,7 @@
 		/* nothing */;
 
 	j = ffsl(page->free[i]);
-	page->free[i] &= ~(1 << (j - 1));
+	page->free[i] &= ~(1L << (j - 1));
 	db = page->buf.buf + (i * 8 * sizeof (long) + (j - 1)) * db_size[type];
 
 out:
@@ -135,7 +135,7 @@
 		goto out;
 
 	i = ((void *) db - page->buf.buf) / db_size[type];
-	page->free[i / (8 * sizeof (long))] |= 1 << (i % (8 * sizeof (long)));
+	page->free[i / (8 * sizeof (long))] |= 1L << (i % (8 * sizeof (long)));
 
 	if (!--page->use_cnt) {
 		if (page->prev)




More information about the general mailing list