Skip to contentSkip to conversation

include/linux/bitops.h: Fix function fns

PATCH Superseded Chin-Chun Chen 2 participants 3 messages Apr 13, 2024 1 message not in the archive Bitops API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 include/linux/bitops.h: Fix function fns

Modified the function fns to resolve a calculation error by:
1. Reducing n first.
2. Adding 1 at the end to get the correct index.

This commit improves the accuracy and reliability of the code.

---
 include/linux/bitops.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/bitops.h +2 -2
index 2ba557e067fe..2457610f74eb 100644
@@ -258,8 +258,8 @@ static inline unsigned long fns(unsigned long word, unsigned int n)
 
 	while (word) {
 		bit = __ffs(word);
-		if (n-- == 0)
-			return bit;
+		if (--n == 0)
+			return bit + 1;
 		__clear_bit(bit, &word);
 	}
 

base-commit: 8f2c057754b25075aa3da132cd4fd4478cdab854

Signature · 1 line
2.40.1
#1 lore raw

PATCH v2 1/1 include/linux/bitops.h: Fix function fns

Modified the function fns to resolve a calculation error by reducing n first to correctly determine the n-th set bit instead of n+1.

This commit improves the accuracy and reliability of the code.
---
Changes since v1:
* Clarified the commit message.
* Fixed the incorrect operation.

---
 include/linux/bitops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/bitops.h +1 -1
index 2ba557e067fe..5842d7d03f19 100644
@@ -258,7 +258,7 @@ static inline unsigned long fns(unsigned long word, unsigned int n)
 
 	while (word) {
 		bit = __ffs(word);
-		if (n-- == 0)
+		if (--n == 0)
 			return bit;
 		__clear_bit(bit, &word);
 	}

base-commit: 8f2c057754b25075aa3da132cd4fd4478cdab854

Signature · 1 line
2.40.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#3 lore raw
Quoted 3 lines · Chin-Chun Chen

Modified the function fns to resolve a calculation error by reducing n first to correctly determine the n-th set bit instead of n+1.

This commit improves the accuracy and reliability of the code.

No it doesn't. Accuracy and reliability is tested in lib/test_bitmap.c. Have you tried to run it before sending this patch?

What error did you mean? How does pre-decrement over post-increment fix it?

Quoted 24 lines

---
Changes since v1:
* Clarified the commit message.
* Fixed the incorrect operation.

---
 include/linux/bitops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/bitops.h +1 -1
index 2ba557e067fe..5842d7d03f19 100644
@@ -258,7 +258,7 @@ static inline unsigned long fns(unsigned long word, unsigned int n)
 
 	while (word) {
 		bit = __ffs(word);
-		if (n-- == 0)
+		if (--n == 0)
 			return bit;
 		__clear_bit(bit, &word);
 	}
Quoted 1 line

base-commit: 8f2c057754b25075aa3da132cd4fd4478cdab854

What does this 'base-commit' mean?

Chin-Chun, if it's your first attempt to contribute to a public project, you're very welcome. But you have to be more descriptive on the error you're facing and trying to fix. The best practice is to provide a test together with a fix.

Thanks,
Yury

--

It may be just my paranoia after UMN and xz stories, but... I googled for this person and the email and found that it didn't appear in public domain before now. Let's see...