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

From: Anshuman Khandual
Date: Thu Aug 17 2023 - 00:00:42 EST


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@xxxxxxx>
Cc: Mike Leach <mike.leach@xxxxxxxxxx>
Cc: James Clark <james.clark@xxxxxxx>
Cc: coresight@xxxxxxxxxxxxxxxx
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
Closes: https://lists.linaro.org/archives/list/coresight@xxxxxxxxxxxxxxxx/thread/G4N6P4OXELPLLQSNU3GU2MR4LOLRXRMJ/
Reviewed-by: James Clark <james.clark@xxxxxxx>
Reviewed-by: Mike Leach <mike.leach@xxxxxxxxx>
Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx>
---
This applies on coresight-next

Changes in V2:

- Dropped drvdata->pclk check for non-NULL
- Replaced IS_ERR() with IS_ERR_OR_NULL() for drvdata->pclk

Changes in V1:

https://lore.kernel.org/all/20230811062738.1066787-1-anshuman.khandual@xxxxxxx/

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..77b0271ce6eb 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 && !IS_ERR_OR_NULL(drvdata->pclk))
clk_put(drvdata->pclk);

return 0;
--
2.25.1