2022-07-10 16:08:12

by williamsukatube

[permalink] [raw]
Subject: [PATCH] pinctrl: Add check for kcalloc

From: William Dean <[email protected]>

As the potential failure of the kcalloc(),
it should be better to check it in order to
avoid the dereference of the NULL pointer.

Fixes: aa74c44be19c8 ("pinctrl: Add driver for Sunplus SP7021")
Reported-by: Hacash Robot <[email protected]>
Signed-off-by: William Dean <[email protected]>
---
drivers/pinctrl/sunplus/sppctl.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/pinctrl/sunplus/sppctl.c b/drivers/pinctrl/sunplus/sppctl.c
index 3ba47040ac42..2b3335ab56c6 100644
--- a/drivers/pinctrl/sunplus/sppctl.c
+++ b/drivers/pinctrl/sunplus/sppctl.c
@@ -871,6 +871,9 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node
}

*map = kcalloc(*num_maps + nmG, sizeof(**map), GFP_KERNEL);
+ if (*map == NULL)
+ return -ENOMEM;
+
for (i = 0; i < (*num_maps); i++) {
dt_pin = be32_to_cpu(list[i]);
pin_num = FIELD_GET(GENMASK(31, 24), dt_pin);
--
2.25.1


2022-07-11 13:30:41

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: Add check for kcalloc

On Sun, Jul 10, 2022 at 5:48 PM <[email protected]> wrote:

> From: William Dean <[email protected]>
>
> As the potential failure of the kcalloc(),
> it should be better to check it in order to
> avoid the dereference of the NULL pointer.
>
> Fixes: aa74c44be19c8 ("pinctrl: Add driver for Sunplus SP7021")
> Reported-by: Hacash Robot <[email protected]>
> Signed-off-by: William Dean <[email protected]>

Patch applied, tweaked the subject a bit,

Yours,
Linus Walleij

2022-07-12 08:26:20

by William Dean

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: Add check for kcalloc

thx :)

Linus Walleij <[email protected]> 于2022年7月11日周一 21:04写道:

>
> On Sun, Jul 10, 2022 at 5:48 PM <[email protected]> wrote:
>
> > From: William Dean <[email protected]>
> >
> > As the potential failure of the kcalloc(),
> > it should be better to check it in order to
> > avoid the dereference of the NULL pointer.
> >
> > Fixes: aa74c44be19c8 ("pinctrl: Add driver for Sunplus SP7021")
> > Reported-by: Hacash Robot <[email protected]>
> > Signed-off-by: William Dean <[email protected]>
>
> Patch applied, tweaked the subject a bit,
>
> Yours,
> Linus Walleij