From: Dmitry Osipenko <digetx@gmail.com>
To: Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt>, Lee Jones <lee@kernel.org>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] mfd: max77620: Avoid regmap mutex deadlock in power-off handler
Date: Wed, 20 May 2026 17:42:19 +0300 [thread overview]
Message-ID: <c8d16352-63a3-4512-b90c-a79e7e96dd3c@gmail.com> (raw)
In-Reply-To: <20260520-max77620_poweroff-v1-1-9186a3bcbe9e@tecnico.ulisboa.pt>
20.05.2026 17:28, Diogo Ivo пишет:
> max77620_pm_power_off() is called via the sys-off framework as a
> SYS_OFF_MODE_POWER_OFF handler, which runs in an atomic notifier chain
> with IRQs disabled after smp_send_stop(). regmap_update_bits() acquires
> the regmap mutex in this path; if another CPU held that mutex when it
> was stopped, the power-off sequence deadlocks.
>
> Replace regmap_update_bits() with i2c_smbus_write_byte_data(), which
> bypasses the regmap lock entirely. The I2C core detects the atomic
> context via i2c_in_atomic_xfer_mode() and uses i2c_trylock_bus() rather
> than a blocking acquisition, avoiding the deadlock.
>
> Tested on Pixel C, powers off correctly.
>
> Assisted-by: Claude:claude-sonnet-4-6
> Fixes: 744b13107d0d ("mfd: max77620: Provide system power-off functionality")
> Cc: stable@vger.kernel.org
> Signed-off-by: Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt>
> ---
> This patch was tested on a local branch that sets pm_power_off =
> max77620_pm_power_off() unconditionally so that the function runs.
> I haven't checked whether the other bits in ONOFFCNFG1 are safe to
> discard at power-off time as I don't have access to the datasheet.
> If someone with access to the datasheet confirms they're not I'll
> respin the patch taking that into account.
> ---
> drivers/mfd/max77620.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mfd/max77620.c b/drivers/mfd/max77620.c
> index 3af2974b3023..8c768968a317 100644
> --- a/drivers/mfd/max77620.c
> +++ b/drivers/mfd/max77620.c
> @@ -487,10 +487,14 @@ static int max77620_read_es_version(struct max77620_chip *chip)
> static void max77620_pm_power_off(void)
> {
> struct max77620_chip *chip = max77620_scratch;
> + struct i2c_client *client = to_i2c_client(chip->dev);
>
> - regmap_update_bits(chip->rmap, MAX77620_REG_ONOFFCNFG1,
> - MAX77620_ONOFFCNFG1_SFT_RST,
> - MAX77620_ONOFFCNFG1_SFT_RST);
> + /*
> + * Atomic context: IRQs disabled. Use raw I2C write, bypassing
> + * regmap locking entirely.
> + */
> + i2c_smbus_write_byte_data(client, MAX77620_REG_ONOFFCNFG1,
> + MAX77620_ONOFFCNFG1_SFT_RST);
> }
>
> static int max77620_probe(struct i2c_client *client)
>
> ---
> base-commit: 27fa82620cbaa89a7fc11ac3057701d598813e87
> change-id: 20260520-max77620_poweroff-08e39429835f
>
> Best regards,
> --
> Diogo Ivo <diogo.ivo@tecnico.ulisboa.pt>
Kernel parks secondary CPUs before powering off system, hence there
shouldn't be a locking contention.
Have you checked whether regmap_write_bits() works?
next prev parent reply other threads:[~2026-05-20 14:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 14:28 Diogo Ivo
2026-05-20 14:42 ` Dmitry Osipenko [this message]
2026-05-20 14:59 ` Diogo Ivo
2026-05-20 16:19 ` Lee Jones
2026-05-20 16:23 ` Mark Brown
2026-05-20 16:44 ` Dmitry Osipenko
2026-05-21 9:19 ` Diogo Ivo
2026-05-27 7:32 ` Dmitry Osipenko
2026-05-21 9:14 ` Diogo Ivo
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=c8d16352-63a3-4512-b90c-a79e7e96dd3c@gmail.com \
--to=digetx@gmail.com \
--cc=diogo.ivo@tecnico.ulisboa.pt \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.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
Powered by JetHome