Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: d94a32ac688f ("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>

authored by

Jiayu Du and committed by
Linus Walleij
d8c128fb 35335330

+5 -2
+5 -2
drivers/pinctrl/pinctrl-k230.c
··· 65 65 }; 66 66 67 67 struct k230_pinctrl { 68 + struct device *dev; 68 69 struct pinctrl_desc pctl; 69 70 struct pinctrl_dev *pctl_dev; 70 71 struct regmap *regmap_base; ··· 471 470 struct k230_pinctrl *info, 472 471 unsigned int index) 473 472 { 474 - struct device *dev = info->pctl_dev->dev; 473 + struct device *dev = info->dev; 475 474 const __be32 *list; 476 475 int size, i, ret; 477 476 ··· 512 511 struct k230_pinctrl *info, 513 512 unsigned int index) 514 513 { 515 - struct device *dev = info->pctl_dev->dev; 514 + struct device *dev = info->dev; 516 515 struct k230_pmx_func *func; 517 516 struct k230_pin_group *grp; 518 517 static unsigned int idx, i; ··· 596 595 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); 597 596 if (!info) 598 597 return -ENOMEM; 598 + 599 + info->dev = dev; 599 600 600 601 pctl = &info->pctl; 601 602