Skip to content

Commit d8c128f

Browse files
duge1975linusw
authored andcommitted
pinctrl: canaan: k230: Fix NULL pointer dereference when parsing devicetree
When probing the k230 pinctrl driver, the kernel triggers a NULL pointer dereference. The crash trace showed: [ 0.732084] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000068 [ 0.740737] ... [ 0.776296] epc : k230_pinctrl_probe+0x1be/0x4fc In k230_pinctrl_parse_functions(), we attempt to retrieve the device pointer via info->pctl_dev->dev, but info->pctl_dev is only initialized after k230_pinctrl_parse_dt() completes. At the time of DT parsing, info->pctl_dev is still NULL, leading to the invalid dereference of info->pctl_dev->dev. Use the already available device pointer from platform_device instead of accessing through uninitialized pctl_dev. Fixes: d94a32a ("pinctrl: canaan: k230: Fix order of DT parse and pinctrl register") Signed-off-by: Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn> Signed-off-by: Linus Walleij <linusw@kernel.org>
1 parent 3533533 commit d8c128f

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

drivers/pinctrl/pinctrl-k230.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct k230_pmx_func {
6565
};
6666

6767
struct k230_pinctrl {
68+
struct device *dev;
6869
struct pinctrl_desc pctl;
6970
struct pinctrl_dev *pctl_dev;
7071
struct regmap *regmap_base;
@@ -470,7 +471,7 @@ static int k230_pinctrl_parse_groups(struct device_node *np,
470471
struct k230_pinctrl *info,
471472
unsigned int index)
472473
{
473-
struct device *dev = info->pctl_dev->dev;
474+
struct device *dev = info->dev;
474475
const __be32 *list;
475476
int size, i, ret;
476477

@@ -511,7 +512,7 @@ static int k230_pinctrl_parse_functions(struct device_node *np,
511512
struct k230_pinctrl *info,
512513
unsigned int index)
513514
{
514-
struct device *dev = info->pctl_dev->dev;
515+
struct device *dev = info->dev;
515516
struct k230_pmx_func *func;
516517
struct k230_pin_group *grp;
517518
static unsigned int idx, i;
@@ -596,6 +597,8 @@ static int k230_pinctrl_probe(struct platform_device *pdev)
596597
if (!info)
597598
return -ENOMEM;
598599

600+
info->dev = dev;
601+
599602
pctl = &info->pctl;
600603

601604
pctl->name = "k230-pinctrl";

0 commit comments

Comments
 (0)