mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Maxwell Doose <m32285159@gmail.com>
Cc: rafael@kernel.org, lenb@kernel.org,
	Andy Shevchenko <andy@kernel.org>,
	Mika Westerberg <westeri@kernel.org>,
	"open list:ACPI PMIC DRIVERS" <linux-acpi@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5] ACPI: pmic: Replace mutex_lock/unlock() with guard()/scoped_guard()
Date: Thu, 30 Apr 2026 09:23:27 +0300	[thread overview]
Message-ID: <afL1X3ywCwJRIz1Z@ashevche-desk.local> (raw)
In-Reply-To: <20260430013507.46259-1-m32285159@gmail.com>

On Wed, Apr 29, 2026 at 08:35:06PM -0500, Maxwell Doose wrote:
> Replace mutex_lock() and unlock() macros with the newer guard() and
> scoped_guard() macros. This will help modernize and clean the code.

...

> -	mutex_lock(&opregion->lock);
> -
> -	if (pmic_thermal_is_temp(address))
> -		result = pmic_thermal_temp(opregion, reg, function, value64);
> -	else if (pmic_thermal_is_aux(address))
> -		result = pmic_thermal_aux(opregion, reg, function, value64);
> -	else if (pmic_thermal_is_pen(address))
> -		result = pmic_thermal_pen(opregion, reg, bit,
> -						function, value64);
> -	else
> -		result = -EINVAL;
> -
> -	mutex_unlock(&opregion->lock);
> +	scoped_guard(mutex, &opregion->lock) {
> +		if (pmic_thermal_is_temp(address))
> +			result = pmic_thermal_temp(opregion, reg, function, value64);
> +		else if (pmic_thermal_is_aux(address))
> +			result = pmic_thermal_aux(opregion, reg, function, value64);
> +		else if (pmic_thermal_is_pen(address))
> +			result = pmic_thermal_pen(opregion, reg, bit, function, value64);
> +		else
> +			result = -EINVAL;
> +	}

>  

This blank line is not needed as previous is coupled with this check.
This is a minor thing, but what takes my attention is the result assignment for
last else. While this is correct code it might provoke false positive warnings
from the compiler(s) that can not properly parse scoped_guard() and proof that
result is always assigned (the warning is something like "uninitialised variable
in use"). Let's wait for CIs to be sure we do not enter a such. Otherwise, this
will need a refactoring like

	result = -EINVAL;
	scoped_guard(...) {
		...
	}

>  	if (result < 0) {
>  		if (result == -EINVAL)

...

>  	if (d->exec_mipi_pmic_seq_element) {
> -		ret = d->exec_mipi_pmic_seq_element(intel_pmic_opregion->regmap,
> +		return d->exec_mipi_pmic_seq_element(intel_pmic_opregion->regmap,
>  						    i2c_address, reg_address,
>  						    value, mask);
> -	} else if (d->pmic_i2c_address) {
> +	}
> +
> +	if (d->pmic_i2c_address) {
>  		if (i2c_address == d->pmic_i2c_address) {

Maybe we should not touch this either and actually have clean guard()() patch +
refactoring returns, dunno... My whole concern here is that this code is not as
simple as IIO switch-cases when we replace break:s with return:s mostly
automatically without breaking readability of anything. Here is different case
and mixing guard()() with return:s refactoring makes it harder to review and
understand. Also if any regression happens, will be harder to maintain.

...

I don't want you to waste more time on experimenting, I think we better
wait for CIs and Rafael, if they all are okay with the change, that will
work for me.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-04-30  6:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-30  1:35 Maxwell Doose
2026-04-30  6:23 ` Andy Shevchenko [this message]
2026-05-08 19:11   ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=afL1X3ywCwJRIz1Z@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m32285159@gmail.com \
    --cc=rafael@kernel.org \
    --cc=westeri@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®