linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] isoc: mediatek: Fix dereference of null pointer while alloc fail
@ 2021-12-17 16:52 Jiasheng Jiang
  2021-12-17 17:00 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2021-12-17 16:52 UTC (permalink / raw)
  To: matthias.bgg, lgirdwood, broonie
  Cc: linux-arm-kernel, linux-mediatek, linux-kernel, Jiasheng Jiang

Sorry, maybe I do not fully understand the meaning of your review
comments and I really fail to behave polite.
This time I carefully check all the comments and believe I have already
obey all the request.
The message as follow is my new comments.
If there are also problems, please let me know and I will correct in
time.

Because devm_clk_get() will not always success.
It should be better to check the return value in order to
avoid use of error pointer in case of the failure.
Therefore, we should use the IS_ERR() to check the error pointer and
return -ENOMEM if it is and 0 if not.
Also, we deal with the return value in init_scp.

Fixes: 6078c651947a ("soc: mediatek: Refine scpsys to support multiple platform")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog:

v1 -> v2

*Change 1. Correct the commit message.
---
 drivers/soc/mediatek/mtk-scpsys.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
index ca75b14931ec..778d6ffc42b8 100644
--- a/drivers/soc/mediatek/mtk-scpsys.c
+++ b/drivers/soc/mediatek/mtk-scpsys.c
@@ -411,12 +411,16 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
 	return ret;
 }
 
-static void init_clks(struct platform_device *pdev, struct clk **clk)
+static int init_clks(struct platform_device *pdev, struct clk **clk)
 {
 	int i;
 
-	for (i = CLK_NONE + 1; i < CLK_MAX; i++)
+	for (i = CLK_NONE + 1; i < CLK_MAX; i++) {
 		clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
+		if (IS_ERR(clk[i]))
+			return -ENOMEM;
+	}
+	return 0;
 }
 
 static struct scp *init_scp(struct platform_device *pdev,
@@ -426,7 +430,7 @@ static struct scp *init_scp(struct platform_device *pdev,
 {
 	struct genpd_onecell_data *pd_data;
 	struct resource *res;
-	int i, j;
+	int i, j, ret;
 	struct scp *scp;
 	struct clk *clk[CLK_MAX];
 
@@ -481,7 +485,9 @@ static struct scp *init_scp(struct platform_device *pdev,
 
 	pd_data->num_domains = num;
 
-	init_clks(pdev, clk);
+	ret = init_clks(pdev, clk);
+	if (ret)
+		return ERR_PTR(-ENOMEM);
 
 	for (i = 0; i < num; i++) {
 		struct scp_domain *scpd = &scp->domains[i];
-- 
2.25.1


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* Re: [PATCH v2] isoc: mediatek: Fix dereference of null pointer while alloc fail
  2021-12-17 16:52 [PATCH v2] isoc: mediatek: Fix dereference of null pointer while alloc fail Jiasheng Jiang
@ 2021-12-17 17:00 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2021-12-17 17:00 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: matthias.bgg, lgirdwood, linux-arm-kernel, linux-mediatek, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 635 bytes --]

On Sat, Dec 18, 2021 at 12:52:20AM +0800, Jiasheng Jiang wrote:

>  		clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
> +		if (IS_ERR(clk[i]))
> +			return -ENOMEM;

As I and IIRC someone else pointed out there is an error code encoded in
the pointer if IS_ERR() is true, we should use that error code.

Please submit patches using subject lines reflecting the style for the
subsystem, this makes it easier for people to identify relevant patches.
Look at what existing commits in the area you're changing are doing and
make sure your subject lines visually resemble what they're doing.
There's no need to resubmit to fix this alone.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

end of thread, other threads:[~2021-12-17 18:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-17 16:52 [PATCH v2] isoc: mediatek: Fix dereference of null pointer while alloc fail Jiasheng Jiang
2021-12-17 17:00 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).