[PATCH] coresight: etm4x: Ensure valid drvdata and clock before clk_put()

Anshuman Khandual anshuman.khandual at arm.com
Thu Aug 10 23:27:38 PDT 2023


This validates 'drvdata' and 'drvdata->pclk' clock before calling clk_put()
in etm4_remove_platform_dev(). The problem was detected using Smatch static
checker as reported.

Cc: Suzuki K Poulose <suzuki.poulose at arm.com>
Cc: Mike Leach <mike.leach at linaro.org>
Cc: James Clark <james.clark at arm.com>
Cc: coresight at lists.linaro.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-kernel at vger.kernel.org
Reported-by: Dan Carpenter <dan.carpenter at linaro.org>
Closes: https://lists.linaro.org/archives/list/coresight@lists.linaro.org/thread/G4N6P4OXELPLLQSNU3GU2MR4LOLRXRMJ/
Signed-off-by: Anshuman Khandual <anshuman.khandual at arm.com>
---
This applies on coresight-next

 drivers/hwtracing/coresight/coresight-etm4x-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
index 703b6fcbb6a5..eb412ce302cc 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -2269,7 +2269,7 @@ static int __exit etm4_remove_platform_dev(struct platform_device *pdev)
 		etm4_remove_dev(drvdata);
 	pm_runtime_disable(&pdev->dev);
 
-	if (drvdata->pclk)
+	if (drvdata && drvdata->pclk && !IS_ERR(drvdata->pclk))
 		clk_put(drvdata->pclk);
 
 	return 0;
-- 
2.25.1




More information about the linux-arm-kernel mailing list