[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240413061204.10382-1-chinchunchen2001@gmail.com>
Date: Sat, 13 Apr 2024 14:12:04 +0800
From: Chin-Chun Chen <chinchunchen2001@...il.com>
To: yury.norov@...il.com
Cc: linux@...musvillemoes.dk,
linux-kernel@...r.kernel.org,
Chin-Chun Chen <chinchunchen2001@...il.com>
Subject: [PATCH] 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.
Signed-off-by: Chin-Chun Chen <chinchunchen2001@...il.com>
---
include/linux/bitops.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 2ba557e067fe..2457610f74eb 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -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
--
2.40.1
Powered by blists - more mailing lists