2022-03-25 07:13:31

by QintaoShen

[permalink] [raw]
Subject: [PATCH v1] soc: ti: ti_sci_pm_domains: Check for null return of devm_kcalloc

The allocation funciton devm_kcalloc may fail and return a null pointer,
which would cause a null-pointer dereference later.
It might be better to check it and directly return -ENOMEM just like the
usage of devm_kcalloc in previous code.

Signed-off-by: QintaoShen <[email protected]>
---
drivers/soc/ti/ti_sci_pm_domains.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/soc/ti/ti_sci_pm_domains.c b/drivers/soc/ti/ti_sci_pm_domains.c
index 8afb3f45..a33ec7e 100644
--- a/drivers/soc/ti/ti_sci_pm_domains.c
+++ b/drivers/soc/ti/ti_sci_pm_domains.c
@@ -183,6 +183,8 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev)
devm_kcalloc(dev, max_id + 1,
sizeof(*pd_provider->data.domains),
GFP_KERNEL);
+ if (!pd_provider->data.domains)
+ return -ENOMEM;

pd_provider->data.num_domains = max_id + 1;
pd_provider->data.xlate = ti_sci_pd_xlate;
--
2.7.4


2022-04-16 00:28:59

by Nishanth Menon

[permalink] [raw]
Subject: Re: [PATCH v1] soc: ti: ti_sci_pm_domains: Check for null return of devm_kcalloc

Hi QintaoShen,

On Thu, 24 Mar 2022 15:44:03 +0800, QintaoShen wrote:
> The allocation funciton devm_kcalloc may fail and return a null pointer,
> which would cause a null-pointer dereference later.
> It might be better to check it and directly return -ENOMEM just like the
> usage of devm_kcalloc in previous code.
>
>

I have applied the following to branch ti-drivers-soc-next on [1].
Thank you!

[1/1] soc: ti: ti_sci_pm_domains: Check for null return of devm_kcalloc
commit: ba56291e297d28aa6eb82c5c1964fae2d7594746

Sidenote: [PATCH] is sufficient for v1 of the patch, it is understood to be
default indexed from 1 ;). Ofcourse, an update of the patch would have been
posted as [PATCH V2] and so on..

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent up the chain during
the next merge window (or sooner if it is a relevant bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

[1] git://git.kernel.org/pub/scm/linux/kernel/git/ti/linux.git
--
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3 1A34 DDB5 849D 1736 249D