* [PATCH v2 0/2] pinctrl: starfive: jh7100: validate pins/pinmux groups
@ 2026-12-04 12:45 Zhiqi Zhang
2026-12-04 12:45 ` [PATCH v2 1/2] dt-bindings: pinctrl: starfive,jh7100: Require pins or pinmux Zhiqi Zhang
2026-12-04 12:45 ` [PATCH v2 2/2] pinctrl: starfive: jh7100: Reject malformed pin properties Zhiqi Zhang
0 siblings, 2 replies; 4+ messages in thread
From: Zhiqi Zhang @ 2026-12-04 12:45 UTC (permalink / raw)
To: Linus Walleij, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Emil Renner Berthing, Hal Feng, Drew Fustini, linux-gpio,
devicetree, linux-kernel, Zhiqi Zhang
The JH7100 binding documents each pin group as using exactly one of
"pins" or "pinmux". This series encodes that rule in the schema and
keeps a small driver-side validation helper so unvalidated DTs do not get
silently accepted.
OpenAI Codex helped draft this revision, and I reviewed the result.
Tested with:
- scripts/checkpatch.pl --strict --ignore UNKNOWN_COMMIT_ID --git HEAD~2..HEAD
- gmake DT_SCHEMA_FILES=starfive,jh7100-pinctrl.yaml dt_binding_check
Changes in v2:
- Add schema validation requiring exactly one of "pins" or "pinmux".
- Factor the driver property presence/count checks into a static helper.
Zhiqi Zhang (2):
dt-bindings: pinctrl: starfive,jh7100: Require pins or pinmux
pinctrl: starfive: jh7100: Reject malformed pin properties
.../pinctrl/starfive,jh7100-pinctrl.yaml | 6 ++
.../starfive/pinctrl-starfive-jh7100.c | 61 +++++++++++++------
2 files changed, 49 insertions(+), 18 deletions(-)
--
2.54.0 (Apple Git-157)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] dt-bindings: pinctrl: starfive,jh7100: Require pins or pinmux
2026-12-04 12:45 [PATCH v2 0/2] pinctrl: starfive: jh7100: validate pins/pinmux groups Zhiqi Zhang
@ 2026-12-04 12:45 ` Zhiqi Zhang
2026-12-04 13:16 ` sashiko-bot
2026-12-04 12:45 ` [PATCH v2 2/2] pinctrl: starfive: jh7100: Reject malformed pin properties Zhiqi Zhang
1 sibling, 1 reply; 4+ messages in thread
From: Zhiqi Zhang @ 2026-12-04 12:45 UTC (permalink / raw)
To: Linus Walleij, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Emil Renner Berthing, Hal Feng, Drew Fustini, linux-gpio,
devicetree, linux-kernel, Zhiqi Zhang
Each JH7100 pin group is documented as using either "pins" or
"pinmux", but the schema only described that rule in prose.
Encode the rule with oneOf so binding validation rejects groups that
provide both properties or neither property.
Fixes: ec648f6b7686 ("pinctrl: starfive: Add pinctrl driver for StarFive SoCs")
Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
---
.../bindings/pinctrl/starfive,jh7100-pinctrl.yaml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Documentation/devicetree/bindings/pinctrl/starfive,jh7100-pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/starfive,jh7100-pinctrl.yaml
index 3f14eab01c..f70e2e5fbd 100644
--- a/Documentation/devicetree/bindings/pinctrl/starfive,jh7100-pinctrl.yaml
+++ b/Documentation/devicetree/bindings/pinctrl/starfive,jh7100-pinctrl.yaml
@@ -154,6 +154,12 @@ patternProperties:
description: enable strong pull-up.
type: boolean
+ oneOf:
+ - required:
+ - pins
+ - required:
+ - pinmux
+
additionalProperties: false
additionalProperties: false
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] pinctrl: starfive: jh7100: Reject malformed pin properties
2026-12-04 12:45 [PATCH v2 0/2] pinctrl: starfive: jh7100: validate pins/pinmux groups Zhiqi Zhang
2026-12-04 12:45 ` [PATCH v2 1/2] dt-bindings: pinctrl: starfive,jh7100: Require pins or pinmux Zhiqi Zhang
@ 2026-12-04 12:45 ` Zhiqi Zhang
1 sibling, 0 replies; 4+ messages in thread
From: Zhiqi Zhang @ 2026-12-04 12:45 UTC (permalink / raw)
To: Linus Walleij, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Emil Renner Berthing, Hal Feng, Drew Fustini, linux-gpio,
devicetree, linux-kernel, Zhiqi Zhang
The JH7100 binding allows each pin group to specify either "pinmux"
or "pins", but not both. starfive_dt_node_to_map() used
of_property_count_u32_elems() to decide which property is present, so a
negative parser error was handled the same way as an absent property.
A group that contains a malformed "pinmux" property and a valid "pins"
property is therefore accepted as a "pins" group. Similarly, a malformed
"pins" property can be ignored when a valid "pinmux" property is present.
Use a helper to check property presence separately from array length.
Reject groups that specify both or neither property, and require the
selected u32 array to contain at least one element before sizing and
filling the maps.
I found this issue. OpenAI Codex helped draft the fix, and I reviewed
the result.
Fixes: ec648f6b7686 ("pinctrl: starfive: Add pinctrl driver for StarFive SoCs")
Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
---
.../starfive/pinctrl-starfive-jh7100.c | 61 +++++++++++++------
1 file changed, 43 insertions(+), 18 deletions(-)
diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c b/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c
index d89f6a4722..eea9e8cad9 100644
--- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c
+++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c
@@ -472,6 +472,34 @@ static void starfive_pin_dbg_show(struct pinctrl_dev *pctldev,
#define starfive_pin_dbg_show NULL
#endif
+static int starfive_dt_count_pins(struct device *dev, struct device_node *np,
+ struct device_node *child, bool *is_pinmux)
+{
+ bool has_pinmux = of_property_present(child, "pinmux");
+ bool has_pins = of_property_present(child, "pins");
+ const char *propname;
+ int npins;
+
+ if (has_pinmux && has_pins) {
+ dev_err(dev, "invalid pinctrl group %pOFn.%pOFn: both pinmux and pins set\n",
+ np, child);
+ return -EINVAL;
+ }
+ if (!has_pinmux && !has_pins) {
+ dev_err(dev, "invalid pinctrl group %pOFn.%pOFn: neither pinmux nor pins set\n",
+ np, child);
+ return -EINVAL;
+ }
+
+ *is_pinmux = has_pinmux;
+ propname = has_pinmux ? "pinmux" : "pins";
+ npins = of_property_count_u32_elems(child, propname);
+ if (npins < 1)
+ return npins ?: -EINVAL;
+
+ return npins;
+}
+
static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev,
struct device_node *np,
struct pinctrl_map **maps,
@@ -491,21 +519,14 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev,
nmaps = 0;
ngroups = 0;
for_each_available_child_of_node_scoped(np, child) {
- int npinmux = of_property_count_u32_elems(child, "pinmux");
- int npins = of_property_count_u32_elems(child, "pins");
+ bool is_pinmux;
+ int npins;
- if (npinmux > 0 && npins > 0) {
- dev_err(dev, "invalid pinctrl group %pOFn.%pOFn: both pinmux and pins set\n",
- np, child);
- return -EINVAL;
- }
- if (npinmux == 0 && npins == 0) {
- dev_err(dev, "invalid pinctrl group %pOFn.%pOFn: neither pinmux nor pins set\n",
- np, child);
- return -EINVAL;
- }
+ npins = starfive_dt_count_pins(dev, np, child, &is_pinmux);
+ if (npins < 0)
+ return npins;
- if (npinmux > 0)
+ if (is_pinmux)
nmaps += 2;
else
nmaps += 1;
@@ -524,9 +545,16 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev,
ngroups = 0;
mutex_lock(&sfp->mutex);
for_each_available_child_of_node_scoped(np, child) {
+ bool is_pinmux;
int npins;
int i;
+ npins = starfive_dt_count_pins(dev, np, child, &is_pinmux);
+ if (npins < 0) {
+ ret = npins;
+ goto free_map;
+ }
+
grpname = devm_kasprintf(dev, GFP_KERNEL, "%pOFn.%pOFn", np, child);
if (!grpname) {
ret = -ENOMEM;
@@ -535,7 +563,7 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev,
pgnames[ngroups++] = grpname;
- if ((npins = of_property_count_u32_elems(child, "pinmux")) > 0) {
+ if (is_pinmux) {
pins = devm_kzalloc_objs(dev, *pins, npins);
if (!pins) {
ret = -ENOMEM;
@@ -562,7 +590,7 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev,
map[nmaps].data.mux.function = np->name;
map[nmaps].data.mux.group = grpname;
nmaps += 1;
- } else if ((npins = of_property_count_u32_elems(child, "pins")) > 0) {
+ } else {
pins = devm_kzalloc_objs(dev, *pins, npins);
if (!pins) {
ret = -ENOMEM;
@@ -579,9 +607,6 @@ static int starfive_dt_node_to_map(struct pinctrl_dev *pctldev,
goto free_map;
pins[i] = v;
}
- } else {
- ret = -EINVAL;
- goto free_map;
}
ret = pinctrl_generic_add_group(pctldev, grpname, pins, npins, pinmux);
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: pinctrl: starfive,jh7100: Require pins or pinmux
2026-12-04 12:45 ` [PATCH v2 1/2] dt-bindings: pinctrl: starfive,jh7100: Require pins or pinmux Zhiqi Zhang
@ 2026-12-04 13:16 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-04 13:16 UTC (permalink / raw)
To: Zhiqi Zhang; +Cc: linux-gpio, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dt-bindings: pinctrl: Fixes tag cites driver instead of binding
commit
--
commit 6cd824abfa7ca65904390a9acc0b75289c28b46e
Author: Zhiqi Zhang <zhiqizhangg@gmail.com>
> dt-bindings: pinctrl: starfive,jh7100: Require pins or pinmux
>
> Each JH7100 pin group is documented as using either "pins" or
> "pinmux", but the schema only described that rule in prose.
>
> Encode the rule with oneOf so binding validation rejects groups that
> provide both properties or neither property.
>
> Fixes: ec648f6b7686 ("pinctrl: starfive: Add pinctrl driver for StarFive SoCs")
> Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
[Severity: Low]
Commit ec648f6b7686 ("pinctrl: starfive: Add pinctrl driver for StarFive
SoCs") added the driver and did not touch starfive,jh7100-pinctrl.yaml.
Should the Fixes tag cite the commit that introduced the binding instead?
Fixes: 7431b391df95 ("dt-bindings: pinctrl: Add StarFive JH7100 bindings")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204124531.80365-1-zhiqizhangg@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-04 13:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 12:45 [PATCH v2 0/2] pinctrl: starfive: jh7100: validate pins/pinmux groups Zhiqi Zhang
2026-12-04 12:45 ` [PATCH v2 1/2] dt-bindings: pinctrl: starfive,jh7100: Require pins or pinmux Zhiqi Zhang
2026-12-04 13:16 ` sashiko-bot
2026-12-04 12:45 ` [PATCH v2 2/2] pinctrl: starfive: jh7100: Reject malformed pin properties Zhiqi Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox