[-next] media: amphion: Add missing of_node_put() in vpu_core_parse_dt()

Message ID 20220316081938.80819-1-wangxiongfeng2@huawei.com (mailing list archive)
State Accepted
Headers
Series [-next] media: amphion: Add missing of_node_put() in vpu_core_parse_dt() |

Commit Message

Xiongfeng Wang March 16, 2022, 8:19 a.m. UTC
  of_parse_phandle() will increment the refcount of the returned
device_node. Calling of_node_put() to avoid the refcount leak.

Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
 drivers/media/platform/amphion/vpu_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Ming Qian March 16, 2022, 8:56 a.m. UTC | #1
Hi Xiongfeng,

    Lijun Fang has sent a patch to fix this issue.
See link https://patchwork.linuxtv.org/project/linux-media/patch/20220314060952.66762-1-fanglijun3@huawei.com/

Ming

> From: Xiongfeng Wang [mailto:wangxiongfeng2@huawei.com]
> Sent: Wednesday, March 16, 2022 4:20 PM
> To: Ming Qian <ming.qian@nxp.com>; Shijie Qin <shijie.qin@nxp.com>; Eagle
> Zhou <eagle.zhou@nxp.com>; mchehab@kernel.org
> Cc: linux-media@vger.kernel.org; linux-kernel@vger.kernel.org;
> wangxiongfeng2@huawei.com
> Subject: [PATCH -next] media: amphion: Add missing of_node_put() in
> vpu_core_parse_dt()
> 
> of_parse_phandle() will increment the refcount of the returned device_node.
> Calling of_node_put() to avoid the refcount leak.
> 
> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> ---
>  drivers/media/platform/amphion/vpu_core.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/media/platform/amphion/vpu_core.c
> b/drivers/media/platform/amphion/vpu_core.c
> index 016554387f3f..1da20335bc45 100644
> --- a/drivers/media/platform/amphion/vpu_core.c
> +++ b/drivers/media/platform/amphion/vpu_core.c
> @@ -529,11 +529,14 @@ static int vpu_core_parse_dt(struct vpu_core *core,
> struct device_node *np)
>  	}
>  	if (of_address_to_resource(node, 0, &res)) {
>  		dev_err(core->dev, "boot-region of_address_to_resource error\n");
> +		of_node_put(node);
>  		return -EINVAL;
>  	}
>  	core->fw.phys = res.start;
>  	core->fw.length = resource_size(&res);
> 
> +	of_node_put(node);
> +
>  	node = of_parse_phandle(np, "memory-region", 1);
>  	if (!node) {
>  		dev_err(core->dev, "rpc-region of_parse_phandle error\n"); @@
> -541,6 +544,7 @@ static int vpu_core_parse_dt(struct vpu_core *core, struct
> device_node *np)
>  	}
>  	if (of_address_to_resource(node, 0, &res)) {
>  		dev_err(core->dev, "rpc-region of_address_to_resource error\n");
> +		of_node_put(node);
>  		return -EINVAL;
>  	}
>  	core->rpc.phys = res.start;
> @@ -549,6 +553,7 @@ static int vpu_core_parse_dt(struct vpu_core *core,
> struct device_node *np)
>  	if (core->rpc.length < core->res->rpc_size + core->res->fwlog_size) {
>  		dev_err(core->dev, "the rpc-region <%pad, 0x%x> is not enough\n",
>  			&core->rpc.phys, core->rpc.length);
> +		of_node_put(node);
>  		return -EINVAL;
>  	}
> 
> @@ -560,6 +565,7 @@ static int vpu_core_parse_dt(struct vpu_core *core,
> struct device_node *np)
>  	if (ret != VPU_CORE_MEMORY_UNCACHED) {
>  		dev_err(core->dev, "rpc region<%pad, 0x%x> isn't uncached\n",
>  			&core->rpc.phys, core->rpc.length);
> +		of_node_put(node);
>  		return -EINVAL;
>  	}
> 
> @@ -571,6 +577,8 @@ static int vpu_core_parse_dt(struct vpu_core *core,
> struct device_node *np)
>  	core->act.length = core->rpc.length - core->res->rpc_size -
> core->log.length;
>  	core->rpc.length = core->res->rpc_size;
> 
> +	of_node_put(node);
> +
>  	return 0;
>  }
> 
> --
> 2.20.1
  

Patch

diff --git a/drivers/media/platform/amphion/vpu_core.c b/drivers/media/platform/amphion/vpu_core.c
index 016554387f3f..1da20335bc45 100644
--- a/drivers/media/platform/amphion/vpu_core.c
+++ b/drivers/media/platform/amphion/vpu_core.c
@@ -529,11 +529,14 @@  static int vpu_core_parse_dt(struct vpu_core *core, struct device_node *np)
 	}
 	if (of_address_to_resource(node, 0, &res)) {
 		dev_err(core->dev, "boot-region of_address_to_resource error\n");
+		of_node_put(node);
 		return -EINVAL;
 	}
 	core->fw.phys = res.start;
 	core->fw.length = resource_size(&res);
 
+	of_node_put(node);
+
 	node = of_parse_phandle(np, "memory-region", 1);
 	if (!node) {
 		dev_err(core->dev, "rpc-region of_parse_phandle error\n");
@@ -541,6 +544,7 @@  static int vpu_core_parse_dt(struct vpu_core *core, struct device_node *np)
 	}
 	if (of_address_to_resource(node, 0, &res)) {
 		dev_err(core->dev, "rpc-region of_address_to_resource error\n");
+		of_node_put(node);
 		return -EINVAL;
 	}
 	core->rpc.phys = res.start;
@@ -549,6 +553,7 @@  static int vpu_core_parse_dt(struct vpu_core *core, struct device_node *np)
 	if (core->rpc.length < core->res->rpc_size + core->res->fwlog_size) {
 		dev_err(core->dev, "the rpc-region <%pad, 0x%x> is not enough\n",
 			&core->rpc.phys, core->rpc.length);
+		of_node_put(node);
 		return -EINVAL;
 	}
 
@@ -560,6 +565,7 @@  static int vpu_core_parse_dt(struct vpu_core *core, struct device_node *np)
 	if (ret != VPU_CORE_MEMORY_UNCACHED) {
 		dev_err(core->dev, "rpc region<%pad, 0x%x> isn't uncached\n",
 			&core->rpc.phys, core->rpc.length);
+		of_node_put(node);
 		return -EINVAL;
 	}
 
@@ -571,6 +577,8 @@  static int vpu_core_parse_dt(struct vpu_core *core, struct device_node *np)
 	core->act.length = core->rpc.length - core->res->rpc_size - core->log.length;
 	core->rpc.length = core->res->rpc_size;
 
+	of_node_put(node);
+
 	return 0;
 }