[PATCH] pinctrl: berlin: fix error return code of berlin_pinctrl_build_state()

Meng Tang posted 1 patch 4 years, 3 months ago
drivers/pinctrl/berlin/berlin.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] pinctrl: berlin: fix error return code of berlin_pinctrl_build_state()
Posted by Meng Tang 4 years, 3 months ago
When krealloc() fails and pctrl->functions is NULL, no error
return code of berlin_pinctrl_build_state() is assigned.
To fix this bug, ret is assigned with -ENOMEM when pctrl->functions
is NULL.

Signed-off-by: Meng Tang <tangmeng@uniontech.com>
---
 drivers/pinctrl/berlin/berlin.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/berlin/berlin.c b/drivers/pinctrl/berlin/berlin.c
index b17a03cf87be..a073eedd71aa 100644
--- a/drivers/pinctrl/berlin/berlin.c
+++ b/drivers/pinctrl/berlin/berlin.c
@@ -233,6 +233,8 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
 	pctrl->functions = krealloc(pctrl->functions,
 				    pctrl->nfunctions * sizeof(*pctrl->functions),
 				    GFP_KERNEL);
+	if (!pctrl->functions)
+		return -ENOMEM;
 
 	/* map functions to theirs groups */
 	for (i = 0; i < pctrl->desc->ngroups; i++) {
-- 
2.20.1
Re: [PATCH] pinctrl: berlin: fix error return code of berlin_pinctrl_build_state()
Posted by Linus Walleij 4 years, 3 months ago
On Thu, Mar 3, 2022 at 9:02 AM Meng Tang <tangmeng@uniontech.com> wrote:

> When krealloc() fails and pctrl->functions is NULL, no error
> return code of berlin_pinctrl_build_state() is assigned.
> To fix this bug, ret is assigned with -ENOMEM when pctrl->functions
> is NULL.
>
> Signed-off-by: Meng Tang <tangmeng@uniontech.com>

Patch applied!

Yours,
Linus Walleij