All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yixun Lan" <dlan@kernel.org>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 2/2] pmdomain: spacemit: Add power domain driver
Date: Wed, 18 Nov 2026 23:32:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-222182@kernel.org> (raw)
In-Reply-To: <20261118-04-k3-pm-support-v5-2-42394acdf3e3@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] pmdomain: spacemit: devres frees active domains when
  pm_genpd_remove() fails
- [Medium] pmdomain: spacemit: unpowered always-on domain in
  spacemit_pm_add_one_domain()
--

commit 3dbb7292ceae5fc8cd5471f6a58e884045deb2ec
Author: Yixun Lan <dlan@kernel.org>

pmdomain: spacemit: Add power domain driver

This commit adds a generic PM domain driver on the auxiliary bus for
SpacemiT K1 and K3 SoCs, supporting software and hardware power-on/off
sequences.

> diff --git a/drivers/pmdomain/spacemit/spacemit-pm-domains.c b/drivers/pmdomain/spacemit/spacemit-pm-domains.c
> new file mode 100644
> index 0000000000000..9d77d3f4c182b
> --- /dev/null
> +++ b/drivers/pmdomain/spacemit/spacemit-pm-domains.c
> @@ -0,0 +1,422 @@

[ ... ]

> +static int spacemit_pm_add_one_domain(struct spacemit_pmu *pmu, int id,
> +				      const struct spacemit_pm_domain_param *param)
> +{
> +	struct spacemit_pm_domain *pd;
> +	int ret;
> +
> +	pd = devm_kzalloc(pmu->dev, sizeof(*pd), GFP_KERNEL);
> +	if (!pd)
> +		return -ENOMEM;
> +
> +	pd->param           = param;
> +	pd->pmu             = pmu;
> +	pd->genpd.name      = param->name;
> +	pd->genpd.flags     = param->flags;
> +	pd->genpd.power_off = spacemit_pd_power_off;
> +	pd->genpd.power_on  = spacemit_pd_power_on;
> +
> +	ret = pm_genpd_init(&pd->genpd, NULL, spacemit_pm_is_off_state(pmu, pd));
> +	if (ret)
> +		return ret;
> +
> +	pmu->domains[id] = &pd->genpd;
> +
> +	return 0;
> +}

[Severity: Medium]
Can pm_genpd_init() fail with -EINVAL for a GENPD_FLAG_ALWAYS_ON domain
such as K3_PMDOMAIN_AUDIO if it is powered off at boot?

pm_genpd_init() requires always-on domains to already be powered on
(is_off == false) and rejects them with -EINVAL otherwise, aborting
spacemit_pm_domain_probe().  Also, because genpd never powers an
always-on domain off or on after initialization, the power control
parameters defined on K3_PMDOMAIN_AUDIO are unused unless
spacemit_pm_add_one_domain() powers the domain on before calling
pm_genpd_init() (note that spacemit_pd_power_on() logs with &domain->dev,
which is not initialized until pm_genpd_init(), so pmu->dev would need to
be used for logging).

> +
> +static void spacemit_pm_domain_cleanup(struct spacemit_pmu *pmu)
> +{
> +	struct spacemit_pm_domain *pd;
> +	int i, ret;
> +
> +	for (i = 0; i < pmu->genpd_data.num_domains; i++) {
> +		if (!pmu->domains[i])
> +			continue;
> +
> +		pd = to_spacemit_pd(pmu->domains[i]);
> +		ret = pm_genpd_remove(pmu->domains[i]);
> +		if (ret)
> +			dev_err(pmu->dev, "failed to remove domain %s: %d - state may be inconsistent\n",
> +				pd->param->name, ret);
> +	}
> +}

[ ... ]

> +static void spacemit_pm_domain_remove(struct auxiliary_device *adev)
> +{
> +	struct spacemit_pmu *pmu = auxiliary_get_drvdata(adev);
> +	struct device *dev = &adev->dev;
> +
> +	of_genpd_del_provider(dev->of_node);
> +	spacemit_pm_domain_cleanup(pmu);
> +}

[Severity: High]
As reported by Troy Mitchell on v3 [1], can unbinding the driver or
unloading the module while a consumer device is attached cause a
use-after-free on pd->genpd?

Because adev->dev shares the parent CCU device's of_node, fw_devlink
links consumers to the parent CCU platform device rather than adev->dev,
so unbinding spacemit_pm_domain_driver does not detach consumer devices
first.  When genpd->device_count > 0, pm_genpd_remove() fails with -EBUSY
and leaves pd->genpd linked in the global gpd_list and referenced by
consumers' dev->pm_domain pointers right before devres frees the
devm_kzalloc()-allocated struct spacemit_pm_domain.

[1] https://lore.kernel.org/r/DMQHSDTR177I.1HWHAF4FWTFQ5@linux.spacemit.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-04-k3-pm-support-v5-0-42394acdf3e3@kernel.org?part=2

      reply	other threads:[~2026-11-18 23:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 23:13 [PATCH v5 0/2] PM: spacemit: Add power domain support Yixun Lan
2026-11-18 23:13 ` Yixun Lan
2026-11-18 23:13 ` [PATCH v5 1/2] dt-bindings: power: spacemit: Add power domain controller IDs Yixun Lan
2026-11-18 23:13   ` Yixun Lan
2026-11-18 23:13 ` [PATCH v5 2/2] pmdomain: spacemit: Add power domain driver Yixun Lan
2026-11-18 23:13   ` Yixun Lan
2026-11-18 23:32   ` sashiko-bot [this message]

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=sashiko-outbox-222182@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlan@kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.