linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib/string_choices: Add str_plural() helper
@ 2024-02-14 16:50 Michal Wajdeczko
  2024-02-14 18:08 ` Andy Shevchenko
  2024-02-15 19:23 ` Kees Cook
  0 siblings, 2 replies; 13+ messages in thread
From: Michal Wajdeczko @ 2024-02-14 16:50 UTC (permalink / raw)
  To: linux-hardening; +Cc: Michal Wajdeczko, Andy Shevchenko, Jani Nikula

Add str_plural() helper to replace existing open implementations
used by many drivers and help improve future user facing messages.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
---
 include/linux/string_choices.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/linux/string_choices.h b/include/linux/string_choices.h
index 3c1091941eb8..f3cd270d11fd 100644
--- a/include/linux/string_choices.h
+++ b/include/linux/string_choices.h
@@ -42,4 +42,9 @@ static inline const char *str_yes_no(bool v)
 	return v ? "yes" : "no";
 }
 
+static inline const char *str_plural(size_t num)
+{
+	return num == 1 ? "" : "s";
+}
+
 #endif
-- 
2.43.0


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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-14 16:50 [PATCH] lib/string_choices: Add str_plural() helper Michal Wajdeczko
@ 2024-02-14 18:08 ` Andy Shevchenko
  2024-02-14 18:09   ` Andy Shevchenko
  2024-02-15 19:23 ` Kees Cook
  1 sibling, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2024-02-14 18:08 UTC (permalink / raw)
  To: Michal Wajdeczko; +Cc: linux-hardening, Jani Nikula

On Wed, Feb 14, 2024 at 05:50:15PM +0100, Michal Wajdeczko wrote:
> Add str_plural() helper to replace existing open implementations
> used by many drivers and help improve future user facing messages.

Any user of this, please?

> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>

> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>

Move these Cc to the after '---' line.

> ---

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-14 18:08 ` Andy Shevchenko
@ 2024-02-14 18:09   ` Andy Shevchenko
  2024-02-14 18:30     ` Jani Nikula
  0 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2024-02-14 18:09 UTC (permalink / raw)
  To: Michal Wajdeczko; +Cc: linux-hardening, Jani Nikula

On Wed, Feb 14, 2024 at 08:08:16PM +0200, Andy Shevchenko wrote:
> On Wed, Feb 14, 2024 at 05:50:15PM +0100, Michal Wajdeczko wrote:
> > Add str_plural() helper to replace existing open implementations
> > used by many drivers and help improve future user facing messages.
> 
> Any user of this, please?
> 
> > Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
> 
> > Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Cc: Jani Nikula <jani.nikula@intel.com>
> 
> Move these Cc to the after '---' line.
> 
> > ---

Besides that, check with the latest MAINTAINERS updates,
you missed the maintainer of this file.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-14 18:09   ` Andy Shevchenko
@ 2024-02-14 18:30     ` Jani Nikula
  2024-02-14 18:49       ` Andy Shevchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Jani Nikula @ 2024-02-14 18:30 UTC (permalink / raw)
  To: Andy Shevchenko, Michal Wajdeczko; +Cc: linux-hardening, Kees Cook

On Wed, 14 Feb 2024, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> On Wed, Feb 14, 2024 at 08:08:16PM +0200, Andy Shevchenko wrote:
>> On Wed, Feb 14, 2024 at 05:50:15PM +0100, Michal Wajdeczko wrote:
>> > Add str_plural() helper to replace existing open implementations
>> > used by many drivers and help improve future user facing messages.
>> 
>> Any user of this, please?

git grep "\"\" *: *\"s\""

>> > Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
>> 
>> > Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> > Cc: Jani Nikula <jani.nikula@intel.com>
>> 
>> Move these Cc to the after '---' line.

Why?

>> 
>> > ---
>
> Besides that, check with the latest MAINTAINERS updates,
> you missed the maintainer of this file.

Come on Andy, you might have Cc'd Kees yourself instead of just
nitpicking about it! Done now. ;)

BR,
Jani.


-- 
Jani Nikula, Intel

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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-14 18:30     ` Jani Nikula
@ 2024-02-14 18:49       ` Andy Shevchenko
  2024-02-14 19:07         ` Kees Cook
  0 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2024-02-14 18:49 UTC (permalink / raw)
  To: Jani Nikula; +Cc: Michal Wajdeczko, linux-hardening, Kees Cook

On Wed, Feb 14, 2024 at 08:30:53PM +0200, Jani Nikula wrote:
> On Wed, 14 Feb 2024, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > On Wed, Feb 14, 2024 at 08:08:16PM +0200, Andy Shevchenko wrote:
> >> On Wed, Feb 14, 2024 at 05:50:15PM +0100, Michal Wajdeczko wrote:
> >> > Add str_plural() helper to replace existing open implementations
> >> > used by many drivers and help improve future user facing messages.
> >> 
> >> Any user of this, please?
> 
> git grep "\"\" *: *\"s\""

You know what I meant.
Second patch in the series that shows usefulness of the first patch.

...

> >> > Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
> >> 
> >> > Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >> > Cc: Jani Nikula <jani.nikula@intel.com>
> >> 
> >> Move these Cc to the after '---' line.
> 
> Why?

At bare minimum to reduce noise in the commit message.
If going further, to be environment friendly (no jokes).

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-14 18:49       ` Andy Shevchenko
@ 2024-02-14 19:07         ` Kees Cook
  2024-02-15 15:20           ` Jani Nikula
  0 siblings, 1 reply; 13+ messages in thread
From: Kees Cook @ 2024-02-14 19:07 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Jani Nikula, Michal Wajdeczko, linux-hardening

On Wed, Feb 14, 2024 at 08:49:39PM +0200, Andy Shevchenko wrote:
> On Wed, Feb 14, 2024 at 08:30:53PM +0200, Jani Nikula wrote:
> > On Wed, 14 Feb 2024, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > > On Wed, Feb 14, 2024 at 08:08:16PM +0200, Andy Shevchenko wrote:
> > >> On Wed, Feb 14, 2024 at 05:50:15PM +0100, Michal Wajdeczko wrote:
> > >> > Add str_plural() helper to replace existing open implementations
> > >> > used by many drivers and help improve future user facing messages.
> > >> 
> > >> Any user of this, please?
> > 
> > git grep "\"\" *: *\"s\""
> 
> You know what I meant.
> Second patch in the series that shows usefulness of the first patch.

Or a Coccinelle script that could do some rewrites? But, yes, if you can
include some examples, that would be nice. I think the helper is fine to
add.

> 
> ...
> 
> > >> > Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
> > >> 
> > >> > Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > >> > Cc: Jani Nikula <jani.nikula@intel.com>
> > >> 
> > >> Move these Cc to the after '---' line.
> > 
> > Why?
> 
> At bare minimum to reduce noise in the commit message.
> If going further, to be environment friendly (no jokes).

I learned the above-the-line CC habit from akpm. But in looking through
recent commit history, this does appear to be the exception now. I'll
need to adjust my own workflow for this too...

-- 
Kees Cook

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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-14 19:07         ` Kees Cook
@ 2024-02-15 15:20           ` Jani Nikula
  2024-02-15 15:37             ` Michal Wajdeczko
  0 siblings, 1 reply; 13+ messages in thread
From: Jani Nikula @ 2024-02-15 15:20 UTC (permalink / raw)
  To: Kees Cook, Andy Shevchenko; +Cc: Michal Wajdeczko, linux-hardening

On Wed, 14 Feb 2024, Kees Cook <keescook@chromium.org> wrote:
> On Wed, Feb 14, 2024 at 08:49:39PM +0200, Andy Shevchenko wrote:
>> On Wed, Feb 14, 2024 at 08:30:53PM +0200, Jani Nikula wrote:
>> > On Wed, 14 Feb 2024, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>> > > On Wed, Feb 14, 2024 at 08:08:16PM +0200, Andy Shevchenko wrote:
>> > >> On Wed, Feb 14, 2024 at 05:50:15PM +0100, Michal Wajdeczko wrote:
>> > >> > Add str_plural() helper to replace existing open implementations
>> > >> > used by many drivers and help improve future user facing messages.
>> > >> 
>> > >> Any user of this, please?
>> > 
>> > git grep "\"\" *: *\"s\""
>> 
>> You know what I meant.
>> Second patch in the series that shows usefulness of the first patch.
>
> Or a Coccinelle script that could do some rewrites? But, yes, if you can
> include some examples, that would be nice. I think the helper is fine to
> add.

In all kindness, I think it's actually better to get the inevitable
bikeshedding rounds done first. It's trivial to add users after
that. And for simple things like this it should really be obvious to
everyone what the usage would be like.

My first attempt at adding a plural helper seems to date back to
2019. Yes, really. Personally, I honestly can no longer be bothered to
put in the extra effort before there's some indication of
acceptance. (Like there's here now, thanks!)

>> > >> > Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
>> > >> 
>> > >> > Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> > >> > Cc: Jani Nikula <jani.nikula@intel.com>
>> > >> 
>> > >> Move these Cc to the after '---' line.
>> > 
>> > Why?
>> 
>> At bare minimum to reduce noise in the commit message.
>> If going further, to be environment friendly (no jokes).
>
> I learned the above-the-line CC habit from akpm. But in looking through
> recent commit history, this does appear to be the exception now. I'll
> need to adjust my own workflow for this too...

It just depends on where in the kernel you look, every subsystem is
subtly different. In the drm subsystem if you added the Cc's below
"---", you might be asked to move them above.

Trivial for whoever applies the patches to do whatever they please with
the trailers, impossible for the contributor. It's like The Trial. :p

BR,
Jani.


-- 
Jani Nikula, Intel

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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-15 15:20           ` Jani Nikula
@ 2024-02-15 15:37             ` Michal Wajdeczko
  2024-02-15 16:11               ` Andy Shevchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Michal Wajdeczko @ 2024-02-15 15:37 UTC (permalink / raw)
  To: Jani Nikula, Kees Cook, Andy Shevchenko; +Cc: linux-hardening



On 15.02.2024 16:20, Jani Nikula wrote:
> On Wed, 14 Feb 2024, Kees Cook <keescook@chromium.org> wrote:
>> On Wed, Feb 14, 2024 at 08:49:39PM +0200, Andy Shevchenko wrote:
>>> On Wed, Feb 14, 2024 at 08:30:53PM +0200, Jani Nikula wrote:
>>>> On Wed, 14 Feb 2024, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>>>>> On Wed, Feb 14, 2024 at 08:08:16PM +0200, Andy Shevchenko wrote:
>>>>>> On Wed, Feb 14, 2024 at 05:50:15PM +0100, Michal Wajdeczko wrote:
>>>>>>> Add str_plural() helper to replace existing open implementations
>>>>>>> used by many drivers and help improve future user facing messages.
>>>>>>
>>>>>> Any user of this, please?
>>>>
>>>> git grep "\"\" *: *\"s\""
>>>
>>> You know what I meant.
>>> Second patch in the series that shows usefulness of the first patch.
>>
>> Or a Coccinelle script that could do some rewrites? But, yes, if you can
>> include some examples, that would be nice. I think the helper is fine to
>> add.

please find below requested Coccinelle script:

virtual patch
virtual context
virtual report

@depends on patch@
expression E;
@@
(
-	E == 1 ? "" : "s"
+	str_plural(E)
|
-	(E == 1) ? "" : "s"
+	str_plural(E)
|
-	E > 1 ? "s" : ""
+	str_plural(E)
|
-	(E > 1) ? "s" : ""
+	str_plural(E)
)

@r depends on !patch exists@
expression E;
position P;
@@
(
*	E@P == 1 ? "" : "s"
|
*	(E@P == 1) ? "" : "s"
|
*	E@P > 1 ? "s" : ""
|
*	(E@P > 1) ? "s" : ""
)

@script:python depends on report@
p << r.P;
e << r.E;
@@

coccilib.report.print_report(p[0], "opportunity for str_plural(%s)" % e)


> 
> In all kindness, I think it's actually better to get the inevitable
> bikeshedding rounds done first. It's trivial to add users after
> that. And for simple things like this it should really be obvious to
> everyone what the usage would be like.
> 
> My first attempt at adding a plural helper seems to date back to
> 2019. 

true, I do recall that, hence your invite

> Yes, really. Personally, I honestly can no longer be bothered to
> put in the extra effort before there's some indication of
> acceptance. (Like there's here now, thanks!)
> 
>>>>>>> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
>>>>>>
>>>>>>> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>>>>>>> Cc: Jani Nikula <jani.nikula@intel.com>
>>>>>>
>>>>>> Move these Cc to the after '---' line.
>>>>
>>>> Why?
>>>
>>> At bare minimum to reduce noise in the commit message.
>>> If going further, to be environment friendly (no jokes).
>>
>> I learned the above-the-line CC habit from akpm. But in looking through
>> recent commit history, this does appear to be the exception now. I'll
>> need to adjust my own workflow for this too...
> 
> It just depends on where in the kernel you look, every subsystem is
> subtly different. In the drm subsystem if you added the Cc's below
> "---", you might be asked to move them above.
> 
> Trivial for whoever applies the patches to do whatever they please with
> the trailers, impossible for the contributor. It's like The Trial. :p
> 
> BR,
> Jani.
> 
> 

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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-15 15:37             ` Michal Wajdeczko
@ 2024-02-15 16:11               ` Andy Shevchenko
  2024-02-15 16:55                 ` Michal Wajdeczko
  0 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2024-02-15 16:11 UTC (permalink / raw)
  To: Michal Wajdeczko; +Cc: Jani Nikula, Kees Cook, linux-hardening

On Thu, Feb 15, 2024 at 04:37:18PM +0100, Michal Wajdeczko wrote:
> On 15.02.2024 16:20, Jani Nikula wrote:
> > On Wed, 14 Feb 2024, Kees Cook <keescook@chromium.org> wrote:
> >> On Wed, Feb 14, 2024 at 08:49:39PM +0200, Andy Shevchenko wrote:

...

> >> Or a Coccinelle script that could do some rewrites? But, yes, if you can
> >> include some examples, that would be nice. I think the helper is fine to
> >> add.
> 
> please find below requested Coccinelle script:

Thanks!

Btw, what to do with 0?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-15 16:11               ` Andy Shevchenko
@ 2024-02-15 16:55                 ` Michal Wajdeczko
  2024-02-15 17:05                   ` Andy Shevchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Michal Wajdeczko @ 2024-02-15 16:55 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Jani Nikula, Kees Cook, linux-hardening



On 15.02.2024 17:11, Andy Shevchenko wrote:
> On Thu, Feb 15, 2024 at 04:37:18PM +0100, Michal Wajdeczko wrote:
>> On 15.02.2024 16:20, Jani Nikula wrote:
>>> On Wed, 14 Feb 2024, Kees Cook <keescook@chromium.org> wrote:
>>>> On Wed, Feb 14, 2024 at 08:49:39PM +0200, Andy Shevchenko wrote:
> 
> ...
> 
>>>> Or a Coccinelle script that could do some rewrites? But, yes, if you can
>>>> include some examples, that would be nice. I think the helper is fine to
>>>> add.
>>
>> please find below requested Coccinelle script:
> 
> Thanks!
> 
> Btw, what to do with 0?
> 

code is based on this rule:

"With countable nouns, zero is always followed by plural nouns."


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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-15 16:55                 ` Michal Wajdeczko
@ 2024-02-15 17:05                   ` Andy Shevchenko
  2024-02-15 17:14                     ` Michal Wajdeczko
  0 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2024-02-15 17:05 UTC (permalink / raw)
  To: Michal Wajdeczko; +Cc: Jani Nikula, Kees Cook, linux-hardening

On Thu, Feb 15, 2024 at 05:55:43PM +0100, Michal Wajdeczko wrote:
> On 15.02.2024 17:11, Andy Shevchenko wrote:
> > On Thu, Feb 15, 2024 at 04:37:18PM +0100, Michal Wajdeczko wrote:
> >> On 15.02.2024 16:20, Jani Nikula wrote:
> >>> On Wed, 14 Feb 2024, Kees Cook <keescook@chromium.org> wrote:
> >>>> On Wed, Feb 14, 2024 at 08:49:39PM +0200, Andy Shevchenko wrote:

...

> >>>> Or a Coccinelle script that could do some rewrites? But, yes, if you can
> >>>> include some examples, that would be nice. I think the helper is fine to
> >>>> add.
> >>
> >> please find below requested Coccinelle script:
> > 
> > Thanks!
> > 
> > Btw, what to do with 0?
> 
> code is based on this rule:
> 
> "With countable nouns, zero is always followed by plural nouns."

If it's not documented / commented, please add one.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-15 17:05                   ` Andy Shevchenko
@ 2024-02-15 17:14                     ` Michal Wajdeczko
  0 siblings, 0 replies; 13+ messages in thread
From: Michal Wajdeczko @ 2024-02-15 17:14 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Jani Nikula, Kees Cook, linux-hardening



On 15.02.2024 18:05, Andy Shevchenko wrote:
> On Thu, Feb 15, 2024 at 05:55:43PM +0100, Michal Wajdeczko wrote:
>> On 15.02.2024 17:11, Andy Shevchenko wrote:
>>> On Thu, Feb 15, 2024 at 04:37:18PM +0100, Michal Wajdeczko wrote:
>>>> On 15.02.2024 16:20, Jani Nikula wrote:
>>>>> On Wed, 14 Feb 2024, Kees Cook <keescook@chromium.org> wrote:
>>>>>> On Wed, Feb 14, 2024 at 08:49:39PM +0200, Andy Shevchenko wrote:
> 
> ...
> 
>>>>>> Or a Coccinelle script that could do some rewrites? But, yes, if you can
>>>>>> include some examples, that would be nice. I think the helper is fine to
>>>>>> add.
>>>>
>>>> please find below requested Coccinelle script:
>>>
>>> Thanks!
>>>
>>> Btw, what to do with 0?
>>
>> code is based on this rule:
>>
>> "With countable nouns, zero is always followed by plural nouns."
> 
> If it's not documented / commented, please add one.

but this is a rule of the English language, no ?
do we really have to repeat it in the code ?


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

* Re: [PATCH] lib/string_choices: Add str_plural() helper
  2024-02-14 16:50 [PATCH] lib/string_choices: Add str_plural() helper Michal Wajdeczko
  2024-02-14 18:08 ` Andy Shevchenko
@ 2024-02-15 19:23 ` Kees Cook
  1 sibling, 0 replies; 13+ messages in thread
From: Kees Cook @ 2024-02-15 19:23 UTC (permalink / raw)
  To: linux-hardening, Michal Wajdeczko; +Cc: Kees Cook, Andy Shevchenko, Jani Nikula

On Wed, 14 Feb 2024 17:50:15 +0100, Michal Wajdeczko wrote:
> Add str_plural() helper to replace existing open implementations
> used by many drivers and help improve future user facing messages.

I added some kern-doc just for good measure.

Applied to for-next/hardening, thanks!

[1/1] lib/string_choices: Add str_plural() helper
      https://git.kernel.org/kees/c/bf10745c0053

Take care,

-- 
Kees Cook


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

end of thread, other threads:[~2024-02-15 19:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14 16:50 [PATCH] lib/string_choices: Add str_plural() helper Michal Wajdeczko
2024-02-14 18:08 ` Andy Shevchenko
2024-02-14 18:09   ` Andy Shevchenko
2024-02-14 18:30     ` Jani Nikula
2024-02-14 18:49       ` Andy Shevchenko
2024-02-14 19:07         ` Kees Cook
2024-02-15 15:20           ` Jani Nikula
2024-02-15 15:37             ` Michal Wajdeczko
2024-02-15 16:11               ` Andy Shevchenko
2024-02-15 16:55                 ` Michal Wajdeczko
2024-02-15 17:05                   ` Andy Shevchenko
2024-02-15 17:14                     ` Michal Wajdeczko
2024-02-15 19:23 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).