* [PATCH] lib/vsprintf: replace min_t/max_t with min/max
@ 2026-05-18 12:31 Thorsten Blum
2026-05-21 13:49 ` Petr Mladek
0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Blum @ 2026-05-18 12:31 UTC (permalink / raw)
To: Petr Mladek, Steven Rostedt, Andy Shevchenko, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton
Cc: Thorsten Blum, linux-kernel
Use the simpler min()/max() macros since the values are all compatible.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
lib/vsprintf.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 9f359b31c8d1..57ae85680536 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1208,7 +1208,7 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
}
if (spec.field_width > 0)
- len = min_t(int, spec.field_width, 64);
+ len = min(spec.field_width, 64);
for (i = 0; i < len; ++i) {
if (buf < end)
@@ -1233,7 +1233,7 @@ char *bitmap_string(char *buf, char *end, const unsigned long *bitmap,
struct printf_spec spec, const char *fmt)
{
const int CHUNKSZ = 32;
- int nr_bits = max_t(int, spec.field_width, 0);
+ int nr_bits = max(spec.field_width, 0);
int i, chunksz;
bool first = true;
@@ -1276,7 +1276,7 @@ static noinline_for_stack
char *bitmap_list_string(char *buf, char *end, const unsigned long *bitmap,
struct printf_spec spec, const char *fmt)
{
- int nr_bits = max_t(int, spec.field_width, 0);
+ int nr_bits = max(spec.field_width, 0);
bool first = true;
int rbot, rtop;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] lib/vsprintf: replace min_t/max_t with min/max
2026-05-18 12:31 [PATCH] lib/vsprintf: replace min_t/max_t with min/max Thorsten Blum
@ 2026-05-21 13:49 ` Petr Mladek
2026-06-02 18:02 ` Andy Shevchenko
2026-06-03 9:35 ` David Laight
0 siblings, 2 replies; 6+ messages in thread
From: Petr Mladek @ 2026-05-21 13:49 UTC (permalink / raw)
To: Thorsten Blum
Cc: Steven Rostedt, Andy Shevchenko, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton, linux-kernel
On Mon 2026-05-18 14:31:47, Thorsten Blum wrote:
> Use the simpler min()/max() macros since the values are all compatible.
>
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1208,7 +1208,7 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
> }
>
> if (spec.field_width > 0)
> - len = min_t(int, spec.field_width, 64);
> + len = min(spec.field_width, 64);
Honestly, I do not see any big advantage in replacing the macros.
In fact, the min()/max() macros are even more complex because
they check compatibility of the compared types.
IMHO, this adds non-necessary churn into the git history without
an obvious advantage.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lib/vsprintf: replace min_t/max_t with min/max
2026-05-21 13:49 ` Petr Mladek
@ 2026-06-02 18:02 ` Andy Shevchenko
2026-06-03 9:35 ` David Laight
1 sibling, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-06-02 18:02 UTC (permalink / raw)
To: Petr Mladek
Cc: Thorsten Blum, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton, linux-kernel
On Thu, May 21, 2026 at 03:49:12PM +0200, Petr Mladek wrote:
> On Mon 2026-05-18 14:31:47, Thorsten Blum wrote:
> > Use the simpler min()/max() macros since the values are all compatible.
...
> > if (spec.field_width > 0)
> > - len = min_t(int, spec.field_width, 64);
> > + len = min(spec.field_width, 64);
>
> Honestly, I do not see any big advantage in replacing the macros.
> In fact, the min()/max() macros are even more complex because
> they check compatibility of the compared types.
>
> IMHO, this adds non-necessary churn into the git history without
> an obvious advantage.
The advantage I see is to give a good example to others to avoid min_t()
whenever is possible. I am not insisting to include this patch, just
share my 2 cents.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lib/vsprintf: replace min_t/max_t with min/max
@ 2026-06-02 18:21 Alexey Dobriyan
0 siblings, 0 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2026-06-02 18:21 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Petr Mladek, Thorsten Blum, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton, linux-kernel
Andy Shevchenko wrote:
> > > if (spec.field_width > 0)
> > > - len = min_t(int, spec.field_width, 64);
> > > + len = min(spec.field_width, 64);
> >
> > Honestly, I do not see any big advantage in replacing the macros.
> > In fact, the min()/max() macros are even more complex because
> > they check compatibility of the compared types.
> >
> > IMHO, this adds non-necessary churn into the git history without
> > an obvious advantage.
>
> The advantage I see is to give a good example to others to avoid min_t()
> whenever is possible. I am not insisting to include this patch, just
> share my 2 cents.
Patch is good. "field_width" was bitfield for a long time, so min/max
couldn't be used.
%alexey
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lib/vsprintf: replace min_t/max_t with min/max
2026-05-21 13:49 ` Petr Mladek
2026-06-02 18:02 ` Andy Shevchenko
@ 2026-06-03 9:35 ` David Laight
2026-06-03 12:01 ` Petr Mladek
1 sibling, 1 reply; 6+ messages in thread
From: David Laight @ 2026-06-03 9:35 UTC (permalink / raw)
To: Petr Mladek
Cc: Thorsten Blum, Steven Rostedt, Andy Shevchenko, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton, linux-kernel
On Thu, 21 May 2026 15:49:12 +0200
Petr Mladek <pmladek@suse.com> wrote:
> On Mon 2026-05-18 14:31:47, Thorsten Blum wrote:
> > Use the simpler min()/max() macros since the values are all compatible.
> >
> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
> > @@ -1208,7 +1208,7 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
> > }
> >
> > if (spec.field_width > 0)
> > - len = min_t(int, spec.field_width, 64);
> > + len = min(spec.field_width, 64);
>
> Honestly, I do not see any big advantage in replacing the macros.
> In fact, the min()/max() macros are even more complex because
> they check compatibility of the compared types.
But min_t() is often worse that just letting the compiler promote
a negative signed value to a very large unsigned one.
There are basically three common misuses:
1) Using the type you want the result to be.
2) Using the smaller type, including 'long' v 'u64' on 32bit.
3) Thinking min_t(type, a, b) is the best way to compare items of
type 'type'.
All not helped by checkpatch suggesting that:
min(foo, (type)bar)
is 'an opportunity for':
min_t(type, foo, bar)
but the latter is:
min((type)foo, (type)bar)
and you never need both casts.
There are also a few of the pointless/buggy:
min_t(u8, foo, U8_MAX)
but you'd notice that the test:
if ((u8)foo > U8_MAX)
doesn't do what was intended.
Ideally min_t() ought to be killed, but it is a big job.
(The sort of thing Linus could because of his 'god' bit.)
-- David
>
> IMHO, this adds non-necessary churn into the git history without
> an obvious advantage.
>
> Best Regards,
> Petr
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lib/vsprintf: replace min_t/max_t with min/max
2026-06-03 9:35 ` David Laight
@ 2026-06-03 12:01 ` Petr Mladek
0 siblings, 0 replies; 6+ messages in thread
From: Petr Mladek @ 2026-06-03 12:01 UTC (permalink / raw)
To: David Laight
Cc: Thorsten Blum, Steven Rostedt, Andy Shevchenko, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton, linux-kernel
On Wed 2026-06-03 10:35:39, David Laight wrote:
> On Thu, 21 May 2026 15:49:12 +0200
> Petr Mladek <pmladek@suse.com> wrote:
>
> > On Mon 2026-05-18 14:31:47, Thorsten Blum wrote:
> > > Use the simpler min()/max() macros since the values are all compatible.
> > >
> > > --- a/lib/vsprintf.c
> > > +++ b/lib/vsprintf.c
> > > @@ -1208,7 +1208,7 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
> > > }
> > >
> > > if (spec.field_width > 0)
> > > - len = min_t(int, spec.field_width, 64);
> > > + len = min(spec.field_width, 64);
> >
> > Honestly, I do not see any big advantage in replacing the macros.
> > In fact, the min()/max() macros are even more complex because
> > they check compatibility of the compared types.
>
> But min_t() is often worse that just letting the compiler promote
> a negative signed value to a very large unsigned one.
>
> There are basically three common misuses:
> 1) Using the type you want the result to be.
> 2) Using the smaller type, including 'long' v 'u64' on 32bit.
> 3) Thinking min_t(type, a, b) is the best way to compare items of
> type 'type'.
>
> All not helped by checkpatch suggesting that:
> min(foo, (type)bar)
> is 'an opportunity for':
> min_t(type, foo, bar)
> but the latter is:
> min((type)foo, (type)bar)
> and you never need both casts.
>
> There are also a few of the pointless/buggy:
> min_t(u8, foo, U8_MAX)
> but you'd notice that the test:
> if ((u8)foo > U8_MAX)
> doesn't do what was intended.
>
> Ideally min_t() ought to be killed, but it is a big job.
> (The sort of thing Linus could because of his 'god' bit.)
Andy, David, thanks for feedback. Fair enough.
Thorsten, thanks for the patch.
I have just pushed the patch into printk/linux.git,
branch for-7.2.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-03 12:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-18 12:31 [PATCH] lib/vsprintf: replace min_t/max_t with min/max Thorsten Blum
2026-05-21 13:49 ` Petr Mladek
2026-06-02 18:02 ` Andy Shevchenko
2026-06-03 9:35 ` David Laight
2026-06-03 12:01 ` Petr Mladek
-- strict thread matches above, loose matches on Subject: below --
2026-06-02 18:21 Alexey Dobriyan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.