Re: [PATCH v2 3/2] lib/uuid.c: Silence an unchecked return value warning

From: Andy Shevchenko
Date: Sun Jun 05 2016 - 10:19:55 EST


On Sat, 2016-06-04 at 09:16 -0400, George Spelvin wrote:
> Andy Shevchenko pointed out that __uuid_to_bin doesn't need to check
> the return value from hex2bin(), because the preceding uuid_is_valid()
> check already took care of that.
>
> But hex2bin() is declared __must_check, so checking anyway is the
> simplest way to silence the warning.
>
> This cancels a small fraction of the the space savings, but not all:
>
> vs. previous patch vs. before patch series
> BeforeÂÂAfterÂÂÂDeltaÂÂÂPercent Orig. Delta
> Percent
> x86-32 90 Â96 Â+6 6.7% 122 -
> 26 -21.3%
> x86-64 90 Â96 Â+6 6.7% 127ÂÂÂÂÂ-31
> -24.4%
> arm 92 104 +12 13.0% 116ÂÂÂÂÂ-12
> -10.3%
> thumb 50 Â62 +12 24.0% 100ÂÂÂÂÂ-38
> -38.0%
> arm64 116 124 Â+8 6.9% 148ÂÂÂÂÂ-24
> -16.2%
>
> Signed-off-by: George Spelvin <linux@xxxxxxxxxxxxxxxxxxx>
> ---
> Âlib/uuid.c | 3 ++-
> Â1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/uuid.c b/lib/uuid.c
> index 93945915..1a6dbbd2 100644
> --- a/lib/uuid.c
> +++ b/lib/uuid.c
> @@ -104,7 +104,8 @@ static int __uuid_to_bin(const char uuid[36], __u8
> b[16], const u8 pos[16])
> Â return -EINVAL;
> Â
> Â for (i = 0; i < 16; i++)
> - hex2bin(b + i, uuid + pos[i], 1);
> + if (hex2bin(b + i, uuid + pos[i], 1) < 0)
> + return -EINVAL;

Which I against of. Please, use normal hex_to_bin() calls here.

Compiler will inline it anyway, but at least will not do second check
for nothing.

> Â
> Â return 0;
> Â}

--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy