All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] soc: qcom: rpmpd: Check for null return of devm_kcalloc
@ 2021-12-31  9:44 Jiasheng Jiang
  2022-02-04 18:35 ` (subset) " Bjorn Andersson
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2021-12-31  9:44 UTC (permalink / raw)
  To: agross, bjorn.andersson; +Cc: linux-arm-msm, linux-kernel, Jiasheng Jiang

Because of the possible failure of the allocation, data->domains might
be NULL pointer and will cause the dereference of the NULL pointer
later.
Therefore, it might be better to check it and directly return -ENOMEM
without releasing data manually if fails, because the comment of the
devm_kmalloc() says "Memory allocated with this function is
automatically freed on driver detach.".

Fixes: bbe3a66c3f5a ("soc: qcom: rpmpd: Add a Power domain driver to model corners")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/soc/qcom/rpmpd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/soc/qcom/rpmpd.c b/drivers/soc/qcom/rpmpd.c
index 27733b0e7fca..f4ef8a100c99 100644
--- a/drivers/soc/qcom/rpmpd.c
+++ b/drivers/soc/qcom/rpmpd.c
@@ -496,6 +496,9 @@ static int rpmpd_probe(struct platform_device *pdev)
 
 	data->domains = devm_kcalloc(&pdev->dev, num, sizeof(*data->domains),
 				     GFP_KERNEL);
+	if (!data->domains)
+		return -ENOMEM;
+
 	data->num_domains = num;
 
 	for (i = 0; i < num; i++) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: (subset) [PATCH] soc: qcom: rpmpd: Check for null return of devm_kcalloc
  2021-12-31  9:44 [PATCH] soc: qcom: rpmpd: Check for null return of devm_kcalloc Jiasheng Jiang
@ 2022-02-04 18:35 ` Bjorn Andersson
  0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Andersson @ 2022-02-04 18:35 UTC (permalink / raw)
  To: agross, Jiasheng Jiang; +Cc: linux-arm-msm, linux-kernel

On Fri, 31 Dec 2021 17:44:19 +0800, Jiasheng Jiang wrote:
> Because of the possible failure of the allocation, data->domains might
> be NULL pointer and will cause the dereference of the NULL pointer
> later.
> Therefore, it might be better to check it and directly return -ENOMEM
> without releasing data manually if fails, because the comment of the
> devm_kmalloc() says "Memory allocated with this function is
> automatically freed on driver detach.".
> 
> [...]

Applied, thanks!

[1/1] soc: qcom: rpmpd: Check for null return of devm_kcalloc
      commit: 5a811126d38f9767a20cc271b34db7c8efc5a46c

Best regards,
-- 
Bjorn Andersson <bjorn.andersson@linaro.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-04 18:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31  9:44 [PATCH] soc: qcom: rpmpd: Check for null return of devm_kcalloc Jiasheng Jiang
2022-02-04 18:35 ` (subset) " Bjorn Andersson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.