[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2a8afc70-c0d8-2b37-9d49-9a054a30ea4b@gmail.com>
Date: Thu, 24 Mar 2022 10:04:44 -0700
From: Florian Fainelli <f.fainelli@...il.com>
To: QintaoShen <unSimple1993@....com>,
Rafał Miłecki <rafal@...ecki.pl>
Cc: bcm-kernel-feedback-list@...adcom.com, linux-mips@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1] soc: bcm: Check for NULL return of devm_kzalloc()
+Rafal,
On 3/24/22 01:35, QintaoShen wrote:
> As the potential failuer of allocation, devm_kzalloc() may return NULL.
s/failuer/failure/
> 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 <unSimple1993@....com>
Fixes: 8bcac4011ebe ("soc: bcm: add PM driver for Broadcom's PMB")
> ---
> drivers/soc/bcm/bcm63xx/bcm-pmb.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/soc/bcm/bcm63xx/bcm-pmb.c b/drivers/soc/bcm/bcm63xx/bcm-pmb.c
> index 7bbe46e..55bf389 100644
> --- a/drivers/soc/bcm/bcm63xx/bcm-pmb.c
> +++ b/drivers/soc/bcm/bcm63xx/bcm-pmb.c
> @@ -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.
>
> pd->pmb = pmb;
> pd->data = e;
--
Florian
Powered by blists - more mailing lists