public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] lib: glob: add explicit include for export.h
@ 2026-03-01 15:21 Josh Law
  2026-03-01 15:21 ` [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean Josh Law
  0 siblings, 1 reply; 9+ messages in thread
From: Josh Law @ 2026-03-01 15:21 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Josh Law

Include <linux/export.h> explicitly instead of relying on it being implicitly included by <linux/module.h> for the EXPORT_SYMBOL macro.

Signed-off-by: Josh Law <objecting@objecting.org>
---
 lib/glob.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/glob.c b/lib/glob.c
index d0654a5b6f0b..902b5037a0a8 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
 #include <linux/module.h>
 #include <linux/glob.h>
+#include <linux/export.h>
 
 /*
  * The only reason this code can be compiled as a module is because the
-- 
2.43.0


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

* [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean
  2026-03-01 15:21 [PATCH 1/2] lib: glob: add explicit include for export.h Josh Law
@ 2026-03-01 15:21 ` Josh Law
  2026-03-01 19:25   ` Andrew Morton
  2026-03-02  2:56   ` Kuan-Wei Chiu
  0 siblings, 2 replies; 9+ messages in thread
From: Josh Law @ 2026-03-01 15:21 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Josh Law

Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.

Signed-off-by: Josh Law <objecting@objecting.org>
---
 lib/glob.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/glob.c b/lib/glob.c
index 902b5037a0a8..afff28285bd4 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -96,7 +96,8 @@ bool __pure glob_match(char const *pat, char const *str)
 					class += 2;
 					/* Any special action if a > b? */
 				}
-				match |= (a <= c && c <= b);
+				if (a <= c && c <= b)
+					match = true;
 			} while ((a = *class++) != ']');
 
 			if (match == inverted)
-- 
2.43.0


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

* Re: [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean
  2026-03-01 15:21 ` [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean Josh Law
@ 2026-03-01 19:25   ` Andrew Morton
  2026-03-01 19:40     ` Josh Law
  2026-03-01 22:05     ` David Laight
  2026-03-02  2:56   ` Kuan-Wei Chiu
  1 sibling, 2 replies; 9+ messages in thread
From: Andrew Morton @ 2026-03-01 19:25 UTC (permalink / raw)
  To: Josh Law; +Cc: linux-kernel, Josh Law

On Sun,  1 Mar 2026 15:21:42 +0000 Josh Law <hlcj1234567@gmail.com> wrote:

> Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.
> 

Fair enough.

> --- a/lib/glob.c
> +++ b/lib/glob.c
> @@ -96,7 +96,8 @@ bool __pure glob_match(char const *pat, char const *str)
>  					class += 2;
>  					/* Any special action if a > b? */
>  				}
> -				match |= (a <= c && c <= b);
> +				if (a <= c && c <= b)
> +					match = true;
>  			} while ((a = *class++) != ']');
>  
>  			if (match == inverted)

But if we're concerned about bool abuse, what's this?

			bool match = false, inverted = (*pat == '!');
			char const *class = pat + inverted;


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

* Re: [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean
  2026-03-01 19:25   ` Andrew Morton
@ 2026-03-01 19:40     ` Josh Law
  2026-03-01 19:43       ` Andrew Morton
  2026-03-01 22:05     ` David Laight
  1 sibling, 1 reply; 9+ messages in thread
From: Josh Law @ 2026-03-01 19:40 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Josh Law

Hm, I see that, I am sorry about that haha, I tested the functionality of the code and it seems all fine, if anything major happens, I'll release another patch fixing this, I am sorry

V/R

1 Mar 2026 19:25:44 Andrew Morton <akpm@linux-foundation.org>:

> On Sun,  1 Mar 2026 15:21:42 +0000 Josh Law <hlcj1234567@gmail.com> wrote:
> 
>> Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.
>> 
> 
> Fair enough.
> 
>> --- a/lib/glob.c
>> +++ b/lib/glob.c
>> @@ -96,7 +96,8 @@ bool __pure glob_match(char const *pat, char const *str)
>>                     class += 2;
>>                     /* Any special action if a > b? */
>>                 }
>> -               match |= (a <= c && c <= b);
>> +               if (a <= c && c <= b)
>> +                   match = true;
>>             } while ((a = *class++) != ']');
>> 
>>             if (match == inverted)
> 
> But if we're concerned about bool abuse, what's this?
> 
>             bool match = false, inverted = (*pat == '!');
>             char const *class = pat + inverted;

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

* Re: [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean
  2026-03-01 19:40     ` Josh Law
@ 2026-03-01 19:43       ` Andrew Morton
  0 siblings, 0 replies; 9+ messages in thread
From: Andrew Morton @ 2026-03-01 19:43 UTC (permalink / raw)
  To: Josh Law; +Cc: linux-kernel, Josh Law

On Sun, 1 Mar 2026 19:40:16 +0000 Josh Law <hlcj1234567@gmail.com> wrote:

> 1 Mar 2026 19:25:44 Andrew Morton <akpm@linux-foundation.org>:
> 
> > On Sun,  1 Mar 2026 15:21:42 +0000 Josh Law <hlcj1234567@gmail.com> wrote:
> > 
> >> Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.
> >> 
> > 
> > Fair enough.
> > 
> >> --- a/lib/glob.c
> >> +++ b/lib/glob.c
> >> @@ -96,7 +96,8 @@ bool __pure glob_match(char const *pat, char const *str)
> >>                     class += 2;
> >>                     /* Any special action if a > b? */
> >>                 }
> >> -               match |= (a <= c && c <= b);
> >> +               if (a <= c && c <= b)
> >> +                   match = true;
> >>             } while ((a = *class++) != ']');
> >> 
> >>             if (match == inverted)
> > 
> > But if we're concerned about bool abuse, what's this?
> > 
> >             bool match = false, inverted = (*pat == '!');
> >             char const *class = pat + inverted;

OK, please don't top-post and please do wordwrap the email text.

> Hm, I see that, I am sorry about that haha, I tested the functionality
> of the code and it seems all fine, if anything major happens, I'll
> release another patch fixing this, I am sorry 

You did't add this.  It's existing code which I felt you might want to
consider cleaning up.


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

* Re: [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean
  2026-03-01 19:25   ` Andrew Morton
  2026-03-01 19:40     ` Josh Law
@ 2026-03-01 22:05     ` David Laight
  1 sibling, 0 replies; 9+ messages in thread
From: David Laight @ 2026-03-01 22:05 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Josh Law, linux-kernel, Josh Law

On Sun, 1 Mar 2026 11:25:42 -0800
Andrew Morton <akpm@linux-foundation.org> wrote:

> On Sun,  1 Mar 2026 15:21:42 +0000 Josh Law <hlcj1234567@gmail.com> wrote:
> 
> > Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.
> >   
> 
> Fair enough.

It might even generate better code.
Compilers have been known to generate 'really crap code(tm)' for
boolean arithmetic.

	David

> 
> > --- a/lib/glob.c
> > +++ b/lib/glob.c
> > @@ -96,7 +96,8 @@ bool __pure glob_match(char const *pat, char const *str)
> >  					class += 2;
> >  					/* Any special action if a > b? */
> >  				}
> > -				match |= (a <= c && c <= b);
> > +				if (a <= c && c <= b)
> > +					match = true;
> >  			} while ((a = *class++) != ']');
> >  
> >  			if (match == inverted)  
> 
> But if we're concerned about bool abuse, what's this?
> 
> 			bool match = false, inverted = (*pat == '!');
> 			char const *class = pat + inverted;
> 
> 


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

* Re: [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean
  2026-03-01 15:21 ` [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean Josh Law
  2026-03-01 19:25   ` Andrew Morton
@ 2026-03-02  2:56   ` Kuan-Wei Chiu
  2026-03-02  3:02     ` Kuan-Wei Chiu
  1 sibling, 1 reply; 9+ messages in thread
From: Kuan-Wei Chiu @ 2026-03-02  2:56 UTC (permalink / raw)
  To: Josh Law; +Cc: Andrew Morton, linux-kernel, Josh Law

Hi Josh,

On Sun, Mar 01, 2026 at 03:21:42PM +0000, Josh Law wrote:
> Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.
> 
> Signed-off-by: Josh Law <objecting@objecting.org>

checkpath.pl reported the following warnings:

WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit description?)
#81:
Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.

WARNING: From:/Signed-off-by: email address mismatch: 'From: Josh Law <hlcj1234567@gmail.com>' != 'Signed-off-by: Josh Law <objecting@objecting.org>'

total: 0 errors, 2 warnings, 0 checks, 9 lines checked

Regards,
Kuan-Wei

> ---
>  lib/glob.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/glob.c b/lib/glob.c
> index 902b5037a0a8..afff28285bd4 100644
> --- a/lib/glob.c
> +++ b/lib/glob.c
> @@ -96,7 +96,8 @@ bool __pure glob_match(char const *pat, char const *str)
>  					class += 2;
>  					/* Any special action if a > b? */
>  				}
> -				match |= (a <= c && c <= b);
> +				if (a <= c && c <= b)
> +					match = true;
>  			} while ((a = *class++) != ']');
>  
>  			if (match == inverted)
> -- 
> 2.43.0
> 
> 

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

* Re: [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean
  2026-03-02  2:56   ` Kuan-Wei Chiu
@ 2026-03-02  3:02     ` Kuan-Wei Chiu
  2026-03-02  7:11       ` Josh Law
  0 siblings, 1 reply; 9+ messages in thread
From: Kuan-Wei Chiu @ 2026-03-02  3:02 UTC (permalink / raw)
  To: Josh Law; +Cc: Andrew Morton, linux-kernel, Josh Law

On Mon, Mar 02, 2026 at 10:56:47AM +0800, Kuan-Wei Chiu wrote:
> Hi Josh,
> 
> On Sun, Mar 01, 2026 at 03:21:42PM +0000, Josh Law wrote:
> > Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.
> > 
> > Signed-off-by: Josh Law <objecting@objecting.org>
> 
> checkpath.pl reported the following warnings:
> 
> WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit description?)
> #81:
> Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.
> 
> WARNING: From:/Signed-off-by: email address mismatch: 'From: Josh Law <hlcj1234567@gmail.com>' != 'Signed-off-by: Josh Law <objecting@objecting.org>'
> 
> total: 0 errors, 2 warnings, 0 checks, 9 lines checked
>

BTW, both of your patches does not apply cleanly.

Regards,
Kuan-Wei

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

* Re: [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean
  2026-03-02  3:02     ` Kuan-Wei Chiu
@ 2026-03-02  7:11       ` Josh Law
  0 siblings, 0 replies; 9+ messages in thread
From: Josh Law @ 2026-03-02  7:11 UTC (permalink / raw)
  To: Kuan-Wei Chiu; +Cc: Andrew Morton, linux-kernel, Josh Law

>>
>> checkpath.pl reported the following warnings:
>>
>> WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit description?)
>> #81:
>> Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.
>>
>> WARNING: From:/Signed-off-by: email address mismatch: 'From: Josh Law <hlcj1234567@gmail.com>' != 'Signed-off-by: Josh Law <objecting@objecting.org>'
>>
>> total: 0 errors, 2 warnings, 0 checks, 9 lines checked
>>
>
> BTW, both of your patches does not apply cleanly.
>
> Regards,
> Kuan-Wei


I think Andrew fixed that....
Including the from lines

V/R

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

end of thread, other threads:[~2026-03-02  7:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-01 15:21 [PATCH 1/2] lib: glob: add explicit include for export.h Josh Law
2026-03-01 15:21 ` [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean Josh Law
2026-03-01 19:25   ` Andrew Morton
2026-03-01 19:40     ` Josh Law
2026-03-01 19:43       ` Andrew Morton
2026-03-01 22:05     ` David Laight
2026-03-02  2:56   ` Kuan-Wei Chiu
2026-03-02  3:02     ` Kuan-Wei Chiu
2026-03-02  7:11       ` Josh Law

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