From: sashiko-bot@kernel.org
To: "Gabriel Fernandez" <gabriel.fernandez@foss.st.com>
Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 2/6] soc: st: stm32mp2-syscfg: register the syscon regmap
Date: Wed, 18 Nov 2026 12:37:14 +0000 [thread overview]
Message-ID: <sashiko-outbox-220918@kernel.org> (raw)
In-Reply-To: <20261118-ups_mp25_clk_syscfg-v3-2-935de791a4ce@foss.st.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] soc: st: leak of ioremap and regmap on -EEXIST in
stm32mp2_syscfg_probe()
- [Medium] soc: st: dangling regmap in syscon_list on
stm32mp2_syscfg_probe() failure
- [Medium] soc: st: stm32mp2-syscfg: fw_devlink and initcall order let
consumers create clock-attached syscon regmap first
--
commit 3074d10104a5aee141b2e91cda96d7c4ea358a2e
Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
soc: st: stm32mp2-syscfg: register the syscon regmap
This commit creates an MMIO regmap in stm32mp2_syscfg_probe() and registers
it with the syscon core before populating subnodes so that syscon does not
attach the node's first clock to the regmap.
> diff --git a/drivers/soc/st/stm32mp2-syscfg.c b/drivers/soc/st/stm32mp2-syscfg.c
> index 770321a4a6f71..0d45fdef46b73 100644
> --- a/drivers/soc/st/stm32mp2-syscfg.c
> +++ b/drivers/soc/st/stm32mp2-syscfg.c
> @@ -3,13 +3,55 @@
> * Copyright 2026 Marek Vasut
> */
>
> +#include <linux/mfd/syscon.h>
> #include <linux/module.h>
> #include <linux/of_platform.h>
> #include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +
> +static const struct regmap_config stm32mp2_syscfg_regmap_config = {
> + .reg_bits = 32,
> + .val_bits = 32,
> + .reg_stride = 4,
> +};
>
> static int stm32mp2_syscfg_probe(struct platform_device *pdev)
> {
> - return devm_of_platform_populate(&pdev->dev);
> + struct regmap_config config = stm32mp2_syscfg_regmap_config;
> + struct device *dev = &pdev->dev;
> + struct regmap *regmap;
> + struct resource *res;
> + void __iomem *base;
> + int ret;
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!res)
> + return -ENODEV;
> +
> + /* Not requested: the SDMMC delay blocks lie in the SYSCFG range */
> + base = devm_ioremap(dev, res->start, resource_size(res));
> + if (!base)
> + return -ENOMEM;
> +
> + config.max_register = resource_size(res) - config.reg_stride;
> +
> + regmap = devm_regmap_init_mmio(dev, base, &config);
> + if (IS_ERR(regmap))
> + return dev_err_probe(dev, PTR_ERR(regmap),
> + "failed to init the regmap\n");
> +
> + /*
> + * The SYSCFG registers need no clock, but the generic syscon regmap
> + * would enable the first clock of the node, the LTDC kernel clock
> + * which is only a parent of the pixel clock mux, around each access.
> + */
> + ret = of_syscon_register_regmap(dev->of_node, regmap);
> + if (ret == -EEXIST)
> + dev_warn(dev, "syscon regmap already created, its clock stays attached\n");
[Severity: Medium]
Does the -EEXIST path leave the newly mapped base and regmap allocated on
dev?
When a consumer has already called syscon_node_to_regmap(),
stm32mp2_syscfg_probe() logs a warning and returns 0 via
devm_of_platform_populate(dev) without releasing regmap or unmapping base.
Because the driver is built-in with suppress_bind_attrs = true, the
duplicate 64 KiB mapping, regmap, and debugfs entry remain allocated for
the lifetime of the system, and dev_get_regmap(dev, NULL) points to the
unused regmap instead of the active one in syscon_list.
> + else if (ret)
> + return dev_err_probe(dev, ret, "failed to register the regmap\n");
> +
> + return devm_of_platform_populate(dev);
[Severity: Medium]
If devm_of_platform_populate(dev) fails after of_syscon_register_regmap()
has succeeded, can syscon_list be left with a dangling regmap pointer?
There is no API to unregister a regmap from syscon_list, while a negative
return from stm32mp2_syscfg_probe() triggers devres_release_all(dev),
freeing regmap and unmapping base. Any later syscon lookup for this node
then returns the freed regmap pointer and causes a use-after-free.
> }
>
> static const struct of_device_id stm32mp2_syscfg_ids[] = {
> @@ -23,10 +65,12 @@ static struct platform_driver stm32mp2_syscfg_driver = {
> .driver = {
> .name = "stm32mp2_syscfg",
> .of_match_table = stm32mp2_syscfg_ids,
> + /* The consumers keep using the regmap */
> + .suppress_bind_attrs = true,
> },
> .probe = stm32mp2_syscfg_probe,
> };
> -module_platform_driver(stm32mp2_syscfg_driver);
> +builtin_platform_driver(stm32mp2_syscfg_driver);
[Severity: Medium]
Will consumers still create the clock-attached syscon regmap before
stm32mp2_syscfg_probe() runs?
Once the SYSCFG DT node lists clocks = <&rcc CK_KER_LTDC>, <&lvds>,
<&clk_dsi_txbyte>, fw_devlink creates supplier links from rcc (and lvds
when enabled) to syscfg. Because rcc depends on scmi_clk, it is not bound
when device_initcall runs through drivers/phy/, drivers/pci/, and
drivers/soc/. Built-in consumers such as phy-stm32-combophy and
pcie-stm32 defer on rcc ahead of syscfg, have no fw_devlink dependency on
syscfg (they look it up via syscon_regmap_lookup_by_compatible() or vendor
properties), and probe first once rcc binds. Because the syscfg node
retains "syscon" in its compatible list, syscon_node_to_regmap() creates
the generic regmap with CK_KER_LTDC attached instead of returning
-EPROBE_DEFER:
drivers/mfd/syscon.c:syscon_node_to_regmap() {
return device_node_get_regmap(np, of_device_is_compatible(np, "syscon"), true);
}
As a result, stm32mp2_syscfg_probe() hits -EEXIST and CK_KER_LTDC stays
prepared and toggled on every SYSCFG access; in addition, if lvds is
enabled without a consumer cycle (for example when CONFIG_DRM_STM_LVDS is
disabled or modular), fw_devlink blocks stm32mp2_syscfg_probe() and delays
populating the USB2 PHY child nodes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-ups_mp25_clk_syscfg-v3-0-935de791a4ce@foss.st.com?part=2
next prev parent reply other threads:[~2026-11-18 12:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 11:59 [PATCH v3 0/6] clk: stm32: Add the STM32MP2 SYSCFG LTDC pixel clock mux Gabriel Fernandez
2026-11-18 11:59 ` [PATCH v3 1/6] dt-bindings: arm: stm32: Add clock inputs to STM32MP2 SYSCFG Gabriel Fernandez
2026-11-18 11:59 ` [PATCH v3 2/6] soc: st: stm32mp2-syscfg: register the syscon regmap Gabriel Fernandez
2026-11-18 12:37 ` sashiko-bot [this message]
2026-11-18 11:59 ` [PATCH v3 3/6] clk: stm32: Add STM32MP25 SYSCFG clock driver Gabriel Fernandez
2026-11-18 11:59 ` [PATCH v3 4/6] soc: st: stm32mp2-syscfg: register the clock device Gabriel Fernandez
2026-11-18 12:13 ` sashiko-bot
2026-11-18 11:59 ` [PATCH v3 5/6] arm64: dts: st: add LTDC pixel clock mux inputs on stm32mp23 Gabriel Fernandez
2026-11-18 11:59 ` [PATCH v3 6/6] arm64: dts: st: add LTDC pixel clock mux inputs on stm32mp25 Gabriel Fernandez
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-220918@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gabriel.fernandez@foss.st.com \
--cc=linux-clk@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox