linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] scsi: cxlflash: Use 'bitmap_set()' to simplify the code
@ 2021-11-27 11:46 Christophe JAILLET
  2021-11-27 11:46 ` [PATCH 2/2] scsi: cxlflash: Simplify usage of 'test_bit()' Christophe JAILLET
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2021-11-27 11:46 UTC (permalink / raw)
  To: manoj, mrochs, ukrishn, jejb, martin.petersen
  Cc: linux-scsi, linux-kernel, kernel-janitors, Christophe JAILLET

The 'lun_alloc_map' bitmap is zalloc'ed, so initially all its bits are
zeroed.

So use 'bitmap_set()' which will only set bits in the given range. The
upper bits are left unmodified. (i.e. zero)

This simplifies a lot the logic when initializing this bitmap.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
The mix-up of 'unsigned long', BITS_PER_LONG, 'u64' and ULL is puzzling.
I guess that 'struct ba_lun_info' and its 'u64 *lun_alloc_map' should
remain as is because the file is also used outside Linux.

I also guess that on the system that uses this driver, u64 = unsigned long.

Finally, this is only partially compile tested because I don't have the
needed cross-compiling tool chain.
---
 drivers/scsi/cxlflash/vlun.c | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/cxlflash/vlun.c b/drivers/scsi/cxlflash/vlun.c
index 01917b28cdb6..5600082145bc 100644
--- a/drivers/scsi/cxlflash/vlun.c
+++ b/drivers/scsi/cxlflash/vlun.c
@@ -59,9 +59,7 @@ static void marshal_clone_to_rele(struct dk_cxlflash_clone *clone,
 static int ba_init(struct ba_lun *ba_lun)
 {
 	struct ba_lun_info *bali = NULL;
-	int lun_size_au = 0, i = 0;
-	int last_word_underflow = 0;
-	u64 *lam;
+	int lun_size_au = 0;
 
 	pr_debug("%s: Initializing LUN: lun_id=%016llx "
 		 "ba_lun->lsize=%lx ba_lun->au_size=%lX\n",
@@ -100,20 +98,7 @@ static int ba_init(struct ba_lun *ba_lun)
 
 	/* Initialize the bit map size and set all bits to '1' */
 	bali->free_aun_cnt = lun_size_au;
-
-	for (i = 0; i < bali->lun_bmap_size; i++)
-		bali->lun_alloc_map[i] = 0xFFFFFFFFFFFFFFFFULL;
-
-	/* If the last word not fully utilized, mark extra bits as allocated */
-	last_word_underflow = (bali->lun_bmap_size * BITS_PER_LONG);
-	last_word_underflow -= bali->free_aun_cnt;
-	if (last_word_underflow > 0) {
-		lam = &bali->lun_alloc_map[bali->lun_bmap_size - 1];
-		for (i = (HIBIT - last_word_underflow + 1);
-		     i < BITS_PER_LONG;
-		     i++)
-			clear_bit(i, (ulong *)lam);
-	}
+	bitmap_set((ulong *)bali->lun_alloc_map, 0, bali->free_aun_cnt);
 
 	/* Initialize high elevator index, low/curr already at 0 from kzalloc */
 	bali->free_high_idx = bali->lun_bmap_size;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] scsi: cxlflash: Simplify usage of 'test_bit()'
  2021-11-27 11:46 [PATCH 1/2] scsi: cxlflash: Use 'bitmap_set()' to simplify the code Christophe JAILLET
@ 2021-11-27 11:46 ` Christophe JAILLET
  0 siblings, 0 replies; 2+ messages in thread
From: Christophe JAILLET @ 2021-11-27 11:46 UTC (permalink / raw)
  To: manoj, mrochs, ukrishn, jejb, martin.petersen
  Cc: linux-scsi, linux-kernel, kernel-janitors, Christophe JAILLET

'test_bit()' can access any bit of a bitmap. There is no need to precompute
anything. This just duplicate some computations and is more verbose.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This is only partially compile tested because I don't have the needed
cross-compiling tool chain.
---
 drivers/scsi/cxlflash/vlun.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/scsi/cxlflash/vlun.c b/drivers/scsi/cxlflash/vlun.c
index 5600082145bc..39de9ae49aaf 100644
--- a/drivers/scsi/cxlflash/vlun.c
+++ b/drivers/scsi/cxlflash/vlun.c
@@ -221,12 +221,7 @@ static u64 ba_alloc(struct ba_lun *ba_lun)
  */
 static int validate_alloc(struct ba_lun_info *bali, u64 aun)
 {
-	int idx = 0, bit_pos = 0;
-
-	idx = aun / BITS_PER_LONG;
-	bit_pos = aun % BITS_PER_LONG;
-
-	if (test_bit(bit_pos, (ulong *)&bali->lun_alloc_map[idx]))
+	if (test_bit(aun, (ulong *)bali->lun_alloc_map))
 		return -1;
 
 	return 0;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-27 11:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-27 11:46 [PATCH 1/2] scsi: cxlflash: Use 'bitmap_set()' to simplify the code Christophe JAILLET
2021-11-27 11:46 ` [PATCH 2/2] scsi: cxlflash: Simplify usage of 'test_bit()' Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).