Linux-Fsdevel Archive mirror
 help / color / mirror / Atom feed
* [PATCH] zonefs: Use str_plural() to fix Coccinelle warning
@ 2024-04-02 10:17 Thorsten Blum
  2024-04-08  1:48 ` Damien Le Moal
  2024-04-09 23:50 ` Damien Le Moal
  0 siblings, 2 replies; 5+ messages in thread
From: Thorsten Blum @ 2024-04-02 10:17 UTC (permalink / raw
  To: Damien Le Moal, Naohiro Aota, Johannes Thumshirn
  Cc: linux-fsdevel, linux-kernel, Thorsten Blum

Fixes the following Coccinelle/coccicheck warning reported by
string_choices.cocci:

	opportunity for str_plural(zgroup->g_nr_zones)

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 fs/zonefs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index c6a124e8d565..964fa7f24003 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -1048,7 +1048,7 @@ static int zonefs_init_zgroup(struct super_block *sb,
 	zonefs_info(sb, "Zone group \"%s\" has %u file%s\n",
 		    zonefs_zgroup_name(ztype),
 		    zgroup->g_nr_zones,
-		    zgroup->g_nr_zones > 1 ? "s" : "");
+		    str_plural(zgroup->g_nr_zones));
 
 	return 0;
 }
-- 
2.44.0


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

* Re: [PATCH] zonefs: Use str_plural() to fix Coccinelle warning
  2024-04-02 10:17 [PATCH] zonefs: Use str_plural() to fix Coccinelle warning Thorsten Blum
@ 2024-04-08  1:48 ` Damien Le Moal
  2024-04-08 10:04   ` Thorsten Blum
  2024-04-09 23:50 ` Damien Le Moal
  1 sibling, 1 reply; 5+ messages in thread
From: Damien Le Moal @ 2024-04-08  1:48 UTC (permalink / raw
  To: Thorsten Blum, Naohiro Aota, Johannes Thumshirn
  Cc: linux-fsdevel, linux-kernel

On 4/2/24 19:17, Thorsten Blum wrote:
> Fixes the following Coccinelle/coccicheck warning reported by
> string_choices.cocci:
> 
> 	opportunity for str_plural(zgroup->g_nr_zones)
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>  fs/zonefs/super.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
> index c6a124e8d565..964fa7f24003 100644
> --- a/fs/zonefs/super.c
> +++ b/fs/zonefs/super.c
> @@ -1048,7 +1048,7 @@ static int zonefs_init_zgroup(struct super_block *sb,
>  	zonefs_info(sb, "Zone group \"%s\" has %u file%s\n",
>  		    zonefs_zgroup_name(ztype),
>  		    zgroup->g_nr_zones,
> -		    zgroup->g_nr_zones > 1 ? "s" : "");
> +		    str_plural(zgroup->g_nr_zones));

Looking at this function definition:

static inline const char *str_plural(size_t num)
{
	return num == 1 ? "" : "s";
}

It is wrong: num == 0 should not imply plural. This function needs to be fixed.
E.g. it should be:

static inline const char *str_plural(size_t num)
{
	return num <= 1 ? "" : "s";
}

Please fix that first and then we can apply your patch to zonefs.

-- 
Damien Le Moal
Western Digital Research


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

* Re: [PATCH] zonefs: Use str_plural() to fix Coccinelle warning
  2024-04-08  1:48 ` Damien Le Moal
@ 2024-04-08 10:04   ` Thorsten Blum
  2024-04-08 10:06     ` Damien Le Moal
  0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2024-04-08 10:04 UTC (permalink / raw
  To: Damien Le Moal
  Cc: Naohiro Aota, Johannes Thumshirn, linux-fsdevel, linux-kernel

On 8. Apr 2024, at 03:48, Damien Le Moal <dlemoal@kernel.org> wrote:
> 
> Looking at this function definition:
> 
> static inline const char *str_plural(size_t num)
> {
> return num == 1 ? "" : "s";
> }
> 
> It is wrong: num == 0 should not imply plural. This function needs to be fixed.

I think the function is correct because in English it's:

0 files
1 file (every number but 1 is plural in English)
2 files
...

Best,
Thorsten

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

* Re: [PATCH] zonefs: Use str_plural() to fix Coccinelle warning
  2024-04-08 10:04   ` Thorsten Blum
@ 2024-04-08 10:06     ` Damien Le Moal
  0 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2024-04-08 10:06 UTC (permalink / raw
  To: Thorsten Blum
  Cc: Naohiro Aota, Johannes Thumshirn, linux-fsdevel, linux-kernel

On 4/8/24 19:04, Thorsten Blum wrote:
> On 8. Apr 2024, at 03:48, Damien Le Moal <dlemoal@kernel.org> wrote:
>>
>> Looking at this function definition:
>>
>> static inline const char *str_plural(size_t num)
>> {
>> return num == 1 ? "" : "s";
>> }
>>
>> It is wrong: num == 0 should not imply plural. This function needs to be fixed.
> 
> I think the function is correct because in English it's:
> 
> 0 files

Hu... I learned something today :)
OK. Will queue that the patch then !

> 1 file (every number but 1 is plural in English)
> 2 files
> ...
> 
> Best,
> Thorsten

-- 
Damien Le Moal
Western Digital Research


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

* Re: [PATCH] zonefs: Use str_plural() to fix Coccinelle warning
  2024-04-02 10:17 [PATCH] zonefs: Use str_plural() to fix Coccinelle warning Thorsten Blum
  2024-04-08  1:48 ` Damien Le Moal
@ 2024-04-09 23:50 ` Damien Le Moal
  1 sibling, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2024-04-09 23:50 UTC (permalink / raw
  To: Thorsten Blum, Naohiro Aota, Johannes Thumshirn
  Cc: linux-fsdevel, linux-kernel

On 4/2/24 19:17, Thorsten Blum wrote:
> Fixes the following Coccinelle/coccicheck warning reported by
> string_choices.cocci:
> 
> 	opportunity for str_plural(zgroup->g_nr_zones)
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>

Applied to for-6.9-fixes. Thanks !


-- 
Damien Le Moal
Western Digital Research


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

end of thread, other threads:[~2024-04-09 23:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-02 10:17 [PATCH] zonefs: Use str_plural() to fix Coccinelle warning Thorsten Blum
2024-04-08  1:48 ` Damien Le Moal
2024-04-08 10:04   ` Thorsten Blum
2024-04-08 10:06     ` Damien Le Moal
2024-04-09 23:50 ` Damien Le Moal

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 read-only IMAP folder(s) and NNTP newsgroup(s).