Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jisheng Zhang" <jszhang@kernel.org>
Cc: devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
	linux-gpio@vger.kernel.org, mfd@lists.linux.dev, robh@kernel.org,
	conor+dt@kernel.org, lee@kernel.org
Subject: Re: [PATCH v4 08/13] pinctrl: berlin: add Synaptics SL2610 pin controller support
Date: Fri, 04 Dec 2026 16:51:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-250237@kernel.org> (raw)
In-Reply-To: <20261204140732.31223-9-jszhang@kernel.org>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] pinctrl: berlin: UAF on sl2610-pinctrl unbind or module unload
- [Medium] pinctrl: berlin: memory leak on error in
  berlin_pinctrl_dt_node_to_map()
- [Medium] pinctrl: berlin: unsafe parent node reuse in
  sl2610_pinctrl_probe()
- [Low] pinctrl: berlin: berlin_pinconf_group_get() returns wrong
  unsupported errno
- [Low] pinctrl: berlin: PINCTRL_SL2610 Kconfig blocks isolated pinctrl
  tree builds
--

commit 4f61b6f2c7486fb1374b1521f40ce612d38b00ad
Author: Jisheng Zhang <jszhang@kernel.org>

pinctrl: berlin: add Synaptics SL2610 pin controller support

This commit adds the Synaptics SL2610 SoC and MCU pin controller driver,
defining their pin groups, mux functions, and pad configuration registers,
and binding to the platform devices created by the parent system controller.

> diff --git a/drivers/pinctrl/berlin/Kconfig b/drivers/pinctrl/berlin/Kconfig
> index abb1c912b9ba0..0ed25151caf41 100644
> --- a/drivers/pinctrl/berlin/Kconfig
> +++ b/drivers/pinctrl/berlin/Kconfig
> @@ -32,4 +32,19 @@ config PINCTRL_BERLIN_BG4CT
>  	depends on OF
>  	select PINCTRL_BERLIN
>  
> +config PINCTRL_SL2610
> +	tristate "Synaptics SL2610 pin controller driver"
> +	depends on MFD_SL2610_SYSCON

[Severity: Low]
As reported by Linus Walleij on v2 [1], does this hard dependency on
MFD_SL2610_SYSCON prevent PINCTRL_SL2610 from being enabled or
compile-tested when the pinctrl patches are applied in isolation?

MFD_SL2610_SYSCON is added by commit "mfd: synaptics: add SL2610 system
controller support", while pinctrl-sl2610.c has no build-time dependency on
it beyond syscon_node_to_regmap() and platform_device_id matching.  Allowing
COMPILE_TEST here (for example, depends on MFD_SL2610_SYSCON || COMPILE_TEST)
and splitting the pinctrl changes into a standalone series would let the
pinctrl tree take them independently.

[ ... ]

> diff --git a/drivers/pinctrl/berlin/pinctrl-sl2610.c b/drivers/pinctrl/berlin/pinctrl-sl2610.c
> new file mode 100644
> index 0000000000000..90b2538597cc7
> --- /dev/null
> +++ b/drivers/pinctrl/berlin/pinctrl-sl2610.c

[ ... ]

> +static void sl2610_pinctrl_clear_node(void *data)
> +{
> +	device_set_node(data, NULL);
> +}
> +
> +static int sl2610_pinctrl_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	const struct berlin_pinctrl_desc *desc =
> +		(void *)platform_get_device_id(pdev)->driver_data;
> +	struct regmap *regmap;
> +	int ret;
> +
> +	regmap = syscon_node_to_regmap(dev->parent->of_node);
> +	if (IS_ERR(regmap))
> +		return dev_err_probe(dev, PTR_ERR(regmap), "Failed to get syscon regmap\n");
> +
> +	device_set_node(dev, dev_fwnode(dev->parent));
> +	ret = devm_add_action_or_reset(dev, sl2610_pinctrl_clear_node, dev);
> +	if (ret)
> +		return ret;

[Severity: Medium]
Can reusing the parent syscon node with device_set_node() and clearing it
in sl2610_pinctrl_clear_node() misreport the device modalias and race with
driver binding to cause a NULL pointer dereference?

Because device_set_node() leaves dev_of_node_reused(dev) false,
of_device_modalias() and of_device_uevent_modalias() report the parent
syscon OF modalias instead of platform:sl2610-soc-pinctrl on probe, and
clearing dev->of_node on a live device during unbind can emit "(null)" in
lockless sysfs modalias/uevent reads.

In addition, of_match_device() matches sl2610_syscon_driver against the
child pinctrl device while dev_of_node_reused(dev) is false.  Because
bind_store() calls driver_match_device() without device_lock(dev) and then
attaches without re-matching, racing sysfs bind on sl2610-syscon against
unbinding sl2610-pinctrl hits a NULL dereference:

CPU0                              CPU1
bind_store() [sl2610-syscon]
  driver_match_device()
    of_match_device() -> match
                                  unbind [sl2610-pinctrl]
                                    devres_release_all()
                                      sl2610_pinctrl_clear_node()
                                        dev->of_node = NULL
                                    device_set_driver(dev, NULL)
  device_driver_attach()
    sl2610_syscon_probe()
      data = device_get_match_data() -> NULL
      data->cells  <-- NULL pointer dereference

Calling platform_device_set_of_node_from_dev(pdev, dev->parent) instead of
device_set_node() and sl2610_pinctrl_clear_node() sets
dev_set_of_node_reused(dev), takes a balanced OF node reference, and avoids
clearing dev->of_node on a live device.

> +
> +	return berlin_pinctrl_probe_regmap(pdev, desc, regmap);

[Severity: Medium]
When pinconf map allocation fails for these BERLIN_PINCTRLCONF_GROUP
controllers, does berlin_pinctrl_dt_node_to_map() leak the reserved
pinctrl_map array and any previously duplicated config arrays?

In commit "pinctrl: berlin: add optional pinconf support", the error path
frees only the temporary configs buffer:

drivers/pinctrl/berlin/berlin.c:berlin_pinctrl_dt_node_to_map() {
    ...
		if (num_configs) {
			ret = pinctrl_utils_add_map_configs(pctrl_dev, map,
					&reserved_maps, num_maps, group_name,
					configs, num_configs,
					PIN_MAP_TYPE_CONFIGS_GROUP);
			if (ret < 0)
				goto exit;
		}
	}

exit:
	kfree(configs);
	return ret;
}

When pinctrl_utils_add_map_configs() returns -ENOMEM (or
pinctrl_utils_add_map_mux() fails), dt_to_map_one_config() returns
immediately without calling dt_free_map(), so *map and earlier per-group
config copies leak unless the error path calls
pinctrl_utils_free_map(pctrl_dev, *map, *num_maps).

[Severity: Low]
Does berlin_pinconf_group_get() return -EOPNOTSUPP instead of -ENOTSUPP for
unsupported pinconf parameters or groups without pinconf registers?

In commit "pinctrl: berlin: add optional pinconf support",
berlin_pinconf_group_get() returns -EOPNOTSUPP when conf_bits is zero and
in the default switch case, but pinconf_generic_dump_one() only skips
-EINVAL and -ENOTSUPP:

drivers/pinctrl/pinconf-generic.c:pinconf_generic_dump_one() {
    ...
		if (ret == -EINVAL || ret == -ENOTSUPP)
			continue;
		if (ret) {
			seq_printf(s, "ERROR READING CONFIG SETTING %d ", i);
			continue;
		}
    ...
}

Reading the pinconf-groups debugfs file will therefore print error messages
for every unsupported generic parameter on SL2610 groups and for all
parameters on legacy Berlin SoCs.

> +}
> +
> +static struct platform_driver sl2610_pinctrl_driver = {
> +	.probe = sl2610_pinctrl_probe,
> +	.id_table = sl2610_pinctrl_ids,
> +	.driver = {
> +		.name = "sl2610-pinctrl",
> +	},
> +};
> +module_platform_driver(sl2610_pinctrl_driver);

[Severity: High]
Can unloading pinctrl-sl2610 or unbinding its platform device via sysfs
cause a use-after-free in bound pinctrl consumers?

Because sl2610_pinctrl_probe() borrows the parent syscon fwnode after the
parent has already claimed fwnode->dev, fw_devlink links DT consumers to
sl2610-syscon rather than to the child pinctrl devices.  In
drivers/pinctrl/berlin/berlin.c, berlin_pctrl_desc leaves link_consumers
false so pinctrl_link_add() adds no consumer device links, and omits
pins/get_group_pins so pin_request() never takes a module reference (and
berlin_pctrl_desc.owner is built-in berlin.c's THIS_MODULE).

Running rmmod pinctrl-sl2610 or unbinding via sysfs therefore runs
pinctrl_unregister() -> kfree(pctldev) and unmaps the module data while
consumers remain bound with dangling setting->pctldev and dt_map->pctldev
pointers.  A subsequent consumer unbind (pinmux_disable_setting() or
dt_free_map()) or pinctrl state change deterministically dereferences the
freed pctldev and unmapped module memory.

Setting link_consumers = true in berlin_pctrl_desc ensures consumer device
links unbind consumers before pinctrl_unregister() runs.

[1] https://lore.kernel.org/r/CAD++jL=TE0pF60vR-Y==z2LDfs4n2rvfZ5FMOuEoFsD2PwMXhw@mail.gmail.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204140732.31223-1-jszhang@kernel.org?part=8

  reply	other threads:[~2026-12-04 16:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 14:07 [PATCH v4 00/13] arm64: add Synaptics SL2610 SoCs and RDK boards Jisheng Zhang
2026-12-04 14:07 ` [PATCH v4 01/13] arm64: kconfig: let ARCH_BERLIN cover Synaptics arm64 SoCs Jisheng Zhang
2026-12-04 14:07 ` [PATCH v4 02/13] pinctrl: berlin: use u16 instead of u8 for the offset Jisheng Zhang
2026-12-04 14:07 ` [PATCH v4 03/13] pinctrl: berlin: enable module build support Jisheng Zhang
2026-12-04 15:03   ` sashiko-bot
2026-12-04 14:07 ` [PATCH v4 04/13] pinctrl: berlin: add optional pinconf support Jisheng Zhang
2026-12-04 15:22   ` sashiko-bot
2026-12-04 14:07 ` [PATCH v4 05/13] dt-bindings: soc: synaptics: add SL2610 system controllers Jisheng Zhang
2026-12-04 15:41   ` sashiko-bot
2026-12-04 14:07 ` [PATCH v4 06/13] mfd: synaptics: add SL2610 system controller support Jisheng Zhang
2026-12-04 15:58   ` sashiko-bot
2026-12-04 14:07 ` [PATCH v4 07/13] reset: add Synaptics SL2610 reset " Jisheng Zhang
2026-12-04 16:24   ` sashiko-bot
2026-12-04 14:07 ` [PATCH v4 08/13] pinctrl: berlin: add Synaptics SL2610 pin " Jisheng Zhang
2026-12-04 16:51   ` sashiko-bot [this message]
2026-12-04 14:07 ` [PATCH v4 09/13] clk: berlin: add Synaptics clock controller helpers Jisheng Zhang
2026-12-04 17:13   ` sashiko-bot
2026-12-04 14:07 ` [PATCH v4 10/13] clk: berlin: add Synaptics SL2610 clocks and PLLs Jisheng Zhang
2026-12-04 17:39   ` sashiko-bot
2026-12-04 14:07 ` [PATCH v4 11/13] dt-bindings: arm: berlin: add Synaptics SL2610 SoCs and RDK boards Jisheng Zhang
2026-12-04 14:07 ` [PATCH v4 12/13] arm64: dts: synaptics: add SL2610 family SoCs Jisheng Zhang
2026-12-04 18:05   ` sashiko-bot
2026-12-04 14:07 ` [PATCH v4 13/13] arm64: dts: synaptics: add SL2610 family RDK boards Jisheng Zhang
2026-12-04 18:19   ` sashiko-bot

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-250237@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jszhang@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=mfd@lists.linux.dev \
    --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