[dm-devel] [PATCH] dm-verity: code cleanup - use __ffs and __fls

Mikulas Patocka mpatocka at redhat.com
Fri Jun 28 18:46:30 UTC 2013


dm-verity: code cleanup - use __ffs and __fls

This patch is a small code cleanup for dm-verity. In Linux kernel there
are functions __ffs and __fls which don't add one to the result like libc
functions ffs and fls. This patch changes ffs to __ffs and fls to __fls.

Signed-off-by: Mikulas Patocka <mpatocka at redhat.com>

---
 drivers/md/dm-verity.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Index: linux-3.9.8-fast/drivers/md/dm-verity.c
===================================================================
--- linux-3.9.8-fast.orig/drivers/md/dm-verity.c	2013-06-28 18:16:02.000000000 +0200
+++ linux-3.9.8-fast/drivers/md/dm-verity.c	2013-06-28 18:52:31.000000000 +0200
@@ -451,7 +451,7 @@ static void verity_prefetch_io(struct wo
 				goto no_prefetch_cluster;
 
 			if (unlikely(cluster & (cluster - 1)))
-				cluster = 1 << (fls(cluster) - 1);
+				cluster = 1 << __fls(cluster);
 
 			hash_block_start &= ~(sector_t)(cluster - 1);
 			hash_block_end |= cluster - 1;
@@ -723,7 +723,7 @@ static int verity_ctr(struct dm_target *
 		r = -EINVAL;
 		goto bad;
 	}
-	v->data_dev_block_bits = ffs(num) - 1;
+	v->data_dev_block_bits = __ffs(num);
 
 	if (sscanf(argv[4], "%u%c", &num, &dummy) != 1 ||
 	    !num || (num & (num - 1)) ||
@@ -733,7 +733,7 @@ static int verity_ctr(struct dm_target *
 		r = -EINVAL;
 		goto bad;
 	}
-	v->hash_dev_block_bits = ffs(num) - 1;
+	v->hash_dev_block_bits = __ffs(num);
 
 	if (sscanf(argv[5], "%llu%c", &num_ll, &dummy) != 1 ||
 	    (sector_t)(num_ll << (v->data_dev_block_bits - SECTOR_SHIFT))
@@ -812,7 +812,7 @@ static int verity_ctr(struct dm_target *
 	}
 
 	v->hash_per_block_bits =
-		fls((1 << v->hash_dev_block_bits) / v->digest_size) - 1;
+		__fls((1 << v->hash_dev_block_bits) / v->digest_size);
 
 	v->levels = 0;
 	if (v->data_blocks)




More information about the dm-devel mailing list