Re: [PATCH v10 1/3] btrfs: add btrfs_strmatch helper

David Sterba
2020-10-29T18:37:32Z

On Wed, Oct 28, 2020 at 09:14:45PM +0800, Anand Jain wrote:
> Add a generic helper to match the golden-string in the given-string,
> and ignore the leading and trailing whitespaces if any.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> Suggested-by: David Sterba <dsterba@suse.com>
> Reviewed-by: Josef Bacik <josef@toxicpanda.com>
> ---
> v10: return bool instead of int.
> drop unnecessary local variable and ( ) with in if.
> v9: use Josef suggested C coding style, using single if statement.
> v5: born
> fs/btrfs/sysfs.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index fcd6c7a9bbd1..5955379d3d9e 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -888,6 +888,24 @@ static ssize_t btrfs_generation_show(struct kobject *kobj,
> }
> BTRFS_ATTR(, generation, btrfs_generation_show);
>
> +/*
> + * Match the %golden in the %given. Ignore the leading and trailing whitespaces
> + * if any.
> + */
> +static bool btrfs_strmatch(const char *given, const char *golden)
> +{
> + size_t len = strlen(golden);
> +
> + /* skip leading whitespace */

Comments should start with uppercase unless it's an identifier.

> + given = skip_spaces(given);
> +
> + if (strncmp(given, golden, len) == 0 &&
> + !strlen(skip_spaces(given + len)))

You had strlen() == 0 instead of !strlen in v9, the == 0 is better here.

I'll fix that locally and push to misc-next so we can proceed with the
actual policies.