There are several issues in the probe function: 1) of_iomap() return NULL on error but the code checks for error pointers. 2) pinctrl_register() is the reverse. It returns error pointers but the code checks for NULL. 3) The error paths need to call iounmap(data->base) before returning to avoid a resource leak. Fixes: e99ce78030db ("pinctrl: realtek: Add common pinctrl driver for Realtek DHC RTD SoCs") Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx> --- drivers/pinctrl/realtek/pinctrl-rtd.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/pinctrl/realtek/pinctrl-rtd.c b/drivers/pinctrl/realtek/pinctrl-rtd.c index bafe27face80..6c6aa9c3c567 100644 --- a/drivers/pinctrl/realtek/pinctrl-rtd.c +++ b/drivers/pinctrl/realtek/pinctrl-rtd.c @@ -535,14 +535,15 @@ static struct regmap_config rtd_pinctrl_regmap_config = { int rtd_pinctrl_probe(struct platform_device *pdev, const struct rtd_pinctrl_desc *desc) { struct rtd_pinctrl *data; + int ret; data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; data->base = of_iomap(pdev->dev.of_node, 0); - if (IS_ERR(data->base)) - return PTR_ERR(data->base); + if (!data->base) + return -ENOMEM; data->dev = &pdev->dev; data->info = desc; @@ -561,18 +562,25 @@ int rtd_pinctrl_probe(struct platform_device *pdev, const struct rtd_pinctrl_des if (IS_ERR(data->regmap_pinctrl)) { dev_err(data->dev, "failed to init regmap: %ld\n", PTR_ERR(data->regmap_pinctrl)); - return PTR_ERR(data->regmap_pinctrl); + ret = PTR_ERR(data->regmap_pinctrl); + goto unmap; } data->pcdev = pinctrl_register(&data->desc, &pdev->dev, data); - if (!data->pcdev) - return -ENOMEM; + if (IS_ERR(data->pcdev)) { + ret = PTR_ERR(data->pcdev); + goto unmap; + } platform_set_drvdata(pdev, data); dev_dbg(&pdev->dev, "probed\n"); return 0; + +unmap: + iounmap(data->base); + return ret; } EXPORT_SYMBOL(rtd_pinctrl_probe); -- 2.39.2