Skip to contentSkip to conversation

is_power_of_2 in scsi

kj vignesh babu 1 participant 1 message Aug 13, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Replacing n & (n - 1) for power of 2 check by is_power_of_2(n)

---

drivers/scsi/esp_scsi.c +2 -1
index 77b06a9..908f342 100644
@@ -14,6 +14,7 @@
 #include <linux/moduleparam.h>
 #include <linux/init.h>
 #include <linux/irqreturn.h>
+#include <linux/log2.h>
 
 #include <asm/irq.h>
 #include <asm/io.h>
@@ -1126,7 +1127,7 @@ static int esp_reconnect(struct esp *esp)
 		if (!(bits & esp->scsi_id_mask))
 			goto do_reset;
 		bits &= ~esp->scsi_id_mask;
-		if (!bits || (bits & (bits - 1)))
+		if (!is_power_of_2(bits))
 			goto do_reset;
 
 		target = ffs(bits) - 1;
drivers/scsi/libiscsi.c +2 -1
index 5606d1e..ffa6cc1 100644
@@ -24,6 +24,7 @@
 #include <linux/types.h>
 #include <linux/kfifo.h>
 #include <linux/delay.h>
+#include <linux/log2.h>
 #include <asm/unaligned.h>
 #include <net/tcp.h>
 #include <scsi/scsi_cmnd.h>
@@ -1366,7 +1367,7 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
 		qdepth = ISCSI_DEF_CMD_PER_LUN;
 	}
 
-	if (cmds_max < 2 || (cmds_max & (cmds_max - 1)) ||
+	if (!is_power_of_2(cmds_max) ||
 	    cmds_max >= ISCSI_MGMT_ITT_OFFSET) {
 		if (cmds_max != 0)
 			printk(KERN_ERR "iscsi: invalid can_queue of %d. "
Signature · 3 lines
Vignesh Babu BM 
_____________________________________________________________ 
"Why is it that every time I'm with you, makes me believe in magic?"