diff mbox series

zonefs: Use str_plural() to fix Coccinelle warning

Message ID 20240402101715.226284-2-thorsten.blum@toblux.com (mailing list archive)
State New, archived
Headers show
Series zonefs: Use str_plural() to fix Coccinelle warning | expand

Commit Message

Thorsten Blum April 2, 2024, 10:17 a.m. UTC
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(-)

Comments

Damien Le Moal April 8, 2024, 1:48 a.m. UTC | #1
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.
Thorsten Blum April 8, 2024, 10:04 a.m. UTC | #2
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
Damien Le Moal April 8, 2024, 10:06 a.m. UTC | #3
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 April 9, 2024, 11:50 p.m. UTC | #4
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 !
diff mbox series

Patch

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;
 }