Skip to contentSkip to conversation

EXT4: Use is_power_of_2() routine for clarity.

PATCH In review Robert P. J. Day 3 participants 4 messages Apr 24, 2009 – Apr 25, 2009 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EXT4: Use is_power_of_2() routine for clarity.

---

fs/ext4/super.c +2 -2
index 2958f4e..479d5ef 100644
@@ -1479,7 +1479,7 @@ set_qf_format:
 				return 0;
 			if (option < 0 || option > (1 << 30))
 				return 0;
-			if (option & (option - 1)) {
+			if (!is_power_of_2(option)) {
 				printk(KERN_ERR "EXT4-fs: inode_readahead_blks"
 				       " must be a power of 2\n");
 				return 0;
@@ -2092,7 +2092,7 @@ static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
 		return -EINVAL;
 
 	/* inode_readahead_blks must be a power of 2 */
-	if (t & (t-1))
+	if (!is_power_of_2(t))
 		return -EINVAL;
 
 	sbi->s_inode_readahead_blks = t;

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Annoying Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Linked In:                             http://www.linkedin.com/in/rpjday
Twitter:                                       http://twitter.com/rpjday

========================================================================

Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Robert P. J. Day

Looks fine, thanks.

Quoted 25 lines

---

fs/ext4/super.c +2 -2
index 2958f4e..479d5ef 100644
@@ -1479,7 +1479,7 @@ set_qf_format:
 				return 0;
 			if (option < 0 || option > (1 << 30))
 				return 0;
-			if (option & (option - 1)) {
+			if (!is_power_of_2(option)) {
 				printk(KERN_ERR "EXT4-fs: inode_readahead_blks"
 				       " must be a power of 2\n");
 				return 0;
@@ -2092,7 +2092,7 @@ static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
 		return -EINVAL;
 
 	/* inode_readahead_blks must be a power of 2 */
-	if (t & (t-1))
+	if (!is_power_of_2(t))
 		return -EINVAL;
 
 	sbi->s_inode_readahead_blks = t;
maintainer
#2 lore raw
Quoted 7 lines · Eric Sandeen

fs/ext4/super.c static ssize_t inode_readahead_blks_store(struct ext4_attr *a, · line 2096

Quoted 7 lines
fs/ext4/super.c +1 -1
@@ -2092,7 +2092,7 @@ static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
 		return -EINVAL;
 
 	/* inode_readahead_blks must be a power of 2 */
-	if (t & (t-1))
+	if (!is_power_of_2(t))
 		return -EINVAL;

Might as well remove the comment; it's not needed if we're going to be using is_power_of_2().

- Ted

maintainer
#3 lore raw

PATCH 1/1 ext4: Use is_power_of_2() for clarity

---
 fs/ext4/super.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
fs/ext4/super.c +2 -3
index f19d8b8..e20ff9c 100644
@@ -1482,7 +1482,7 @@ set_qf_format:
 				return 0;
 			if (option < 0 || option > (1 << 30))
 				return 0;
-			if (option & (option - 1)) {
+			if (!is_power_of_2(option)) {
 				printk(KERN_ERR "EXT4-fs: inode_readahead_blks"
 				       " must be a power of 2\n");
 				return 0;
@@ -2100,8 +2100,7 @@ static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
 	if (parse_strtoul(buf, 0x40000000, &t))
 		return -EINVAL;
 
-	/* inode_readahead_blks must be a power of 2 */
-	if (t & (t-1))
+	if (!is_power_of_2(t))
 		return -EINVAL;
 
 	sbi->s_inode_readahead_blks = t;
Signature · 1 line
1.5.6.3