[dm-devel] [PATCH 2/8] libmultipath: cleanup add_feature

Martin Wilck martin.wilck at suse.com
Thu Oct 20 14:58:27 UTC 2022


On Fri, 2022-10-07 at 12:35 -0500, Benjamin Marzinski wrote:
> add_feature() didn't correctly handle feature strings that used
> whitespace other than spaces, which the kernel allows. It also didn't
> allow adding features with multiple tokens. When it looked to see if
> the
> feature string to be added already existed, it didn't check if the
> match
> was part of a larger token. Finally, it did unnecessary work.  By
> using
> asprintf() to create the string, the function can be signifcantly
> simplified.
> 
> Signed-off-by: Benjamin Marzinski <bmarzins at redhat.com>

Reviewed-by: Martin Wilck <mwilck at suse.com>

The same general remarks apply as for 01/08.

> ---
>  libmultipath/structs.c | 49 +++++++++++++++++++++-------------------
> --
>  1 file changed, 24 insertions(+), 25 deletions(-)
> 
> diff --git a/libmultipath/structs.c b/libmultipath/structs.c
> index 1f9945e0..0f16c071 100644
> --- a/libmultipath/structs.c
> +++ b/libmultipath/structs.c
> @@ -602,23 +602,33 @@ int add_feature(char **f, const char *n)
>  {
>         int c = 0, d, l;
>         char *e, *t;
> +       const char *p;

Same remark as before about the variable naming. 

>  
>         if (!f)
>                 return 1;
>  
>         /* Nothing to do */
> -       if (!n || *n == '0')
> +       if (!n || *n == '\0')

ouch...



More information about the dm-devel mailing list