lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1ce341045ad0487c66ca21003f9974916aba0bce.1767975412.git.ptesarik@suse.com>
Date: Fri,  9 Jan 2026 17:37:57 +0100
From: Petr Tesarik <ptesarik@...e.com>
To: Yury Norov <yury.norov@...il.com>,
	Rasmus Villemoes <linux@...musvillemoes.dk>
Cc: Richard Henderson <richard.henderson@...aro.org>,
	Matt Turner <mattst88@...il.com>,
	Magnus Lindholm <linmag7@...il.com>,
	Vineet Gupta <vgupta@...nel.org>,
	Geert Uytterhoeven <geert@...ux-m68k.org>,
	"Maciej W. Rozycki" <macro@...am.me.uk>,
	Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
	Madhavan Srinivasan <maddy@...ux.ibm.com>,
	Michael Ellerman <mpe@...erman.id.au>,
	Heiko Carstens <hca@...ux.ibm.com>,
	Vasily Gorbik <gor@...ux.ibm.com>,
	Alexander Gordeev <agordeev@...ux.ibm.com>,
	Chris Zankel <chris@...kel.net>,
	Max Filippov <jcmvbkbc@...il.com>,
	Patrik Jakobsson <patrik.r.jakobsson@...il.com>,
	Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
	Maxime Ripard <mripard@...nel.org>,
	Thomas Zimmermann <tzimmermann@...e.de>,
	David Airlie <airlied@...il.com>,
	Simona Vetter <simona@...ll.ch>,
	Robin Murphy <robin.murphy@....com>,
	Joerg Roedel <joro@...tes.org>,
	Will Deacon <will@...nel.org>,
	Jakub Kicinski <kuba@...nel.org>,
	Andrew Lunn <andrew+netdev@...n.ch>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Paolo Abeni <pabeni@...hat.com>,
	Oliver Neukum <oliver@...kum.org>,
	Arnd Bergmann <arnd@...db.de>,
	Kuan-Wei Chiu <visitorckw@...il.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Marcel Holtmann <marcel@...tmann.org>,
	Johan Hedberg <johan.hedberg@...il.com>,
	Luiz Augusto von Dentz <luiz.dentz@...il.com>,
	Pablo Neira Ayuso <pablo@...filter.org>,
	Florian Westphal <fw@...len.de>,
	linux-kernel@...r.kernel.org,
	Petr Tesarik <ptesarik@...e.com>
Subject: [RFC PATCH 2/2] treewide, bits: use ffs_val() where it is open-coded

Replace the open-coded bit-twiddling trick to get the least significant bit
with a call to ffs_val().

This patch has been generated by the following coccinelle script:

  @
  depends on !(file in "include/asm-generic/bitops/ffs_val.h")
	  && !(file in "tools/")
  @
  expression E;
  @@

  - ((E) & (-(E)))
  + ffs_val(E)

Include <linux/ffs_val.h> where the result did not build.

Signed-off-by: Petr Tesarik <ptesarik@...e.com>
---
 arch/alpha/include/asm/bitops.h              |  2 +-
 arch/alpha/kernel/core_cia.c                 |  2 +-
 arch/alpha/kernel/smp.c                      |  2 +-
 arch/arc/include/asm/bitops.h                |  2 +-
 arch/m68k/include/asm/bitops.h               | 12 ++++++------
 arch/mips/dec/ecc-berr.c                     |  2 +-
 arch/mips/include/asm/bitops.h               |  4 ++--
 arch/mips/pci/pci-malta.c                    |  4 ++--
 arch/powerpc/include/asm/bitops.h            |  4 ++--
 arch/powerpc/kvm/e500_mmu_host.c             |  2 +-
 arch/powerpc/lib/sstep.c                     |  2 +-
 arch/powerpc/xmon/ppc-dis.c                  |  3 ++-
 arch/powerpc/xmon/ppc-opc.c                  |  6 +++---
 arch/s390/include/asm/bitops.h               |  2 +-
 arch/xtensa/include/asm/bitops.h             |  6 +++---
 arch/xtensa/kernel/traps.c                   |  2 +-
 drivers/gpu/drm/gma500/psb_intel_sdvo.c      |  2 +-
 drivers/iommu/dma-iommu.c                    |  2 +-
 drivers/net/ethernet/netronome/nfp/bpf/jit.c |  2 +-
 drivers/net/usb/cdc_ncm.c                    |  4 ++--
 include/asm-generic/div64.h                  |  4 ++--
 include/linux/bitfield.h                     |  3 ++-
 include/linux/log2.h                         |  2 +-
 include/linux/min_heap.h                     |  5 +++--
 lib/math/gcd.c                               |  4 ++--
 lib/sort.c                                   |  3 ++-
 net/bluetooth/mgmt.c                         |  2 +-
 net/netfilter/nft_set_pipapo.c               |  2 +-
 28 files changed, 48 insertions(+), 44 deletions(-)

diff --git a/arch/alpha/include/asm/bitops.h b/arch/alpha/include/asm/bitops.h
index 76e4343c090f7..590e25862192f 100644
--- a/arch/alpha/include/asm/bitops.h
+++ b/arch/alpha/include/asm/bitops.h
@@ -317,7 +317,7 @@ static inline unsigned long ffz_b(unsigned long x)
 {
 	unsigned long sum, x1, x2, x4;
 
-	x = ~x & -~x;		/* set first 0 bit, clear others */
+	x = ffs_val(~x);	/* set first 0 bit, clear others */
 	x1 = x & 0xAA;
 	x2 = x & 0xCC;
 	x4 = x & 0xF0;
diff --git a/arch/alpha/kernel/core_cia.c b/arch/alpha/kernel/core_cia.c
index 6e577228e175d..b3c273c13c104 100644
--- a/arch/alpha/kernel/core_cia.c
+++ b/arch/alpha/kernel/core_cia.c
@@ -1035,7 +1035,7 @@ cia_decode_ecc_error(struct el_CIA_sysdata_mcheck *cia, const char *msg)
 	cia_decode_mem_error(cia, msg);
 
 	syn = cia->cia_syn & 0xff;
-	if (syn == (syn & -syn)) {
+	if (syn == ffs_val(syn)) {
 		fmt = KERN_CRIT "  ECC syndrome %#x -- check bit %d\n";
 		i = ffs(syn) - 1;
 	} else {
diff --git a/arch/alpha/kernel/smp.c b/arch/alpha/kernel/smp.c
index ed06367ece574..2f3809c015b99 100644
--- a/arch/alpha/kernel/smp.c
+++ b/arch/alpha/kernel/smp.c
@@ -525,7 +525,7 @@ handle_ipi(struct pt_regs *regs)
 	  do {
 		unsigned long which;
 
-		which = ops & -ops;
+		which = ffs_val(ops);
 		ops &= ~which;
 		which = __ffs(which);
 
diff --git a/arch/arc/include/asm/bitops.h b/arch/arc/include/asm/bitops.h
index df894235fdbc6..def870bd7e4c7 100644
--- a/arch/arc/include/asm/bitops.h
+++ b/arch/arc/include/asm/bitops.h
@@ -94,7 +94,7 @@ static inline __attribute__ ((const)) unsigned long __fls(unsigned long x)
  * ffs = Find First Set in word (LSB to MSB)
  * @result: [1-32], 0 if all 0's
  */
-#define ffs(x)	({ unsigned long __t = (x); fls(__t & -__t); })
+#define ffs(x)	({ unsigned long __t = (x); fls(ffs_val(__t)); })
 
 /*
  * __ffs: Similar to ffs, but zero based (0-31)
diff --git a/arch/m68k/include/asm/bitops.h b/arch/m68k/include/asm/bitops.h
index e9639e48c6c3c..a67f08b8a7541 100644
--- a/arch/m68k/include/asm/bitops.h
+++ b/arch/m68k/include/asm/bitops.h
@@ -368,7 +368,7 @@ static inline unsigned long find_first_zero_bit(const unsigned long *vaddr,
 	}
 
 	__asm__ __volatile__ ("bfffo %1{#0,#0},%0"
-			      : "=d" (res) : "d" (num & -num));
+			      : "=d" (res) : "d" (ffs_val(num)));
 	res ^= 31;
 out:
 	res += ((long)p - (long)vaddr - 4) * 8;
@@ -392,7 +392,7 @@ static inline unsigned long find_next_zero_bit(const unsigned long *vaddr,
 
 		/* Look for zero in first longword */
 		__asm__ __volatile__ ("bfffo %1{#0,#0},%0"
-				      : "=d" (res) : "d" (num & -num));
+				      : "=d" (res) : "d" (ffs_val(num)));
 		if (res < 32) {
 			offset += res ^ 31;
 			return offset < size ? offset : size;
@@ -425,7 +425,7 @@ static inline unsigned long find_first_bit(const unsigned long *vaddr,
 	}
 
 	__asm__ __volatile__ ("bfffo %1{#0,#0},%0"
-			      : "=d" (res) : "d" (num & -num));
+			      : "=d" (res) : "d" (ffs_val(num)));
 	res ^= 31;
 out:
 	res += ((long)p - (long)vaddr - 4) * 8;
@@ -449,7 +449,7 @@ static inline unsigned long find_next_bit(const unsigned long *vaddr,
 
 		/* Look for one in first longword */
 		__asm__ __volatile__ ("bfffo %1{#0,#0},%0"
-				      : "=d" (res) : "d" (num & -num));
+				      : "=d" (res) : "d" (ffs_val(num)));
 		if (res < 32) {
 			offset += res ^ 31;
 			return offset < size ? offset : size;
@@ -473,7 +473,7 @@ static inline unsigned long __attribute_const__ ffz(unsigned long word)
 	int res;
 
 	__asm__ __volatile__ ("bfffo %1{#0,#0},%0"
-			      : "=d" (res) : "d" (~word & -~word));
+			      : "=d" (res) : "d" (ffs_val(~word)));
 	return res ^ 31;
 }
 
@@ -527,7 +527,7 @@ static inline __attribute_const__ int ffs(int x)
 
 	__asm__ ("bfffo %1{#0:#0},%0"
 		: "=d" (cnt)
-		: "dm" (x & -x));
+		: "dm" (ffs_val(x)));
 	return 32 - cnt;
 }
 
diff --git a/arch/mips/dec/ecc-berr.c b/arch/mips/dec/ecc-berr.c
index 1eb356fdd8323..8934b8b1cf375 100644
--- a/arch/mips/dec/ecc-berr.c
+++ b/arch/mips/dec/ecc-berr.c
@@ -153,7 +153,7 @@ static int dec_ecc_be_backend(struct pt_regs *regs, int is_fixup, int invoker)
 			/* Ack now, now we've rewritten (or not). */
 			dec_ecc_be_ack();
 
-			if (syn && syn == (syn & -syn)) {
+			if (syn && syn == ffs_val(syn)) {
 				if (syn == 0x01) {
 					fmt = KERN_ALERT "%s"
 					      "%#04x -- %s bit error "
diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h
index 42f88452c920f..6e71999618876 100644
--- a/arch/mips/include/asm/bitops.h
+++ b/arch/mips/include/asm/bitops.h
@@ -395,7 +395,7 @@ static __always_inline __attribute_const__ unsigned long __fls(unsigned long wor
  */
 static __always_inline __attribute_const__ unsigned long __ffs(unsigned long word)
 {
-	return __fls(word & -word);
+	return __fls(ffs_val(word));
 }
 
 /*
@@ -463,7 +463,7 @@ static inline __attribute_const__ int ffs(int word)
 	if (!word)
 		return 0;
 
-	return fls(word & -word);
+	return fls(ffs_val(word));
 }
 
 #include <asm-generic/bitops/ffz.h>
diff --git a/arch/mips/pci/pci-malta.c b/arch/mips/pci/pci-malta.c
index 2e35aeba45bc1..502f99f46eb75 100644
--- a/arch/mips/pci/pci-malta.c
+++ b/arch/mips/pci/pci-malta.c
@@ -117,7 +117,7 @@ void __init mips_pcibios_init(void)
 		mask = ~(start ^ end);
 		/* We don't support remapping with a discontiguous mask.  */
 		BUG_ON((start & GT_PCI_HD_MSK) != (map & GT_PCI_HD_MSK) &&
-		       mask != ~((mask & -mask) - 1));
+		       mask != ~(ffs_val(mask) - 1));
 		gt64120_mem_resource.start = start;
 		gt64120_mem_resource.end = end;
 		gt64120_controller.mem_offset = (start & mask) - (map & mask);
@@ -134,7 +134,7 @@ void __init mips_pcibios_init(void)
 		mask = ~(start ^ end);
 		/* We don't support remapping with a discontiguous mask.  */
 		BUG_ON((start & GT_PCI_HD_MSK) != (map & GT_PCI_HD_MSK) &&
-		       mask != ~((mask & -mask) - 1));
+		       mask != ~(ffs_val(mask) - 1));
 		gt64120_io_resource.start = map & mask;
 		gt64120_io_resource.end = (map & mask) | ~mask;
 		gt64120_controller.io_offset = 0;
diff --git a/arch/powerpc/include/asm/bitops.h b/arch/powerpc/include/asm/bitops.h
index 0d0470cd5ac31..571700bb41e46 100644
--- a/arch/powerpc/include/asm/bitops.h
+++ b/arch/powerpc/include/asm/bitops.h
@@ -87,8 +87,8 @@ static __always_inline bool is_rlwinm_mask_valid(unsigned long x)
 	if (!x)
 		return false;
 	if (x & 1)
-		x = ~x;	// make the mask non-wrapping
-	x += x & -x;	// adding the low set bit results in at most one bit set
+		x = ~x;		// make the mask non-wrapping
+	x += ffs_val(x);	// adding the low set bit results in at most one bit set
 
 	return !(x & (x - 1));
 }
diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c
index 06caf8bbbe2b7..00ae88b3369fd 100644
--- a/arch/powerpc/kvm/e500_mmu_host.c
+++ b/arch/powerpc/kvm/e500_mmu_host.c
@@ -205,7 +205,7 @@ void inval_gtlbe_on_host(struct kvmppc_vcpu_e500 *vcpu_e500, int tlbsel,
 
 		local_irq_save(flags);
 		while (tmp) {
-			hw_tlb_indx = __ilog2_u64(tmp & -tmp);
+			hw_tlb_indx = __ilog2_u64(ffs_val(tmp));
 			mtspr(SPRN_MAS0,
 			      MAS0_TLBSEL(1) |
 			      MAS0_ESEL(to_htlb1_esel(hw_tlb_indx)));
diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index ac3ee19531d8a..2a8a7e007dbd2 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -236,7 +236,7 @@ static nokprobe_inline unsigned long mlsd_8lsd_ea(unsigned int instr,
 static nokprobe_inline unsigned long max_align(unsigned long x)
 {
 	x |= sizeof(unsigned long);
-	return x & -x;		/* isolates rightmost bit */
+	return ffs_val(x);		/* isolates rightmost bit */
 }
 
 static nokprobe_inline unsigned long byterev_2(unsigned long x)
diff --git a/arch/powerpc/xmon/ppc-dis.c b/arch/powerpc/xmon/ppc-dis.c
index af105e1bc3fca..13b31964686ad 100644
--- a/arch/powerpc/xmon/ppc-dis.c
+++ b/arch/powerpc/xmon/ppc-dis.c
@@ -9,6 +9,7 @@ This file is part of GDB, GAS, and the GNU binutils.
 
 #include <asm/cputable.h>
 #include <asm/cpu_has_feature.h>
+#include <linux/ffs_val.h>
 #include "nonstdio.h"
 #include "ansidecl.h"
 #include "ppc.h"
@@ -44,7 +45,7 @@ operand_value_powerpc (const struct powerpc_operand *operand,
 	  unsigned long top = operand->bitm;
 	  /* top & -top gives the rightmost 1 bit, so this
 	     fills in any trailing zeros.  */
-	  top |= (top & -top) - 1;
+	  top |= ffs_val(top) - 1;
 	  top &= ~(top >> 1);
 	  value = (value ^ top) - top;
 	}
diff --git a/arch/powerpc/xmon/ppc-opc.c b/arch/powerpc/xmon/ppc-opc.c
index de9b4236728c4..23d845439fa11 100644
--- a/arch/powerpc/xmon/ppc-opc.c
+++ b/arch/powerpc/xmon/ppc-opc.c
@@ -1417,7 +1417,7 @@ insert_fxm (unsigned long insn,
      one bit of the mask field is set.  */
   if ((insn & (1 << 20)) != 0)
     {
-      if (value == 0 || (value & -value) != value)
+      if (value == 0 || ffs_val(value) != value)
 	{
 	  *errmsg = _("invalid mask field");
 	  value = 0;
@@ -1430,7 +1430,7 @@ insert_fxm (unsigned long insn,
      new form unless -mpower4 has been given, or -many and the two
      operand form of mfcr was used.  */
   else if (value > 0
-	   && (value & -value) == value
+	   && ffs_val(value) == value
 	   && ((dialect & PPC_OPCODE_POWER4) != 0
 	       || ((dialect & PPC_OPCODE_ANY) != 0
 		   && (insn & (0x3ff << 1)) == 19 << 1)))
@@ -1460,7 +1460,7 @@ extract_fxm (unsigned long insn,
   if ((insn & (1 << 20)) != 0)
     {
       /* Exactly one bit of MASK should be set.  */
-      if (mask == 0 || (mask & -mask) != mask)
+      if (mask == 0 || ffs_val(mask) != mask)
 	*invalid = 1;
     }
 
diff --git a/arch/s390/include/asm/bitops.h b/arch/s390/include/asm/bitops.h
index 5f10074665b0c..dadd8a5bd5428 100644
--- a/arch/s390/include/asm/bitops.h
+++ b/arch/s390/include/asm/bitops.h
@@ -193,7 +193,7 @@ static __always_inline __flatten __attribute_const__ int ffs(int word)
 {
 	unsigned int val = (unsigned int)word;
 
-	return BITS_PER_LONG - __flogr(-val & val);
+	return BITS_PER_LONG - __flogr(ffs_val(val));
 }
 
 #else /* CONFIG_CC_HAS_BUILTIN_FFS */
diff --git a/arch/xtensa/include/asm/bitops.h b/arch/xtensa/include/asm/bitops.h
index f7390b6761e1b..44e0debde1b3d 100644
--- a/arch/xtensa/include/asm/bitops.h
+++ b/arch/xtensa/include/asm/bitops.h
@@ -39,7 +39,7 @@ static inline unsigned long __cntlz (unsigned long x)
 
 static inline int __attribute_const__ ffz(unsigned long x)
 {
-	return 31 - __cntlz(~x & -~x);
+	return 31 - __cntlz(ffs_val(~x));
 }
 
 /*
@@ -48,7 +48,7 @@ static inline int __attribute_const__ ffz(unsigned long x)
 
 static inline __attribute_const__ unsigned long __ffs(unsigned long x)
 {
-	return 31 - __cntlz(x & -x);
+	return 31 - __cntlz(ffs_val(x));
 }
 
 /*
@@ -59,7 +59,7 @@ static inline __attribute_const__ unsigned long __ffs(unsigned long x)
 
 static inline __attribute_const__ int ffs(unsigned long x)
 {
-	return 32 - __cntlz(x & -x);
+	return 32 - __cntlz(ffs_val(x));
 }
 
 /*
diff --git a/arch/xtensa/kernel/traps.c b/arch/xtensa/kernel/traps.c
index 44c07c4e0833a..7ab71b21581f5 100644
--- a/arch/xtensa/kernel/traps.c
+++ b/arch/xtensa/kernel/traps.c
@@ -309,7 +309,7 @@ static void do_interrupt(struct pt_regs *regs)
 			break;
 
 		/* clear lowest pending irq in the unhandled mask */
-		unhandled ^= (int_at_level & -int_at_level);
+		unhandled ^= ffs_val(int_at_level);
 		do_IRQ(__ffs(int_at_level), regs);
 	}
 
diff --git a/drivers/gpu/drm/gma500/psb_intel_sdvo.c b/drivers/gpu/drm/gma500/psb_intel_sdvo.c
index 553e7c7d9bb83..56d3fa0bd0334 100644
--- a/drivers/gpu/drm/gma500/psb_intel_sdvo.c
+++ b/drivers/gpu/drm/gma500/psb_intel_sdvo.c
@@ -1226,7 +1226,7 @@ psb_intel_sdvo_multifunc_encoder(struct psb_intel_sdvo *psb_intel_sdvo)
 {
 	/* Is there more than one type of output? */
 	int caps = psb_intel_sdvo->caps.output_flags & 0xf;
-	return caps & -caps;
+	return ffs_val(caps);
 }
 
 static struct edid *
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index c92088855450a..a0211b51d8043 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -943,7 +943,7 @@ static struct page **__iommu_dma_alloc_noncontiguous(struct device *dev,
 	    iommu_deferred_attach(dev, domain))
 		return NULL;
 
-	min_size = alloc_sizes & -alloc_sizes;
+	min_size = ffs_val(alloc_sizes);
 	if (min_size < PAGE_SIZE) {
 		min_size = PAGE_SIZE;
 		alloc_sizes |= PAGE_SIZE;
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/jit.c b/drivers/net/ethernet/netronome/nfp/bpf/jit.c
index 3a02eef58cc6d..25e0905a61721 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/jit.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/jit.c
@@ -1565,7 +1565,7 @@ static int wrp_div_imm(struct nfp_prog *nfp_prog, u8 dst, u64 imm)
 	rvalue = reciprocal_value_adv(imm, 32);
 	exp = rvalue.exp;
 	if (rvalue.is_wide_m && !(imm & 1)) {
-		pre_shift = fls(imm & -imm) - 1;
+		pre_shift = fls(ffs_val(imm)) - 1;
 		rvalue = reciprocal_value_adv(imm >> pre_shift, 32 - pre_shift);
 	} else {
 		pre_shift = 0;
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 5d123df0a866b..e132f222a026a 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -668,7 +668,7 @@ static void cdc_ncm_fix_modulus(struct usbnet *dev)
 	val = ctx->tx_ndp_modulus;
 
 	if ((val < USB_CDC_NCM_NDP_ALIGN_MIN_SIZE) ||
-	    (val != ((-val) & val)) || (val >= ctx->tx_max)) {
+	    (val != ffs_val(val)) || (val >= ctx->tx_max)) {
 		dev_dbg(&dev->intf->dev, "Using default alignment: 4 bytes\n");
 		ctx->tx_ndp_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE;
 	}
@@ -682,7 +682,7 @@ static void cdc_ncm_fix_modulus(struct usbnet *dev)
 	val = ctx->tx_modulus;
 
 	if ((val < USB_CDC_NCM_NDP_ALIGN_MIN_SIZE) ||
-	    (val != ((-val) & val)) || (val >= ctx->tx_max)) {
+	    (val != ffs_val(val)) || (val >= ctx->tx_max)) {
 		dev_dbg(&dev->intf->dev, "Using default transmit modulus: 4 bytes\n");
 		ctx->tx_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE;
 	}
diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h
index 25e7b4b58dcf5..d56208be887de 100644
--- a/include/asm-generic/div64.h
+++ b/include/asm-generic/div64.h
@@ -111,8 +111,8 @@
 	}								\
 									\
 	/* Reduce m / p to help avoid overflow handling later. */	\
-	___p /= (___m & -___m);						\
-	___m /= (___m & -___m);						\
+	___p /= ffs_val(___m);						\
+	___m /= ffs_val(___m);						\
 									\
 	/*								\
 	 * Perform (m_bias + m * n) / (1 << 64).			\
diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h
index 126dc5b380afa..26fbb6cfc0719 100644
--- a/include/linux/bitfield.h
+++ b/include/linux/bitfield.h
@@ -8,6 +8,7 @@
 #define _LINUX_BITFIELD_H
 
 #include <linux/build_bug.h>
+#include <linux/ffs_val.h>
 #include <linux/typecheck.h>
 #include <asm/byteorder.h>
 
@@ -202,7 +203,7 @@ static __always_inline u64 field_multiplier(u64 field)
 {
 	if ((field | (field - 1)) & ((field | (field - 1)) + 1))
 		__bad_mask();
-	return field & -field;
+	return ffs_val(field);
 }
 static __always_inline u64 field_mask(u64 field)
 {
diff --git a/include/linux/log2.h b/include/linux/log2.h
index 2eac3fc9303d6..7615e513885e9 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -266,7 +266,7 @@ int __bits_per(unsigned long n)
 static inline __attribute__((const))
 unsigned int max_pow_of_two_factor(unsigned int n)
 {
-	return n & -n;
+	return ffs_val(n);
 }
 
 #endif /* _LINUX_LOG2_H */
diff --git a/include/linux/min_heap.h b/include/linux/min_heap.h
index 79ddc0adbf2bf..e914919470c88 100644
--- a/include/linux/min_heap.h
+++ b/include/linux/min_heap.h
@@ -3,6 +3,7 @@
 #define _LINUX_MIN_HEAP_H
 
 #include <linux/bug.h>
+#include <linux/ffs_val.h>
 #include <linux/string.h>
 #include <linux/types.h>
 
@@ -257,7 +258,7 @@ static __always_inline
 void __min_heap_sift_down_inline(min_heap_char *heap, size_t pos, size_t elem_size,
 				 const struct min_heap_callbacks *func, void *args)
 {
-	const unsigned long lsbit = elem_size & -elem_size;
+	const unsigned long lsbit = ffs_val(elem_size);
 	void *data = heap->data;
 	void (*swp)(void *lhs, void *rhs, void *args) = func->swp;
 	/* pre-scale counters for performance */
@@ -297,7 +298,7 @@ static __always_inline
 void __min_heap_sift_up_inline(min_heap_char *heap, size_t elem_size, size_t idx,
 			       const struct min_heap_callbacks *func, void *args)
 {
-	const unsigned long lsbit = elem_size & -elem_size;
+	const unsigned long lsbit = ffs_val(elem_size);
 	void *data = heap->data;
 	void (*swp)(void *lhs, void *rhs, void *args) = func->swp;
 	/* pre-scale counters for performance */
diff --git a/lib/math/gcd.c b/lib/math/gcd.c
index 62efca6787aef..3706c84e68bc1 100644
--- a/lib/math/gcd.c
+++ b/lib/math/gcd.c
@@ -23,12 +23,12 @@ static unsigned long binary_gcd(unsigned long a, unsigned long b)
 
 	b >>= __ffs(b);
 	if (b == 1)
-		return r & -r;
+		return ffs_val(r);
 
 	for (;;) {
 		a >>= __ffs(a);
 		if (a == 1)
-			return r & -r;
+			return ffs_val(r);
 		if (a == b)
 			return a << __ffs(r);
 
diff --git a/lib/sort.c b/lib/sort.c
index 52363995ccc5c..2489aaaa21a06 100644
--- a/lib/sort.c
+++ b/lib/sort.c
@@ -12,6 +12,7 @@
 
 #include <linux/types.h>
 #include <linux/export.h>
+#include <linux/ffs_val.h>
 #include <linux/sort.h>
 
 /**
@@ -196,7 +197,7 @@ static void __sort_r(void *base, size_t num, size_t size,
 {
 	/* pre-scale counters for performance */
 	size_t n = num * size, a = (num/2) * size;
-	const unsigned int lsbit = size & -size;  /* Used to find parent */
+	const unsigned int lsbit = ffs_val(size);  /* Used to find parent */
 	size_t shift = 0;
 
 	if (!a)		/* num < 2 || size == 0 */
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 5be9b8c919490..2b13998fdb0fe 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -8664,7 +8664,7 @@ static bool requested_adv_flags_are_valid(struct hci_dev *hdev, u32 adv_flags)
 	supported_flags = get_supported_adv_flags(hdev);
 	phy_flags = adv_flags & MGMT_ADV_FLAG_SEC_MASK;
 	if (adv_flags & ~supported_flags ||
-	    ((phy_flags && (phy_flags ^ (phy_flags & -phy_flags)))))
+	    ((phy_flags && (phy_flags ^ ffs_val(phy_flags)))))
 		return false;
 
 	return true;
diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c
index 112fe46788b6f..f93f509cc3fbf 100644
--- a/net/netfilter/nft_set_pipapo.c
+++ b/net/netfilter/nft_set_pipapo.c
@@ -370,7 +370,7 @@ int pipapo_refill(unsigned long *map, unsigned int len, unsigned int rules,
 	for (k = 0; k < len; k++) {
 		bitset = map[k];
 		while (bitset) {
-			unsigned long t = bitset & -bitset;
+			unsigned long t = ffs_val(bitset);
 			int r = __builtin_ctzl(bitset);
 			int i = k * BITS_PER_LONG + r;
 
-- 
2.52.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ