2019-03-18 23:39:12

by Aditya Pakki

[permalink] [raw]
Subject: [PATCH] pinctrl: berlin: as370: Fix to avoid NULL pointer dereference

of_match_device in as370_pinctrl_probe can return a NULL value
when the matching device is not found. The patch avoids a potential
dereference in such scenario.

Signed-off-by: Aditya Pakki <[email protected]>
---
drivers/pinctrl/berlin/pinctrl-as370.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/berlin/pinctrl-as370.c b/drivers/pinctrl/berlin/pinctrl-as370.c
index 44f8ccdbeeff..78bb5b866c99 100644
--- a/drivers/pinctrl/berlin/pinctrl-as370.c
+++ b/drivers/pinctrl/berlin/pinctrl-as370.c
@@ -337,6 +337,8 @@ static int as370_pinctrl_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;

+ if (!match)
+ return -ENODEV;
rmconfig = devm_kzalloc(&pdev->dev, sizeof(*rmconfig), GFP_KERNEL);
if (!rmconfig)
return -ENOMEM;
--
2.17.1



2019-03-19 05:31:46

by Jisheng Zhang

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: berlin: as370: Fix to avoid NULL pointer dereference

On Mon, 18 Mar 2019 18:37:27 -0500 Aditya Pakki wrote:
>
>
> of_match_device in as370_pinctrl_probe can return a NULL value
> when the matching device is not found. The patch avoids a potential

Similar as the comment to your previous patch, this could not happen.
If the probe is called, it means OF registered a device with a valid
compatible string, so match cannot be NULL.

> dereference in such scenario.
>
> Signed-off-by: Aditya Pakki <[email protected]>
> ---
> drivers/pinctrl/berlin/pinctrl-as370.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/pinctrl/berlin/pinctrl-as370.c b/drivers/pinctrl/berlin/pinctrl-as370.c
> index 44f8ccdbeeff..78bb5b866c99 100644
> --- a/drivers/pinctrl/berlin/pinctrl-as370.c
> +++ b/drivers/pinctrl/berlin/pinctrl-as370.c
> @@ -337,6 +337,8 @@ static int as370_pinctrl_probe(struct platform_device *pdev)
> struct resource *res;
> void __iomem *base;
>
> + if (!match)
> + return -ENODEV;
> rmconfig = devm_kzalloc(&pdev->dev, sizeof(*rmconfig), GFP_KERNEL);
> if (!rmconfig)
> return -ENOMEM;
> --
> 2.17.1
>