2019-03-12 15:20:07

by Aditya Pakki

[permalink] [raw]
Subject: [PATCH] pinctrl: axp209: Fix NULL pointer dereference after allocation

axp20x_build_funcs_groups allocates groups via devm_kcalloc and tries to
dereference without checking for NULL. This patch avoids such a
scenario.

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

diff --git a/drivers/pinctrl/pinctrl-axp209.c b/drivers/pinctrl/pinctrl-axp209.c
index afd0b533c40a..4fcf7262bed9 100644
--- a/drivers/pinctrl/pinctrl-axp209.c
+++ b/drivers/pinctrl/pinctrl-axp209.c
@@ -366,6 +366,8 @@ static int axp20x_build_funcs_groups(struct platform_device *pdev)
pctl->funcs[i].groups = devm_kcalloc(&pdev->dev,
npins, sizeof(char *),
GFP_KERNEL);
+ if (!pctl->funcs[i].groups)
+ return -ENOMEM;
for (pin = 0; pin < npins; pin++)
pctl->funcs[i].groups[pin] = pctl->desc->pins[pin].name;
}
--
2.17.1



2019-03-23 22:13:38

by Aditya Pakki

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: axp209: Fix NULL pointer dereference after allocation

Gentle reminder, Can someone review this patch.


On 3/12/19 10:19 AM, Aditya Pakki wrote:
> axp20x_build_funcs_groups allocates groups via devm_kcalloc and tries to
> dereference without checking for NULL. This patch avoids such a
> scenario.
>
> Signed-off-by: Aditya Pakki <[email protected]>
> ---
> drivers/pinctrl/pinctrl-axp209.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/pinctrl/pinctrl-axp209.c b/drivers/pinctrl/pinctrl-axp209.c
> index afd0b533c40a..4fcf7262bed9 100644
> --- a/drivers/pinctrl/pinctrl-axp209.c
> +++ b/drivers/pinctrl/pinctrl-axp209.c
> @@ -366,6 +366,8 @@ static int axp20x_build_funcs_groups(struct platform_device *pdev)
> pctl->funcs[i].groups = devm_kcalloc(&pdev->dev,
> npins, sizeof(char *),
> GFP_KERNEL);
> + if (!pctl->funcs[i].groups)
> + return -ENOMEM;
> for (pin = 0; pin < npins; pin++)
> pctl->funcs[i].groups[pin] = pctl->desc->pins[pin].name;
> }

2019-04-05 03:39:12

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: axp209: Fix NULL pointer dereference after allocation

On Tue, Mar 12, 2019 at 10:19 PM Aditya Pakki <[email protected]> wrote:

> axp20x_build_funcs_groups allocates groups via devm_kcalloc and tries to
> dereference without checking for NULL. This patch avoids such a
> scenario.
>
> Signed-off-by: Aditya Pakki <[email protected]>

Patch applied.

Yours,
Linus Walleij