[PATCH] firmware: qcom: scm: Use __cleanup() for device_node pointers

Kathiravan Thirumoorthy posted 1 patch 2 weeks ago
drivers/firmware/qcom/qcom_scm.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
[PATCH] firmware: qcom: scm: Use __cleanup() for device_node pointers
Posted by Kathiravan Thirumoorthy 2 weeks ago
Make use of the __cleanup() attribute for device_node pointers to simplify
resource management and remove explicit of_node_put() calls.

Signed-off-by: Kathiravan Thirumoorthy <kathiravan.thirumoorthy@oss.qualcomm.com>
---
 drivers/firmware/qcom/qcom_scm.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
index e777b7cb9b127944fe112f453cae9cbc40c06cae..7c1fffa8e7ad48b294b90e7e63f726d0ba7d55e1 100644
--- a/drivers/firmware/qcom/qcom_scm.c
+++ b/drivers/firmware/qcom/qcom_scm.c
@@ -1746,7 +1746,7 @@ EXPORT_SYMBOL_GPL(qcom_scm_gpu_init_regs);
 
 static int qcom_scm_find_dload_address(struct device *dev, u64 *addr)
 {
-	struct device_node *tcsr;
+	struct device_node *tcsr __free(device_node) = NULL;
 	struct device_node *np = dev->of_node;
 	struct resource res;
 	u32 offset;
@@ -1757,7 +1757,6 @@ static int qcom_scm_find_dload_address(struct device *dev, u64 *addr)
 		return 0;
 
 	ret = of_address_to_resource(tcsr, 0, &res);
-	of_node_put(tcsr);
 	if (ret)
 		return ret;
 
@@ -2020,17 +2019,12 @@ static const struct of_device_id qcom_scm_qseecom_allowlist[] __maybe_unused = {
 
 static bool qcom_scm_qseecom_machine_is_allowed(void)
 {
-	struct device_node *np;
-	bool match;
+	struct device_node *np __free(device_node) = of_find_node_by_path("/");
 
-	np = of_find_node_by_path("/");
 	if (!np)
 		return false;
 
-	match = of_match_node(qcom_scm_qseecom_allowlist, np);
-	of_node_put(np);
-
-	return match;
+	return of_match_node(qcom_scm_qseecom_allowlist, np);
 }
 
 static void qcom_scm_qseecom_free(void *data)

---
base-commit: 0c1c7a6a83feaf2cf182c52983ffe330ffb50280
change-id: 20251117-scm_cleanup_of_node_put-6c915216b1bf

Best regards,
-- 
Kathiravan Thirumoorthy <kathiravan.thirumoorthy@oss.qualcomm.com>
Re: [PATCH] firmware: qcom: scm: Use __cleanup() for device_node pointers
Posted by Krzysztof Kozlowski 1 week, 6 days ago
On 17/11/2025 17:22, Kathiravan Thirumoorthy wrote:
> Make use of the __cleanup() attribute for device_node pointers to simplify
> resource management and remove explicit of_node_put() calls.
> 
> Signed-off-by: Kathiravan Thirumoorthy <kathiravan.thirumoorthy@oss.qualcomm.com>
> ---
>  drivers/firmware/qcom/qcom_scm.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
> index e777b7cb9b127944fe112f453cae9cbc40c06cae..7c1fffa8e7ad48b294b90e7e63f726d0ba7d55e1 100644
> --- a/drivers/firmware/qcom/qcom_scm.c
> +++ b/drivers/firmware/qcom/qcom_scm.c
> @@ -1746,7 +1746,7 @@ EXPORT_SYMBOL_GPL(qcom_scm_gpu_init_regs);
>  
>  static int qcom_scm_find_dload_address(struct device *dev, u64 *addr)
>  {
> -	struct device_node *tcsr;
> +	struct device_node *tcsr __free(device_node) = NULL;


NAK.

This is wrong syntax. This must come with constructor.

Don't use cleanup.h if you do not understand its syntax. You just lead
to worse code and encourage bugs.

Best regards,
Krzysztof
Re: [PATCH] firmware: qcom: scm: Use __cleanup() for device_node pointers
Posted by Dmitry Baryshkov 2 weeks ago
On Mon, Nov 17, 2025 at 09:52:55PM +0530, Kathiravan Thirumoorthy wrote:
> Make use of the __cleanup() attribute for device_node pointers to simplify
> resource management and remove explicit of_node_put() calls.
> 
> Signed-off-by: Kathiravan Thirumoorthy <kathiravan.thirumoorthy@oss.qualcomm.com>
> ---
>  drivers/firmware/qcom/qcom_scm.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>


-- 
With best wishes
Dmitry