mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] include/linux/bitops.h: Fix function fns
@ 2024-04-13  6:12 Chin-Chun Chen
  2024-04-13 16:15 ` [PATCH v2] " Chin-Chun Chen
       [not found] ` <20240413155635.11486-1-chinchunchen2001@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread
From: Chin-Chun Chen @ 2024-04-13  6:12 UTC (permalink / raw)
  To: yury.norov; +Cc: linux, linux-kernel, Chin-Chun Chen

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@gmail.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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] include/linux/bitops.h: Fix function fns
  2024-04-13  6:12 [PATCH] include/linux/bitops.h: Fix function fns Chin-Chun Chen
@ 2024-04-13 16:15 ` Chin-Chun Chen
       [not found] ` <20240413155635.11486-1-chinchunchen2001@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread
From: Chin-Chun Chen @ 2024-04-13 16:15 UTC (permalink / raw)
  To: yury.norov; +Cc: linux, linux-kernel, 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.
---
Changes since v1:
* Clarified the commit message.
* Fixed the incorrect operation.

Signed-off-by: Chin-Chun Chen <chinchunchen2001@gmail.com>
---
 include/linux/bitops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 2ba557e067fe..5842d7d03f19 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -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
-- 
2.40.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] include/linux/bitops.h: Fix function fns
       [not found] ` <20240413155635.11486-1-chinchunchen2001@gmail.com>
@ 2024-04-13 17:14   ` Yury Norov
  0 siblings, 0 replies; 5+ messages in thread
From: Yury Norov @ 2024-04-13 17:14 UTC (permalink / raw)
  To: Chin-Chun Chen; +Cc: linux, linux-kernel, Chin-Chun Chen

On Sat, Apr 13, 2024 at 11:56:35PM +0800, Chin-Chun Chen wrote:
> 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?

> ---
> Changes since v1:
> * Clarified the commit message.
> * Fixed the incorrect operation.
> 
> Signed-off-by: Chin-Chun Chen <chinchunchen2001@gmail.com>
> ---
>  include/linux/bitops.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index 2ba557e067fe..5842d7d03f19 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -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

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...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] include/linux/bitops.h: Fix function fns
  2024-04-13  5:28 [PATCH] " Chin-Chun Chen
@ 2024-04-13  5:39 ` Randy Dunlap
  0 siblings, 0 replies; 5+ messages in thread
From: Randy Dunlap @ 2024-04-13  5:39 UTC (permalink / raw)
  To: Chin-Chun Chen, linux-kernel



On 4/12/24 10:28 PM, Chin-Chun Chen wrote:
> 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@gmail.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

Hi,

Please send your patch to some maintainer.
People don't browse the mailing list for patches to pick up.


-- 
#Randy
https://people.kernel.org/tglx/notes-about-netiquette
https://subspace.kernel.org/etiquette.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] include/linux/bitops.h: Fix function fns
@ 2024-04-13  5:28 Chin-Chun Chen
  2024-04-13  5:39 ` Randy Dunlap
  0 siblings, 1 reply; 5+ messages in thread
From: Chin-Chun Chen @ 2024-04-13  5:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: Chin-Chun Chen

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@gmail.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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-13 17:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-13  6:12 [PATCH] include/linux/bitops.h: Fix function fns Chin-Chun Chen
2024-04-13 16:15 ` [PATCH v2] " Chin-Chun Chen
     [not found] ` <20240413155635.11486-1-chinchunchen2001@gmail.com>
2024-04-13 17:14   ` Yury Norov
  -- strict thread matches above, loose matches on Subject: below --
2024-04-13  5:28 [PATCH] " Chin-Chun Chen
2024-04-13  5:39 ` Randy Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®