Re: [PATCH v3 5/5] arm64: mte: add compression support to mteswap.c

From: Andy Shevchenko
Date: Tue Jul 18 2023 - 10:14:41 EST


On Tue, Jul 18, 2023 at 12:48:00PM +0200, Alexander Potapenko wrote:

...

> > > +void _mte_free_saved_tags(void *storage)
> > > +{
> > > + unsigned long handle = xa_to_value(storage);
> > > + int size;
> > > +
> > > + if (!handle)
> > > + return;
> >
> > Perhaps
> >
> > unsigned long handle;
> >
> > handle = xa_to_value(storage);
> > if (!handle)
> > return;
>
> I don't have a strong preference and am happy to change this, but, out
> of curiosity, why do you think it is better?
> This pattern (calling (even non-)trivial functions when declaring
> variables) is widely used across the kernel.
> Or is it just for consistency with how `handle` is used in the rest of the file?

Ah, it's pure maintenance and error prone approach in case some code is sneezed
in between.

Imagine that you have


foo = bar(x);
...many lines that by some reason don't make one page on the screen...
if (!foo)
...do something...

Now if by unsuccessful rebase or by non-experienced developer we got

foo = bar(x);
...part 1 of many lines that by some reason don't make one page on the screen...
baz(foo);
...part 2 of many lines that by some reason don't make one page on the screen...
if (!foo)
...do something...

the compiler will eliminate the check — you got your mine on the nice minefield!

> > > +}

--
With Best Regards,
Andy Shevchenko