From: "Alexey Klimov" <alexey.klimov@linaro.org>
To: "Peter Griffin" <peter.griffin@linaro.org>,
"Alexey Klimov" <alexey.klimov@linaro.org>
Cc: "Krzysztof Kozlowski" <krzk@kernel.org>,
"Alim Akhtar" <alim.akhtar@samsung.com>,
"Sam Protsenko" <semen.protsenko@linaro.org>,
<linux-samsung-soc@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>,
"Sashiko" <sashiko-bot@kernel.org>
Subject: Re: [PATCH 3/3] soc: samsung: exynos-pmu: fix error paths in cpuhotplug/idle states setup
Date: Wed, 10 Jun 2026 16:07:51 +0100 [thread overview]
Message-ID: <DJ5GP6VQJDHL.2V30K56ME95DO@linaro.org> (raw)
In-Reply-To: <CADrjBPq4fou5KWh4T=oNkUVPz5Jk-821OVe3j5sWrKnCtHYM6w@mail.gmail.com>
On Wed Jun 10, 2026 at 2:34 PM BST, Peter Griffin wrote:
> Hi Alexey,
Hi Peter,
> Thanks for your patch!
>
> On Fri, 5 Jun 2026 at 21:19, Alexey Klimov <alexey.klimov@linaro.org> wrote:
>>
>> The setup_cpuhp_and_cpuidle() initialisation sequence currently ignores
>> the return values of cpuhp_setup_state(), cpu_pm_register_notifier(), and
>> register_reboot_notifier(). If any of these registrations fail during
>> probe() routine, the driver returns 0, leaving the driver partially
>> configured.
>
> I originally made the failure non-fatal because the system still boots
> without the notifiers registered (and all other Arm64 Exynos SoCs
> upstream don't register notifiers and AFAICT have broken cpu hotplug
> and cpu idle).
>
> In hindsight, that seems like a mistake. I think your patch to fully
> unwind everything in case of failure makes more sense. See small
> comment below about destroy_cpuhp_and_cpuidle()
Wait, setup_cpuhp_and_cpuidle() should be non-fatal and shouldn't
return any errors?
Why do we need to have notifiers (say cpu_pm_register_notifier())
registered if, for instance, cpuhp_setup_state() fails?
The other thing I didn't get is that this doesn't deal with handling
errors/return values of cpuhp_setup_state() in probe() and there
are still a lot of errors returned from setup_cpuhp_and_cpuidle().
>> Furthermore, if anything after setup_cpuhp_and_cpuidle() fails in probe()
>> routine, for instance devm_mfd_add_devices(), the probe() lacks an error
>> path and leaves notifiers and cpu hotplug states registered.
>>
>> Introduce variables for the cpu hotplug state IDs in exynos_pmu_context
>> struct, that should be initialised to CPUHP_INVALID by default. Check all
>> return codes in setup_cpuhp_and_cpuidle(), and add an error path to remove
>> registered states on failure. Finally, add destroy_cpuhp_and_cpuidle()
>> helper to safely tear down notifiers and cpu hotplug states.
>>
>> Reported-by: Sashiko <sashiko-bot@kernel.org>
>> Closes: https://sashiko.dev/#/patchset/20260513-exynos850-cpuhotplug-v4-0-54fec5f65362@linaro.org?part=3
>> Fixes: 78b72897a5c8 ("soc: samsung: exynos-pmu: Enable CPU Idle for gs101")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Alexey Klimov <alexey.klimov@linaro.org>
>> ---
>> drivers/soc/samsung/exynos-pmu.c | 57 ++++++++++++++++++++++++++++++++++------
>> 1 file changed, 49 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/soc/samsung/exynos-pmu.c b/drivers/soc/samsung/exynos-pmu.c
>> index 9636287f6794..846313a28e9a 100644
>> --- a/drivers/soc/samsung/exynos-pmu.c
>> +++ b/drivers/soc/samsung/exynos-pmu.c
>> @@ -38,6 +38,8 @@ struct exynos_pmu_context {
>> unsigned long *in_cpuhp;
>> bool sys_insuspend;
>> bool sys_inreboot;
>> + int cpuhp_prepare_state;
>> + int cpuhp_online_state;
>> };
>>
>> void __iomem *pmu_base_addr;
>> @@ -404,6 +406,17 @@ static struct notifier_block exynos_cpupm_reboot_nb = {
>> .notifier_call = exynos_cpupm_reboot_notifier,
>> };
>>
>> +static void destroy_cpuhp_and_cpuidle(void)
>> +{
>> + cpu_pm_unregister_notifier(&gs101_cpu_pm_notifier);
>> + unregister_reboot_notifier(&exynos_cpupm_reboot_nb);
>> +
>> + if (pmu_context->cpuhp_prepare_state != CPUHP_INVALID)
>> + cpuhp_remove_state(pmu_context->cpuhp_prepare_state);
>> + if (pmu_context->cpuhp_online_state != CPUHP_INVALID)
>> + cpuhp_remove_state(pmu_context->cpuhp_online_state);
>> +}
>> +
>> static int setup_cpuhp_and_cpuidle(struct device *dev)
>> {
>> struct device_node *intr_gen_node;
>> @@ -465,16 +478,42 @@ static int setup_cpuhp_and_cpuidle(struct device *dev)
>> gs101_cpuhp_pmu_online(cpu);
>>
>> /* register CPU hotplug callbacks */
>> - cpuhp_setup_state(CPUHP_BP_PREPARE_DYN, "soc/exynos-pmu:prepare",
>> - gs101_cpuhp_pmu_online, NULL);
>> + pmu_context->cpuhp_prepare_state = CPUHP_INVALID;
>> + pmu_context->cpuhp_online_state = CPUHP_INVALID;
>>
>> - cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "soc/exynos-pmu:online",
>> - NULL, gs101_cpuhp_pmu_offline);
>> + ret = cpuhp_setup_state(CPUHP_BP_PREPARE_DYN, "soc/exynos-pmu:prepare",
>> + gs101_cpuhp_pmu_online, NULL);
>> + if (ret < 0)
>> + return ret;
>> +
>> + pmu_context->cpuhp_prepare_state = ret;
>> +
>> + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "soc/exynos-pmu:online",
>> + NULL, gs101_cpuhp_pmu_offline);
>> + if (ret < 0)
>> + goto clean_cpuhp_states;
>> +
>> + pmu_context->cpuhp_online_state = ret;
>>
>> /* register CPU PM notifiers for cpuidle */
>> - cpu_pm_register_notifier(&gs101_cpu_pm_notifier);
>> - register_reboot_notifier(&exynos_cpupm_reboot_nb);
>> - return 0;
>> + ret = cpu_pm_register_notifier(&gs101_cpu_pm_notifier);
>> + if (ret)
>> + goto clean_cpuhp_states;
>> +
>> + ret = register_reboot_notifier(&exynos_cpupm_reboot_nb);
>> + if (!ret)
>> + /* Success */
>> + return ret;
>> +
>> + cpu_pm_unregister_notifier(&gs101_cpu_pm_notifier);
>> +
>> +clean_cpuhp_states:
>> + if (pmu_context->cpuhp_prepare_state != CPUHP_INVALID)
>> + cpuhp_remove_state(pmu_context->cpuhp_prepare_state);
>> + if (pmu_context->cpuhp_online_state != CPUHP_INVALID)
>> + cpuhp_remove_state(pmu_context->cpuhp_online_state);
>> +
>> + return ret;
>> }
>>
>> static int exynos_pmu_probe(struct platform_device *pdev)
>> @@ -548,8 +587,10 @@ static int exynos_pmu_probe(struct platform_device *pdev)
>>
>> ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, exynos_pmu_devs,
>> ARRAY_SIZE(exynos_pmu_devs), NULL, 0, NULL);
>> - if (ret)
>> + if (ret) {
>> + destroy_cpuhp_and_cpuidle();
>
> You only want to do this if pmu_cpuhp == true, as currently only gs101
> registers the notifiers.
Thanks! That's good catch.
Best regards,
Alexey
next prev parent reply other threads:[~2026-06-10 15:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 20:18 [PATCH 0/3] Exynos PMU fixes for cpu hotplug and cpuidle routines Alexey Klimov
2026-06-05 20:18 ` [PATCH 1/3] soc: samsung: exynos-pmu: use target cpu ID in hotplug callbacks Alexey Klimov
2026-06-10 9:55 ` Peter Griffin
2026-06-05 20:18 ` [PATCH 2/3] soc: samsung: exynos-pmu: fix use-after-free of interrupt generator node Alexey Klimov
2026-06-10 10:58 ` Peter Griffin
2026-06-05 20:18 ` [PATCH 3/3] soc: samsung: exynos-pmu: fix error paths in cpuhotplug/idle states setup Alexey Klimov
2026-06-10 13:34 ` Peter Griffin
2026-06-10 15:07 ` Alexey Klimov [this message]
2026-06-11 7:07 ` Peter Griffin
2026-06-22 18:57 ` Alexey Klimov
2026-06-22 20:43 ` Peter Griffin
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=DJ5GP6VQJDHL.2V30K56ME95DO@linaro.org \
--to=alexey.klimov@linaro.org \
--cc=alim.akhtar@samsung.com \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=peter.griffin@linaro.org \
--cc=sashiko-bot@kernel.org \
--cc=semen.protsenko@linaro.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