Skip to contentSkip to conversation

cciss: cleanup bitops usage

PATCH New Akinobu Mita 2 participants 5 messages Apr 3, 2012

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

PATCH 1/1 cciss: cleanup bitops usage

- Remove unnecessary correction of bit and address
- Use BITS_TO_LONGS macro to calculate bitmap size
- Use bitmap_zero()

---
 drivers/block/cciss.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
drivers/block/cciss.c +5 -9
index b0f553b..bda6d12 100644
@@ -41,6 +41,7 @@
 #include <linux/spinlock.h>
 #include <linux/compat.h>
 #include <linux/mutex.h>
+#include <linux/bitmap.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
@@ -978,8 +979,7 @@ static CommandList_struct *cmd_alloc(ctlr_info_t *h)
 		i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds);
 		if (i == h->nr_cmds)
 			return NULL;
-	} while (test_and_set_bit(i & (BITS_PER_LONG - 1),
-		  h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0);
+	} while (test_and_set_bit(i, h->cmd_pool_bits) != 0);
 	c = h->cmd_pool + i;
 	memset(c, 0, sizeof(CommandList_struct));
 	cmd_dma_handle = h->cmd_pool_dhandle + i * sizeof(CommandList_struct);
@@ -1046,8 +1046,7 @@ static void cmd_free(ctlr_info_t *h, CommandList_struct *c)
 	int i;
 
 	i = c - h->cmd_pool;
-	clear_bit(i & (BITS_PER_LONG - 1),
-		  h->cmd_pool_bits + (i / BITS_PER_LONG));
+	clear_bit(i, h->cmd_pool_bits);
 	h->nr_frees++;
 }
 
@@ -4812,8 +4811,7 @@ static __devinit int cciss_init_reset_devices(struct pci_dev *pdev)
 
 static __devinit int cciss_allocate_cmd_pool(ctlr_info_t *h)
 {
-	h->cmd_pool_bits = kmalloc(
-		DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) *
+	h->cmd_pool_bits = kmalloc(BITS_TO_LONGS(h->nr_cmds) *
 		sizeof(unsigned long), GFP_KERNEL);
 	h->cmd_pool = pci_alloc_consistent(h->pdev,
 		h->nr_cmds * sizeof(CommandList_struct),
@@ -5068,9 +5066,7 @@ reinit_after_soft_reset:
 	pci_set_drvdata(pdev, h);
 	/* command and error info recs zeroed out before
 	   they are used */
-	memset(h->cmd_pool_bits, 0,
-	       DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG)
-			* sizeof(unsigned long));
+	bitmap_zero(h->cmd_pool_bits, h->nr_cmds);
 
 	h->num_luns = 0;
 	h->highest_lun = -1;
Signature · 1 line
1.7.4.4
#1 lore raw

PATCH 1/1 cciss: use check_signature

Use check_signature to find a signature in the mmio address.

---
 drivers/block/cciss.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
drivers/block/cciss.c +2 -5
index bda6d12..e04c63e 100644
@@ -42,8 +42,8 @@
 #include <linux/compat.h>
 #include <linux/mutex.h>
 #include <linux/bitmap.h>
+#include <linux/io.h>
 #include <asm/uaccess.h>
-#include <asm/io.h>
 
 #include <linux/dma-mapping.h>
 #include <linux/blkdev.h>
@@ -4267,10 +4267,7 @@ static void __devinit cciss_find_board_params(ctlr_info_t *h)
 
 static inline bool CISS_signature_present(ctlr_info_t *h)
 {
-	if ((readb(&h->cfgtable->Signature[0]) != 'C') ||
-	    (readb(&h->cfgtable->Signature[1]) != 'I') ||
-	    (readb(&h->cfgtable->Signature[2]) != 'S') ||
-	    (readb(&h->cfgtable->Signature[3]) != 'S')) {
+	if (!check_signature(h->cfgtable->Signature, "CISS", 4)) {
 		dev_warn(&h->pdev->dev, "not a valid CISS config table\n");
 		return false;
 	}
Signature · 1 line
1.7.4.4
#2 lore raw

PATCH 1/1 hpsa: cleanup bitops usage

In reply to Akinobu Mita

- Remove unnecessary correction of bit and address
- Use BITS_TO_LONGS macro to calculate bitmap size

Cc Stephen M. Cameron <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/hpsa.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)
drivers/scsi/hpsa.c +3 -7
index 500e20d..ddbf5fe 100644
@@ -2351,9 +2351,7 @@ static struct CommandList *cmd_alloc(struct ctlr_info *h)
 		i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds);
 		if (i == h->nr_cmds)
 			return NULL;
-	} while (test_and_set_bit
-		 (i & (BITS_PER_LONG - 1),
-		  h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0);
+	} while (test_and_set_bit(i, h->cmd_pool_bits) != 0);
 	c = h->cmd_pool + i;
 	memset(c, 0, sizeof(*c));
 	cmd_dma_handle = h->cmd_pool_dhandle
@@ -2420,8 +2418,7 @@ static void cmd_free(struct ctlr_info *h, struct CommandList *c)
 	int i;
 
 	i = c - h->cmd_pool;
-	clear_bit(i & (BITS_PER_LONG - 1),
-		  h->cmd_pool_bits + (i / BITS_PER_LONG));
+	clear_bit(i, h->cmd_pool_bits);
 	h->nr_frees++;
 }
 
@@ -4045,8 +4042,7 @@ static __devinit int hpsa_init_reset_devices(struct pci_dev *pdev)
 
 static __devinit int hpsa_allocate_cmd_pool(struct ctlr_info *h)
 {
-	h->cmd_pool_bits = kzalloc(
-		DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) *
+	h->cmd_pool_bits = kzalloc(BITS_TO_LONGS(h->nr_cmds) *
 		sizeof(unsigned long), GFP_KERNEL);
 	h->cmd_pool = pci_alloc_consistent(h->pdev,
 		    h->nr_cmds * sizeof(*h->cmd_pool),
Signature · 1 line
1.7.4.4
#3 lore raw

PATCH 1/1 hpsa: use check_signature

In reply to Akinobu Mita

Use check_signature to find a signature in the mmio address.

---
 drivers/scsi/hpsa.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
drivers/scsi/hpsa.c +1 -4
index ddbf5fe..c867eeb 100644
@@ -3839,10 +3839,7 @@ static void __devinit hpsa_find_board_params(struct ctlr_info *h)
 
 static inline bool hpsa_CISS_signature_present(struct ctlr_info *h)
 {
-	if ((readb(&h->cfgtable->Signature[0]) != 'C') ||
-	    (readb(&h->cfgtable->Signature[1]) != 'I') ||
-	    (readb(&h->cfgtable->Signature[2]) != 'S') ||
-	    (readb(&h->cfgtable->Signature[3]) != 'S')) {
+	if (!check_signature(h->cfgtable->Signature, "CISS", 4)) {
 		dev_warn(&h->pdev->dev, "not a valid CISS config table\n");
 		return false;
 	}
Signature · 1 line
1.7.4.4
Acked-by on v1 1/1
#4 lore raw

Re: [PATCH] hpsa: use check_signature

Quoted 7 lines · Akinobu Mita

Use check_signature to find a signature in the mmio address.

Quoted 20 lines
---
  drivers/scsi/hpsa.c |    5 +----
  1 files changed, 1 insertions(+), 4 deletions(-)
drivers/scsi/hpsa.c +1 -4
index ddbf5fe..c867eeb 100644
@@ -3839,10 +3839,7 @@ static void __devinit hpsa_find_board_params(struct ctlr_info *h)
 
  static inline bool hpsa_CISS_signature_present(struct ctlr_info *h)
  {
-	if ((readb(&h->cfgtable->Signature[0]) != 'C') ||
-	    (readb(&h->cfgtable->Signature[1]) != 'I') ||
-	    (readb(&h->cfgtable->Signature[2]) != 'S') ||
-	    (readb(&h->cfgtable->Signature[3]) != 'S')) {
+	if (!check_signature(h->cfgtable->Signature, "CISS", 4)) {
  		dev_warn(&h->pdev->dev, "not a valid CISS config table\n");
  		return false;
  	}