moving to is_power_of_2
Subsystems (19)
PATCH 1/5 moving to is_power_of_2
Removing instances of (n&(n-1)) for power of 2
check with is_power_of_2 from linux/log.h.
--- 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(-)
arch/ia64/mm/hugetlbpage.c +3 -1
@@ -16,6 +16,7 @@#include <linux/smp_lock.h> #include <linux/slab.h> #include <linux/sysctl.h> +#include <linux/log2.h> #include <asm/mman.h> #include <asm/pgalloc.h> #include <asm/tlb.h>
@@ -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" );
drivers/block/rd.c +2 -1
@@ -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 ;
drivers/md/dm-snap.c +3 -1
@@ -17,6 +17,7 @@#include <linux/module.h> #include <linux/slab.h> #include <linux/vmalloc.h> +#include <linux/log2.h> #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 ; }
drivers/net/cxgb3/cxgb3_main.c +5 -2
@@ -42,6 +42,7 @@#include <linux/workqueue.h> #include <linux/proc_fs.h> #include <linux/rtnetlink.h> +#include <linux/log2.h> #include <asm/uaccess.h> #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 */
drivers/net/pcmcia/pcnet_cs.c +3 -1
@@ -38,6 +38,7 @@#include <linux/delay.h> #include <linux/ethtool.h> #include <linux/netdevice.h> +#include <linux/log2.h> #include <../drivers/net/8390.h> #include <pcmcia/cs_types.h>
@@ -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 */
drivers/rtc/rtc-s3c.c +3 -1
@@ -20,6 +20,7 @@#include <linux/rtc.h> #include <linux/bcd.h> #include <linux/clk.h> +#include <linux/log2.h> #include <asm/hardware.h> #include <asm/uaccess.h>
@@ -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; }
drivers/s390/block/dasd_int.h +3 -1
@@ -53,6 +53,7 @@#include <linux/genhd.h> #include <linux/hdreg.h> #include <linux/interrupt.h> +#include <linux/log2.h> #include <asm/ccwdev.h> #include <linux/workqueue.h> #include <asm/debug.h>
@@ -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 ; }
drivers/s390/cio/cio.c +2 -1
@@ -15,6 +15,7 @@#include <linux/device.h> #include <linux/kernel_stat.h> #include <linux/interrupt.h> +#include <linux/log2.h> #include <asm/cio.h> #include <asm/delay.h> #include <asm/irq.h>
@@ -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:
drivers/s390/cio/device_fsm.c +2 -1
@@ -12,6 +12,7 @@#include <linux/init.h> #include <linux/jiffies.h> #include <linux/string.h> +#include <linux/log2.h> #include <asm/ccwdev.h> #include <asm/cio.h>
@@ -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. */
drivers/video/vesafb.c +3 -1
@@ -20,6 +20,7 @@#include <linux/init.h> #include <linux/platform_device.h> #include <linux/screen_info.h> +#include <linux/log2.h> #include <video/vga.h> #include <asm/io.h>
@@ -421,7 +422,8 @@ static int __init vesafb_probe(struct platform_device *dev)int rc;/* Find the largest power-of-two */ -while (temp_size & (temp_size -1 )) +//while (temp_size & (temp_size - 1)) +while (!is_power_of_2 (temp_size)) temp_size &= (temp_size -1 );/* Try and find a power of two to add */
fs/block_dev.c +3 -1
@@ -22,6 +22,7 @@#include <linux/mount.h> #include <linux/uio.h> #include <linux/namei.h> +#include <linux/log2.h> #include <asm/uaccess.h> #include "internal.h"
@@ -65,7 +66,8 @@ static void kill_bdev(struct block_device *bdev)int set_blocksize (struct block_device *bdev,int size) {/* Size must be a power of two, and between 512 and PAGE_SIZE */ -if (size >PAGE_SIZE || size <512 || (size & (size-1 ))) +//if (size > PAGE_SIZE || size < 512 || (size & (size-1))) +if (size >PAGE_SIZE || size <512 || !is_power_of_2 (size))return -EINVAL ;/* Size cannot be smaller than the size supported by the device */
fs/ext2/super.c +3 -1
@@ -29,6 +29,7 @@#include <linux/vfs.h> #include <linux/seq_file.h> #include <linux/mount.h> +#include <linux/log2.h> #include <asm/uaccess.h> #include "ext2.h" #include "xattr.h"
@@ -802,7 +803,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent) sbi->s_inode_size =le16_to_cpu (es->s_inode_size); sbi->s_first_ino =le32_to_cpu (es->s_first_ino);if ((sbi->s_inode_size <EXT2_GOOD_OLD_INODE_SIZE ) || - (sbi->s_inode_size & (sbi->s_inode_size -1 )) || +//(sbi->s_inode_size & (sbi->s_inode_size - 1)) || + !is_power_of_2 (sbi->s_inode_size) || (sbi->s_inode_size > blocksize)) {printk ("EXT2-fs: unsupported inode size: %d\n" , sbi->s_inode_size);
fs/ext3/super.c +3 -1
@@ -35,6 +35,7 @@#include <linux/namei.h> #include <linux/quotaops.h> #include <linux/seq_file.h> +#include <linux/log2.h> #include <asm/uaccess.h>
@@ -1565,7 +1566,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) sbi->s_inode_size =le16_to_cpu (es->s_inode_size); sbi->s_first_ino =le32_to_cpu (es->s_first_ino);if ((sbi->s_inode_size <EXT3_GOOD_OLD_INODE_SIZE ) || - (sbi->s_inode_size & (sbi->s_inode_size -1 )) || +//(sbi->s_inode_size & (sbi->s_inode_size - 1)) || + !is_power_of_2 (sbi->s_inode_size) || (sbi->s_inode_size > blocksize)) { printk (KERN_ERR "EXT3-fs: unsupported inode size: %d\n",
fs/ext4/super.c +5 -2
@@ -35,6 +35,7 @@#include <linux/namei.h> #include <linux/quotaops.h> #include <linux/seq_file.h> +#include <linux/log2.h> #include <asm/uaccess.h>
@@ -1624,7 +1625,8 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) sbi->s_inode_size =le16_to_cpu (es->s_inode_size); sbi->s_first_ino =le32_to_cpu (es->s_first_ino);if ((sbi->s_inode_size <EXT4_GOOD_OLD_INODE_SIZE ) || - (sbi->s_inode_size & (sbi->s_inode_size -1 )) || +//(sbi->s_inode_size & (sbi->s_inode_size - 1)) || + !is_power_of_2 (sbi->s_inode_size) || (sbi->s_inode_size > blocksize)) { printk (KERN_ERR "EXT4-fs: unsupported inode size: %d\n",
@@ -1644,7 +1646,8 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_64BIT )) {if (sbi->s_desc_size <EXT4_MIN_DESC_SIZE_64BIT || sbi->s_desc_size >EXT4_MAX_DESC_SIZE || - sbi->s_desc_size & (sbi->s_desc_size -1 )) { +//sbi->s_desc_size & (sbi->s_desc_size - 1)) { + !is_power_of_2 (sbi->s_desc_size)) {printk (KERN_ERR "EXT4-fs: unsupported descriptor size %lu\n" , sbi->s_desc_size);
fs/fat/inode.c +7 -4
@@ -25,6 +25,7 @@#include <linux/parser.h> #include <linux/uio.h> #include <linux/writeback.h> +#include <linux/log2.h> #include <asm/unaligned.h> #ifndef CONFIG_FAT_DEFAULT_IOCHARSET
@@ -1216,8 +1217,9 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, } logical_sector_size le16_to_cpu(get_unaligned((__le16 *)&b->sector_size)); -if (!logical_sector_size - || (logical_sector_size & (logical_sector_size -1 )) +//if (!logical_sector_size +// || (logical_sector_size & (logical_sector_size - 1)) +if (!is_power_of_2 (logical_sector_size) || (logical_sector_size <512 ) || (PAGE_CACHE_SIZE < logical_sector_size)) {if (!silent)
@@ -1227,8 +1229,9 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, goto out_invalid; } sbi->sec_per_clus = b->sec_per_clus; -if (!sbi->sec_per_clus - || (sbi->sec_per_clus & (sbi->sec_per_clus -1 ))) { +//if (!sbi->sec_per_clus +// || (sbi->sec_per_clus & (sbi->sec_per_clus - 1))) { +if (!is_power_of_2 (sbi->sec_per_clus)) {if (!silent)printk (KERN_ERR "FAT: bogus sectors per cluster %u\n" , sbi->sec_per_clus);
fs/hfs/btree.c +2 -1
@@ -9,6 +9,7 @@*/ #include <linux/pagemap.h> +#include <linux/log2.h> #include "btree.h"
@@ -76,7 +77,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke tree->depth =be16_to_cpu (head->depth); size = tree->node_size; -if (!size || size & (size -1 )) +if (!is_power_of_2 (size)) goto fail_page;if (!tree->node_count) goto fail_page;
fs/hfsplus/btree.c +3 -1
@@ -10,6 +10,7 @@#include <linux/slab.h> #include <linux/pagemap.h> +#include <linux/log2.h> #include "hfsplus_fs.h" #include "hfsplus_raw.h"
@@ -69,7 +70,8 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id) } size = tree->node_size; -if (!size || size & (size -1 )) +//if (!size || size & (size - 1)) +if (!is_power_of_2 (size)) goto fail_page;if (!tree->node_count) goto fail_page;
fs/nfs/internal.h +3 -2
@@ -3,7 +3,7 @@*/ #include <linux/mount.h> - +#include <linux/log2.h> struct nfs_string ;struct nfs_mount_data ;struct nfs4_mount_data ;
@@ -171,7 +171,8 @@ static inlineunsigned long nfs_block_bits (unsigned long bsize,unsigned char *nrbitsp) {/* make sure blocksize is a power of two */ -if ((bsize & (bsize -1 )) || nrbitsp) { +//if ((bsize & (bsize - 1)) || nrbitsp) { +if (!is_power_of_2 (bsize) || nrbitsp) {unsigned char nrbits;for (nrbits =31 ; nrbits && !(bsize & (1 << nrbits)); nrbits--)
fs/ntfs/inode.c +3 -1
@@ -28,6 +28,7 @@#include <linux/quotaops.h> #include <linux/slab.h> #include <linux/smp_lock.h> +#include <linux/log2.h> #include "aops.h" #include "attrib.h"
@@ -1575,7 +1576,8 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi)ntfs_debug ("Index collation rule is 0x%x." ,le32_to_cpu (ir->collation_rule)); ni->itype.index.block_size =le32_to_cpu (ir->index_block_size); -if (ni->itype.index.block_size & (ni->itype.index.block_size -1 )) { +//if (ni->itype.index.block_size & (ni->itype.index.block_size - 1)) { +if (!is_power_of_2 (ni->itype.index.block_size)) {ntfs_error (vi->i_sb,"Index block size (%u) is not a power of " "two." , ni->itype.index.block_size); goto unm_err_out;
fs/ntfs/logfile.c +3 -1
@@ -26,6 +26,7 @@#include <linux/highmem.h> #include <linux/buffer_head.h> #include <linux/bitops.h> +#include <linux/log2.h> #include "attrib.h" #include "aops.h"
@@ -65,7 +66,8 @@ static bool ntfs_check_restart_page_header(struct inode *vi, logfile_log_page_size < NTFS_BLOCK_SIZE || logfile_system_page_size & (logfile_system_page_size - 1) || - logfile_log_page_size & (logfile_log_page_size - 1)) { + //logfile_log_page_size & (logfile_log_page_size - 1)) { + !is_power_of_2(logfile_log_page_size)) {ntfs_error (vi->i_sb,"$LogFile uses unsupported page size." );return false; }
fs/ufs/super.c +5 -2
@@ -85,6 +85,7 @@#include <linux/smp_lock.h> #include <linux/buffer_head.h> #include <linux/vfs.h> +#include <linux/log2.h> #include "swab.h" #include "util.h"
@@ -850,7 +851,8 @@ magic_found: uspi->s_fmask =fs32_to_cpu (sb, usb1->fs_fmask); uspi->s_fshift =fs32_to_cpu (sb, usb1->fs_fshift); -if (uspi->s_fsize & (uspi->s_fsize -1 )) { +//if (uspi->s_fsize & (uspi->s_fsize - 1)) { +if (!is_power_of_2 (uspi->s_fsize)) {printk (KERN_ERR "ufs_read_super: fragment size %u is not a power of 2\n" , uspi->s_fsize); goto failed;
@@ -865,7 +867,8 @@ magic_found: uspi->s_fsize); goto failed; } -if (uspi->s_bsize & (uspi->s_bsize -1 )) { +//if (uspi->s_bsize & (uspi->s_bsize - 1)) { +if (!isp_power_of_2 (uspi->s_bsize)) {printk (KERN_ERR "ufs_read_super: block size %u is not a power of 2\n" , uspi->s_bsize); goto failed;
kernel/kfifo.c +3 -1
@@ -24,6 +24,7 @@#include <linux/slab.h> #include <linux/err.h> #include <linux/kfifo.h> +#include <linux/log2.h> /** * kfifo_init - allocates a new FIFO using a preallocated buffer
@@ -41,7 +42,8 @@ struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size,struct kfifo *fifo;/* size must be a power of 2 */ -BUG_ON (size & (size -1 )); +//BUG_ON(size & (size - 1)); +BUG_ON (!is_power_of_2 (size)); fifo =kmalloc (sizeof (struct kfifo ), gfp_mask);if (!fifo)
net/core/neighbour.c +3 -1
@@ -34,6 +34,7 @@#include <linux/rtnetlink.h> #include <linux/random.h> #include <linux/string.h> +#include <linux/log2.h> #define NEIGH_DEBUG 1
@@ -310,7 +311,8 @@ static void neigh_hash_grow(struct neigh_table *tbl, unsigned long new_entries)NEIGH_CACHE_STAT_INC (tbl, hash_grows); -BUG_ON (new_entries & (new_entries -1 )); +//BUG_ON(new_entries & (new_entries - 1)); +BUG_ON (!is_power_of_2 (new_entries)); new_hash =neigh_hash_alloc (new_entries);if (!new_hash)return ;
sound/core/rtctimer.c +3 -1
@@ -24,6 +24,7 @@#include <linux/init.h> #include <linux/interrupt.h> #include <linux/moduleparam.h> +#include <linux/log2.h> #include <sound/core.h> #include <sound/timer.h>
@@ -129,7 +130,8 @@ static int __init rtctimer_init(void)struct snd_timer *timer;if (rtctimer_freq <2 || rtctimer_freq >8192 || - (rtctimer_freq & (rtctimer_freq -1 )) !=0 ) { +// (rtctimer_freq & (rtctimer_freq - 1)) != 0) { + !is_power_of_2 (rtctimer_freq)) {snd_printk (KERN_ERR "rtctimer: invalid frequency %d\n" , rtctimer_freq);return -EINVAL ;
Signature · 12 lines
1.4.4.2 -- Regards, Vignesh Babu BM _____________________________________________________________ "Why is it that every time I'm with you, makes me believe in magic?" _______________________________________________ Kernel-janitors mailing list [email protected] https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 3 lines · Vignesh Babu BM
Removing instances of (n&(n-1)) for power of 2
check withis_power_of_2fromlinux/log.h.
As has been stated in this m-l before: is_power_of_2 is also non-zero.
Quoted 5 lines
Signed-off-by vignesh babu <[email protected]>---
[snip]
Quoted 14 lines
arch/ia64/mm/hugetlbpage.c +1
-0@@ -16,6 +16,7 @@#include <linux/smp_lock.h> #include <linux/slab.h> #include <linux/sysctl.h> +#include <linux/log2.h> #include <asm/mman.h> #include <asm/pgalloc.h> #include <asm/tlb.h>
arch/ia64/mm/hugetlbpage.c static int __init hugetlb_setup_sz(char *str) · line 183
Quoted 9 lines
arch/ia64/mm/hugetlbpage.c +2
-1@@ -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" );
I don't think this line is correct by the reason said above and what is the deal with the _C++_ commentary?
One of the "golden rules" with patches is: it should only doing one thing and do it right. You are only doing one thing but why comment out the line that you later delete? If I understand it correctly, you patch-serie of 5 only need to be 2. (Makes it simpler to add/remove).
cu :)
Richard Knutsson
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
G'day,
I'm not sure if you are just separating your patches out, but at a quick glance this one makes it look like a good candidate for roundup_pow_of_two()
drivers/net/pcmcia/pcnet_cs.c static int setup_shmem_window(struct pcmcia_device *link, int start_pg, · line 1489
Quoted 6 lines · Vignesh Babu BM
/* Make sure it's a power of two. */drivers/net/pcmcia/pcnet_cs.c +2
-1-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 );
and this one for a possible future rounddown_pow_of_two() (which I guess is not so interesting).
drivers/video/vesafb.c static int __init vesafb_probe(struct platform_device *dev) · line 427
Quoted 5 lines
/* Find the largest power-of-two */drivers/video/vesafb.c +2
-1-while (temp_size & (temp_size -1 )) +//while (temp_size & (temp_size - 1)) +while (!is_power_of_2 (temp_size)) temp_size &= (temp_size -1 );
Darren Jenkins
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 42 lines · Richard Knutsson
Quoted 3 lines · Vignesh Babu BM
Removing instances of (n&(n-1)) for power of 2
check withis_power_of_2fromlinux/log.h.As has been stated in this m-l before:
is_power_of_2is also non-zero.Quoted 5 lines
Signed-off-by vignesh babu <[email protected]>---
[snip]
Quoted 14 lines
arch/ia64/mm/hugetlbpage.c +1
-0@@ -16,6 +16,7 @@#include <linux/smp_lock.h> #include <linux/slab.h> #include <linux/sysctl.h> +#include <linux/log2.h> #include <asm/mman.h> #include <asm/pgalloc.h> #include <asm/tlb.h> arch/ia64/mm/hugetlbpage.c static int __init hugetlb_setup_sz(char *str) · line 183
Quoted 9 lines
arch/ia64/mm/hugetlbpage.c +2
-1@@ -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" );I don't think this line is correct by the reason said above and what is the deal with the _C++_ commentary?
One of the "golden rules" with patches is: it should only doing one thing and do it right. You are only doing one thing but why comment out the line that you later delete? If I understand it correctly, you patch-serie of 5 only need to be 2. (Makes it simpler to add/remove).
Quoted 3 lines
cu :)
Richard Knutsson
Working on the cleanup...just a quick clarification....
size <= PAGE_SIZE will result in true when size=0
is that not the same that happens when we run !is_power_of_2(size) when size=0?
Signature · 8 lines
Regards, Vignesh Babu BM _____________________________________________________________ "Why is it that every time I'm with you, makes me believe in magic?" _______________________________________________ Kernel-janitors mailing list [email protected] https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 17 lines · Darren Jenkins
G'day,
I'm not sure if you are just separating your patches out, but at a quick glance this one makes it look like a good candidate for
roundup_pow_of_two()drivers/net/pcmcia/pcnet_cs.c static int setup_shmem_window(struct pcmcia_device *link, int start_pg, · line 1489
Quoted 6 lines · Vignesh Babu BM
/* Make sure it's a power of two. */drivers/net/pcmcia/pcnet_cs.c +2
-1-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 );and this one for a possible future
rounddown_pow_of_two()(which I guess is not so interesting).
Quoted 8 lines
drivers/video/vesafb.c static int __init vesafb_probe(struct platform_device *dev) · line 427
Quoted 5 lines
/* Find the largest power-of-two */drivers/video/vesafb.c +2
-1-while (temp_size & (temp_size -1 )) +//while (temp_size & (temp_size - 1)) +while (!is_power_of_2 (temp_size)) temp_size &= (temp_size -1 );Darren Jenkins
Thnks...Darren. I 'am' creating another patch for round up.
Signature · 8 lines
Regards, Vignesh Babu BM _____________________________________________________________ "Why is it that every time I'm with you, makes me believe in magic?" _______________________________________________ Kernel-janitors mailing list [email protected] https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 24 lines · Vignesh Babu BM
Removing instances of (n&(n-1)) for power of 2
check withis_power_of_2fromlinux/log.h.Signed-off-by vignesh babu <[email protected]>--- 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 +++-
Quoted 8 lines
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(-)
you're better off submitting these patches a subsystem at a time, and CCing the subsystem maintainer on each patch, rather than trying to do all this at once.
Quoted 13 lines
arch/ia64/mm/hugetlbpage.c +1
-0@@ -16,6 +16,7 @@#include <linux/smp_lock.h> #include <linux/slab.h> #include <linux/sysctl.h> +#include <linux/log2.h> #include <asm/mman.h> #include <asm/pgalloc.h> #include <asm/tlb.h>
arch/ia64/mm/hugetlbpage.c static int __init hugetlb_setup_sz(char *str) · line 180
Quoted 6 lines
arch/ia64/mm/hugetlbpage.c +2
-1@@ -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) ||
why are you retaining the original line in the source file, and just commenting it out?
rday
Signature · 11 lines
==================================== Robert P. J. Day Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA http://fsdev.net/wiki/index.php?title=Main_Page ==================================== _______________________________________________ Kernel-janitors mailing list [email protected] https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 14 lines · Darren Jenkins
G'day,
I'm not sure if you are just separating your patches out, but at a quick glance this one makes it look like a good candidate for
roundup_pow_of_two()drivers/net/pcmcia/pcnet_cs.c static int setup_shmem_window(struct pcmcia_device *link, int start_pg, · line 1489
Quoted 6 lines · Vignesh Babu BM
/* Make sure it's a power of two. */drivers/net/pcmcia/pcnet_cs.c +2
-1-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 );
Quoted 8 lines
and this one for a possible future
rounddown_pow_of_two()(which I guess is not so interesting).Quoted 5 lines
/* Find the largest power-of-two */drivers/video/vesafb.c +2
-1-while (temp_size & (temp_size -1 )) +//while (temp_size & (temp_size - 1)) +while (!is_power_of_2 (temp_size)) temp_size &= (temp_size -1 );
correct observation -- i specifically suggested on the wiki page:
http://fsdev.net/wiki/index.php?title=Power_of_2_stuff
*not* to make changes that represented rounding.
rday
Signature · 11 lines
==================================== Robert P. J. Day Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA http://fsdev.net/wiki/index.php?title=Main_Page ==================================== _______________________________________________ Kernel-janitors mailing list [email protected] https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 25 lines · Vignesh Babu BM
Quoted 24 lines · Darren Jenkins
G'day,
I'm not sure if you are just separating your patches out, but at a quick glance this one makes it look like a good candidate for
roundup_pow_of_two()drivers/net/pcmcia/pcnet_cs.c static int setup_shmem_window(struct pcmcia_device *link, int start_pg, · line 1489
Quoted 6 lines · Vignesh Babu BM
/* Make sure it's a power of two. */drivers/net/pcmcia/pcnet_cs.c +2
-1-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 );and this one for a possible future
rounddown_pow_of_two()(which I guess is not so interesting).Quoted 5 lines
/* Find the largest power-of-two */drivers/video/vesafb.c +2
-1-while (temp_size & (temp_size -1 )) +//while (temp_size & (temp_size - 1)) +while (!is_power_of_2 (temp_size)) temp_size &= (temp_size -1 );
Quoted 3 lines
Quoted 1 line
Darren Jenkins
Thnks...Darren. I 'am' creating another patch for round up.
as a suggestion, don't start on trying to clean the roundup stuff until you're finished with the power of 2 tests.
rday
Signature · 11 lines
==================================== Robert P. J. Day Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA http://fsdev.net/wiki/index.php?title=Main_Page ==================================== _______________________________________________ Kernel-janitors mailing list [email protected] https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 20 lines · Vignesh Babu BM
Quoted 18 lines · Richard Knutsson
arch/ia64/mm/hugetlbpage.c static int __init hugetlb_setup_sz(char *str) · line 183
Quoted 9 lines · Vignesh Babu BM
arch/ia64/mm/hugetlbpage.c +2
-1size =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" );I don't think this line is correct by the reason said above and what is the deal with the _C++_ commentary?
One of the "golden rules" with patches is: it should only doing one thing and do it right. You are only doing one thing but why comment out the line that you later delete? If I understand it correctly, you patch-serie of 5 only need to be 2. (Makes it simpler to add/remove).
Quoted 6 lines
Working on the cleanup...just a quick clarification....
size <=PAGE_SIZEwill result in true when size=0
is that not the same that happens when we run !is_power_of_2(size) when size=0?
Yes, the result (I think) will be the same, but (size & (size-1)) is 0 when size = 0, while !is_power_of_2(0) is true (1). So can you say (size & (size-1)) was intended as !is_power_of_2?
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 6 lines · Richard Knutsson
Quoted 5 lines · Vignesh Babu BM
Quoted 3 lines · Richard Knutsson
Quoted 1 line · Vignesh Babu BM
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines
arch/ia64/mm/hugetlbpage.c static int __init hugetlb_setup_sz(char *str) · line 183
Quoted 8 lines
arch/ia64/mm/hugetlbpage.c +2
-1size =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" );Yes, the result (I think) will be the same, but (size & (size-1)) is 0 when size = 0, while !is_power_of_2(0) is true (1). So can you say (size & (size-1)) was intended as !is_power_of_2?
In this context I'm sure that's the reason to have (size & (size-1))
Anyway...Im sending in the new ones with changes suggested by you and rday and cc'd to the maintainers...so that should clear up and probabbly uncover more issues ;)
Signature · 8 lines
Regards, Vignesh Babu BM _____________________________________________________________ "Why is it that every time I'm with you, makes me believe in magic?" _______________________________________________ Kernel-janitors mailing list [email protected] https://lists.osdl.org/mailman/listinfo/kernel-janitors