soc: bcm: Check for NULL return of devm_kzalloc()
PATCH 1/1 soc: bcm: Check for NULL return of devm_kzalloc()
As the potential failuer of allocation, devm_kzalloc() may return NULL. Then the 'pd->pmb' and the follow lines of code may bring null pointer dereference.
Therefore, it is better to check the return value of devm_kzalloc() to avoid this confusion.
--- drivers/soc/bcm/bcm63xx/bcm-pmb.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/soc/bcm/bcm63xx/bcm-pmb.c +2 -0
@@ -311,6 +311,8 @@ static int bcm_pmb_probe(struct platform_device *pdev)for (e = table; e->name; e++) {struct bcm_pmb_pm_domain *pd =devm_kzalloc (dev,sizeof (*pd),GFP_KERNEL ); +if (!pd) +return -ENOMEM ; pd->pmb = pmb; pd->data = e;
Signature · 1 line
2.7.4
+Rafal,
Quoted 1 line · QintaoShen
As the potential failuer of allocation,
devm_kzalloc()may return NULL.
s/failuer/failure/
Quoted 5 lines
Then the '
pd->pmb' and the follow lines of code may bring null pointer dereference.Therefore, it is better to check the return value of
devm_kzalloc()to avoid this confusion.Signed-off-by QintaoShen <[email protected]>
Quoted 9 lines
--- drivers/soc/bcm/bcm63xx/bcm-pmb.c | 2 ++ 1 file changed, 2 insertions(+)drivers/soc/bcm/bcm63xx/bcm-pmb.c +0
-0
drivers/soc/bcm/bcm63xx/bcm-pmb.c static int bcm_pmb_probe(struct platform_device *pdev) · line 315
Quoted 5 lines
drivers/soc/bcm/bcm63xx/bcm-pmb.c +2
-0@@ -311,6 +311,8 @@ static int bcm_pmb_probe(struct platform_device *pdev)for (e = table; e->name; e++) {struct bcm_pmb_pm_domain *pd =devm_kzalloc (dev,sizeof (*pd),GFP_KERNEL ); +if (!pd) +return -ENOMEM ;
I am of two minds as to what the appropriate behavior could be here, we could equally use an:
if (!pd) continue;
or do what you are doing.
Quoted 3 lines
drivers/soc/bcm/bcm63xx/bcm-pmb.c +0
-0pd->pmb = pmb; pd->data = e;
Signature · 1 line
Florian
Hello!
s/return/result/ in the subject.
Quoted 2 lines · QintaoShen
As the potential failuer of allocation,
devm_kzalloc()may return NULL. Then the 'pd->pmb' and the follow lines of code may bring null pointer dereference.
Following.
Quoted 12 lines
Therefore, it is better to check the return value of
devm_kzalloc()to avoid this confusion.Signed-off-by QintaoShen <[email protected]>--- drivers/soc/bcm/bcm63xx/bcm-pmb.c | 2 ++ 1 file changed, 2 insertions(+)drivers/soc/bcm/bcm63xx/bcm-pmb.c +0
-0
drivers/soc/bcm/bcm63xx/bcm-pmb.c static int bcm_pmb_probe(struct platform_device *pdev) · line 313
Quoted 3 lines
drivers/soc/bcm/bcm63xx/bcm-pmb.c +0
-0@@ -311,6 +311,8 @@ static int bcm_pmb_probe(struct platform_device *pdev)for (e = table; e->name; e++) {struct bcm_pmb_pm_domain *pd =devm_kzalloc (dev,sizeof (*pd),GFP_KERNEL );
Please keep an empty line after declaration.
drivers/soc/bcm/bcm63xx/bcm-pmb.c static int bcm_pmb_probe(struct platform_device *pdev) · line 318
Quoted 5 lines
drivers/soc/bcm/bcm63xx/bcm-pmb.c +2
-0+if (!pd) +return -ENOMEM ; pd->pmb = pmb; pd->data = e;
MBR, Sergey
OK. Here is the new version.
---
drivers/soc/bcm/bcm63xx/bcm-pmb.c | 3 +++
1 file changed, 3 insertions(+)
drivers/soc/bcm/bcm63xx/bcm-pmb.c +0 -0
@@ -312,6 +312,9 @@ static int bcm_pmb_probe(struct platform_device *pdev)
for (e = table; e->name; e++) {
struct bcm_pmb_pm_domain *pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
+ if (!pd)
+ return -ENOMEM;
+
pd->pmb = pmb;
pd->data = e;
pd->genpd.name = e->name;
Signature · 1 line
2.7.4
Quoted 33 lines · Sergey Shtylyov
Hello!
s/return/result/ in the subject.
Quoted 2 lines · QintaoShen
As the potential failuer of allocation,
devm_kzalloc()may return NULL. Then the 'pd->pmb' and the follow lines of code may bring null pointer dereference.Following.
Quoted 12 lines
Therefore, it is better to check the return value of
devm_kzalloc()to avoid this confusion.Signed-off-by QintaoShen <[email protected]>--- drivers/soc/bcm/bcm63xx/bcm-pmb.c | 2 ++ 1 file changed, 2 insertions(+)drivers/soc/bcm/bcm63xx/bcm-pmb.c +0
-0drivers/soc/bcm/bcm63xx/bcm-pmb.c static int bcm_pmb_probe(struct platform_device *pdev) · line 313
Quoted 3 lines
drivers/soc/bcm/bcm63xx/bcm-pmb.c +0
-0@@ -311,6 +311,8 @@ static int bcm_pmb_probe(struct platform_device *pdev)for (e = table; e->name; e++) {struct bcm_pmb_pm_domain *pd =devm_kzalloc (dev,sizeof (*pd),GFP_KERNEL );Please keep an empty line after declaration.
drivers/soc/bcm/bcm63xx/bcm-pmb.c static int bcm_pmb_probe(struct platform_device *pdev) · line 318
Quoted 5 lines
drivers/soc/bcm/bcm63xx/bcm-pmb.c +2
-0+if (!pd) +return -ENOMEM ; pd->pmb = pmb; pd->data = e;MBR, Sergey
Florian Fainelli
AppliedQuoted 6 lines · QintaoShen
As the potential failuer of allocation,
devm_kzalloc()may return NULL. Then the 'pd->pmb' and the follow lines of code may bring null pointer dereference.Therefore, it is better to check the return value of
devm_kzalloc()to avoid this confusion.Signed-off-by QintaoShen <[email protected]>
Applied to https://github.com/Broadcom/stblinux/commits/drivers/next, thanks!
I modified your patch to have a Fixes: tag as replied, and follow Sergey's style recommendation.
Signature · 1 line
Florian