* [PATCH 0/2] pinctrl: canaan: k230: Fix DT parsing and registration order
@ 2025-06-23 16:11 Ze Huang
2025-06-23 16:11 ` [PATCH 1/2] pinctrl: canaan: k230: add NULL check in DT parse Ze Huang
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ze Huang @ 2025-06-23 16:11 UTC (permalink / raw)
To: Linus Walleij, Ze Huang; +Cc: linux-gpio, linux-kernel, Ze Huang, Yao Zi
This patch set fixes two issues in the Canaan K230 pinctrl driver:
1. Adds a NULL check for the "pinmux" property in the device tree parser to
prevent potential NULL pointer dereference, and fixes a typo in the
match table comment.
2. Moves the DT parsing step before pinctrl registration to ensure that
pin resources are fully initialized before being used.
Signed-off-by: Ze Huang <huangze@whut.edu.cn>
---
Ze Huang (2):
pinctrl: canaan: k230: add NULL check in DT parse
pinctrl: canaan: k230: Fix order of DT parse and pinctrl register
drivers/pinctrl/pinctrl-k230.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
---
base-commit: d9946fe286439c2aeaa7953b8c316efe5b83d515
change-id: 20250620-k230-return-check-d2ca51963064
Best regards,
--
Ze Huang <huangze@whut.edu.cn>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] pinctrl: canaan: k230: add NULL check in DT parse
2025-06-23 16:11 [PATCH 0/2] pinctrl: canaan: k230: Fix DT parsing and registration order Ze Huang
@ 2025-06-23 16:11 ` Ze Huang
2025-06-23 16:11 ` [PATCH 2/2] pinctrl: canaan: k230: Fix order of DT parse and pinctrl register Ze Huang
2025-06-24 19:36 ` [PATCH 0/2] pinctrl: canaan: k230: Fix DT parsing and registration order Linus Walleij
2 siblings, 0 replies; 4+ messages in thread
From: Ze Huang @ 2025-06-23 16:11 UTC (permalink / raw)
To: Linus Walleij, Ze Huang; +Cc: linux-gpio, linux-kernel, Ze Huang, Yao Zi
Add a NULL check for the return value of of_get_property() when
retrieving the "pinmux" property in the group parser. This avoids
a potential NULL pointer dereference if the property is missing
from the device tree node.
Also fix a typo ("sintenel") in the device ID match table comment,
correcting it to "sentinel".
Fixes: 545887eab6f6 ("pinctrl: canaan: Add support for k230 SoC")
Reported-by: Yao Zi <ziyao@disroot.org>
Signed-off-by: Ze Huang <huangze@whut.edu.cn>
---
drivers/pinctrl/pinctrl-k230.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/pinctrl/pinctrl-k230.c b/drivers/pinctrl/pinctrl-k230.c
index a9b4627b46b01237801103df566b9391f8be21b8..4976308e62372c744738dd8372e73b2494e38e0b 100644
--- a/drivers/pinctrl/pinctrl-k230.c
+++ b/drivers/pinctrl/pinctrl-k230.c
@@ -477,6 +477,10 @@ static int k230_pinctrl_parse_groups(struct device_node *np,
grp->name = np->name;
list = of_get_property(np, "pinmux", &size);
+ if (!list) {
+ dev_err(dev, "failed to get pinmux property\n");
+ return -EINVAL;
+ }
size /= sizeof(*list);
grp->num_pins = size;
@@ -623,7 +627,7 @@ static int k230_pinctrl_probe(struct platform_device *pdev)
static const struct of_device_id k230_dt_ids[] = {
{ .compatible = "canaan,k230-pinctrl", },
- { /* sintenel */ }
+ { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, k230_dt_ids);
--
2.50.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] pinctrl: canaan: k230: Fix order of DT parse and pinctrl register
2025-06-23 16:11 [PATCH 0/2] pinctrl: canaan: k230: Fix DT parsing and registration order Ze Huang
2025-06-23 16:11 ` [PATCH 1/2] pinctrl: canaan: k230: add NULL check in DT parse Ze Huang
@ 2025-06-23 16:11 ` Ze Huang
2025-06-24 19:36 ` [PATCH 0/2] pinctrl: canaan: k230: Fix DT parsing and registration order Linus Walleij
2 siblings, 0 replies; 4+ messages in thread
From: Ze Huang @ 2025-06-23 16:11 UTC (permalink / raw)
To: Linus Walleij, Ze Huang; +Cc: linux-gpio, linux-kernel, Ze Huang, Yao Zi
Move DT parse before pinctrl register. This ensures that device tree
parsing is done before calling devm_pinctrl_register() to prevent using
uninitialized pin resources.
Fixes: 545887eab6f6 ("pinctrl: canaan: Add support for k230 SoC")
Reported-by: Yao Zi <ziyao@disroot.org>
Signed-off-by: Ze Huang <huangze@whut.edu.cn>
---
drivers/pinctrl/pinctrl-k230.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-k230.c b/drivers/pinctrl/pinctrl-k230.c
index 4976308e62372c744738dd8372e73b2494e38e0b..d716f23d837f7a70993a75346561ef0b1e07c3eb 100644
--- a/drivers/pinctrl/pinctrl-k230.c
+++ b/drivers/pinctrl/pinctrl-k230.c
@@ -590,6 +590,7 @@ static int k230_pinctrl_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct k230_pinctrl *info;
struct pinctrl_desc *pctl;
+ int ret;
info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
if (!info)
@@ -615,13 +616,15 @@ static int k230_pinctrl_probe(struct platform_device *pdev)
return dev_err_probe(dev, PTR_ERR(info->regmap_base),
"failed to init regmap\n");
+ ret = k230_pinctrl_parse_dt(pdev, info);
+ if (ret)
+ return ret;
+
info->pctl_dev = devm_pinctrl_register(dev, pctl, info);
if (IS_ERR(info->pctl_dev))
return dev_err_probe(dev, PTR_ERR(info->pctl_dev),
"devm_pinctrl_register failed\n");
- k230_pinctrl_parse_dt(pdev, info);
-
return 0;
}
--
2.50.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] pinctrl: canaan: k230: Fix DT parsing and registration order
2025-06-23 16:11 [PATCH 0/2] pinctrl: canaan: k230: Fix DT parsing and registration order Ze Huang
2025-06-23 16:11 ` [PATCH 1/2] pinctrl: canaan: k230: add NULL check in DT parse Ze Huang
2025-06-23 16:11 ` [PATCH 2/2] pinctrl: canaan: k230: Fix order of DT parse and pinctrl register Ze Huang
@ 2025-06-24 19:36 ` Linus Walleij
2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2025-06-24 19:36 UTC (permalink / raw)
To: Ze Huang; +Cc: Ze Huang, linux-gpio, linux-kernel, Yao Zi
On Mon, Jun 23, 2025 at 6:11 PM Ze Huang <huangze@whut.edu.cn> wrote:
> This patch set fixes two issues in the Canaan K230 pinctrl driver:
>
> 1. Adds a NULL check for the "pinmux" property in the device tree parser to
> prevent potential NULL pointer dereference, and fixes a typo in the
> match table comment.
>
> 2. Moves the DT parsing step before pinctrl registration to ensure that
> pin resources are fully initialized before being used.
>
> Signed-off-by: Ze Huang <huangze@whut.edu.cn>
Patches applied!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-24 19:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-23 16:11 [PATCH 0/2] pinctrl: canaan: k230: Fix DT parsing and registration order Ze Huang
2025-06-23 16:11 ` [PATCH 1/2] pinctrl: canaan: k230: add NULL check in DT parse Ze Huang
2025-06-23 16:11 ` [PATCH 2/2] pinctrl: canaan: k230: Fix order of DT parse and pinctrl register Ze Huang
2025-06-24 19:36 ` [PATCH 0/2] pinctrl: canaan: k230: Fix DT parsing and registration order Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).