From: Vignesh Babu BM Date: Fri, 16 Feb 2007 06:05:42 +0000 Subject: [KJ] [PATCH 1/5] moving to is_power_of_2 Message-Id: <1171605222.27506.74.camel@wriver-t81fb058.linuxcoe> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: kernel-janitors@vger.kernel.org Removing instances of (n&(n-1)) for power of 2 check with is_power_of_2 from linux/log.h. Signed-off-by: vignesh babu --- arch/ia64/mm/hugetlbpage.c | 4 +++- drivers/block/rd.c | 3 ++- drivers/md/dm-snap.c | 4 +++- drivers/net/cxgb3/cxgb3_main.c | 7 +++++-- drivers/net/pcmcia/pcnet_cs.c | 4 +++- drivers/rtc/rtc-s3c.c | 4 +++- drivers/s390/block/dasd_int.h | 4 +++- drivers/s390/cio/cio.c | 3 ++- drivers/s390/cio/device_fsm.c | 3 ++- drivers/video/vesafb.c | 4 +++- fs/block_dev.c | 4 +++- fs/ext2/super.c | 4 +++- fs/ext3/super.c | 4 +++- fs/ext4/super.c | 7 +++++-- fs/fat/inode.c | 11 +++++++---- fs/hfs/btree.c | 3 ++- fs/hfsplus/btree.c | 4 +++- fs/nfs/internal.h | 5 +++-- fs/ntfs/inode.c | 4 +++- fs/ntfs/logfile.c | 4 +++- fs/ufs/super.c | 7 +++++-- kernel/kfifo.c | 4 +++- net/core/neighbour.c | 4 +++- sound/core/rtctimer.c | 4 +++- 24 files changed, 78 insertions(+), 31 deletions(-) diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c index 0c7e94e..4fc6887 100644 --- a/arch/ia64/mm/hugetlbpage.c +++ b/arch/ia64/mm/hugetlbpage.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -175,7 +176,8 @@ static int __init hugetlb_setup_sz(char *str) tr_pages = 0x15557000UL; size = memparse(str, &str); - if (*str || (size & (size-1)) || !(tr_pages & size) || + //if (*str || (size & (size-1)) || !(tr_pages & size) || + if (*str || !is_power_of_2(size) || !(tr_pages & size) || size <= PAGE_SIZE || size >= (1UL << PAGE_SHIFT << MAX_ORDER)) { printk(KERN_WARNING "Invalid huge page size specified\n"); diff --git a/drivers/block/rd.c b/drivers/block/rd.c index 485aa87..9c21994 100644 --- a/drivers/block/rd.c +++ b/drivers/block/rd.c @@ -422,7 +422,8 @@ static int __init rd_init(void) int err = -ENOMEM; if (rd_blocksize > PAGE_SIZE || rd_blocksize < 512 || - (rd_blocksize & (rd_blocksize-1))) { + //(rd_blocksize & (rd_blocksize-1))) { + (!is_power_of_2(rd_blocksize))) { printk("RAMDISK: wrong blocksize %d, reverting to defaults\n", rd_blocksize); rd_blocksize = BLOCK_SIZE; diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 0821a2b..f066405 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "dm-snap.h" #include "dm-bio-list.h" @@ -414,7 +415,8 @@ static int set_chunk_size(struct dm_snapshot *s, const char *chunk_size_arg, chunk_size = round_up(chunk_size, PAGE_SIZE >> 9); /* Check chunk_size is a power of 2 */ - if (chunk_size & (chunk_size - 1)) { + //if (chunk_size & (chunk_size - 1)) { + if (!is_power_of_2(chunk_size)) { *error = "Chunk size is not a power of 2"; return -EINVAL; } diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c index c67f7d3..4c7437f 100644 --- a/drivers/net/cxgb3/cxgb3_main.c +++ b/drivers/net/cxgb3/cxgb3_main.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "common.h" @@ -1792,8 +1793,10 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr) return -EBUSY; if (copy_from_user(&m, useraddr, sizeof(m))) return -EFAULT; - if (!m.rx_pg_sz || (m.rx_pg_sz & (m.rx_pg_sz - 1)) || - !m.tx_pg_sz || (m.tx_pg_sz & (m.tx_pg_sz - 1))) + //if (!m.rx_pg_sz || (m.rx_pg_sz & (m.rx_pg_sz - 1)) || + //!m.tx_pg_sz || (m.tx_pg_sz & (m.tx_pg_sz - 1))) + if (!is_power_of_2(m.rx_pg_sz) || + !is_power_of_2(m.tx_pg_sz)) return -EINVAL; /* not power of 2 */ if (!(m.rx_pg_sz & 0x14000)) return -EINVAL; /* not 16KB or 64KB */ diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c index d88e9b2..ee0c8b3 100644 --- a/drivers/net/pcmcia/pcnet_cs.c +++ b/drivers/net/pcmcia/pcnet_cs.c @@ -38,6 +38,7 @@ #include #include #include +#include #include <../drivers/net/8390.h> #include @@ -1483,7 +1484,8 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg, window_size = 32 * 1024; /* Make sure it's a power of two. */ - while ((window_size & (window_size - 1)) != 0) + //while ((window_size & (window_size - 1)) != 0) + while (!is_power_of_2(window_size)) window_size += window_size & ~(window_size - 1); /* Allocate a memory window */ diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index f406a2b..1399059 100644 --- a/drivers/rtc/rtc-s3c.c +++ b/drivers/rtc/rtc-s3c.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -311,7 +312,8 @@ static int s3c_rtc_ioctl(struct device *dev, case RTC_IRQP_SET: /* check for power of 2 */ - if ((arg & (arg-1)) != 0 || arg < 1) { + //if ((arg & (arg-1)) != 0 || arg < 1) { + if (!arg || !is_power_of_2(arg)) { ret = -EINVAL; goto exit; } diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h index a2cc69e..a27426c 100644 --- a/drivers/s390/block/dasd_int.h +++ b/drivers/s390/block/dasd_int.h @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -456,7 +457,8 @@ dasd_free_chunk(struct list_head *chunk_list, void *mem) static inline int dasd_check_blocksize(int bsize) { - if (bsize < 512 || bsize > 4096 || (bsize & (bsize - 1)) != 0) + //if (bsize < 512 || bsize > 4096 || (bsize & (bsize - 1)) != 0) + if (bsize < 512 || bsize > 4096 || !is_power_of_2(bsize)) return -EMEDIUMTYPE; return 0; } diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c index b3a56dc..f61be3e 100644 --- a/drivers/s390/cio/cio.c +++ b/drivers/s390/cio/cio.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -614,7 +615,7 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid) sch->schib.pmcw.isc = 3; /* could be smth. else */ sch->schib.pmcw.csense = 1; /* concurrent sense */ sch->schib.pmcw.ena = 0; - if ((sch->lpm & (sch->lpm - 1)) != 0) + if (!is_power_of_2(sch->lpm)) sch->schib.pmcw.mp = 1; /* multipath mode */ return 0; out: diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c index 51238e7..3ef2092 100644 --- a/drivers/s390/cio/device_fsm.c +++ b/drivers/s390/cio/device_fsm.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -1122,7 +1123,7 @@ device_trigger_reprobe(struct subchannel *sch) sch->schib.pmcw.isc = 3; sch->schib.pmcw.csense = 1; sch->schib.pmcw.ena = 0; - if ((sch->lpm & (sch->lpm - 1)) != 0) + if (!is_power_of_2(sch->lpm)) sch->schib.pmcw.mp = 1; sch->schib.pmcw.intparm = (__u32)(unsigned long)sch; /* We should also udate ssd info, but this has to wait. */ diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c index e16322d..4f62398 100644 --- a/drivers/video/vesafb.c +++ b/drivers/video/vesafb.c @@ -20,6 +20,7 @@ #include #include #include +#include #include