Re: [PATCH v1 1/1] platform/x86: ideapad-laptop: Make the scope_guard() clear of its scope

From: Gergo Koteles
Date: Tue Sep 03 2024 - 11:06:20 EST


Hi Andy,

Thank you for addressing this.

On Thu, 2024-08-29 at 19:50 +0300, Andy Shevchenko wrote:
> First of all, it's a bit counterintuitive to have something like
>
> int err;
> ...
> scoped_guard(...)
> err = foo(...);
> if (err)
> return err;
>
> Second, with a particular kernel configuration and compiler version in
> one of such cases the objtool is not happy:
>
> ideapad-laptop.o: warning: objtool: .text.fan_mode_show: unexpected end of section
>
> I'm not an expert on all this, but the theory is that compiler and
> linker in this case can't understand that 'result' variable will be
> always initialized as long as no error has been returned. Assigning
> 'result' to a dummy value helps with this. Note, that fixing the
> scoped_guard() scope (as per above) does not make issue gone.
>
> That said, assign dummy value and make the scope_guard() clear of its scope.
> For the sake of consistency do it in the entire file.
>

Interestingly, if I open a scope manually and use the plain guard, the
warning disappears.

...
unsigned long result;
int err;

{
guard(mutex)(&priv->vpc_mutex);
err = read_ec_data(priv->adev->handle, VPCCMD_R_FAN,
&result);
if (err)
return err;
}
...

This looks a bit strange, but is probably easier for the compiler than
the for loop of scoped_guard.

But I don't know how well this style fits into the kernel.

Best regards,
Gergo Koteles