drm/msm/adreno: Fix a reference leak in a6xx_gpu_init()
Subsystems (4)
PATCH 1/1 drm/msm/adreno: Fix a reference leak in a6xx_gpu_init()
In a6xx_gpu_init(), node is obtained via of_parse_phandle(). While there was a manual of_node_put() at the end of the common path, several early error returns would bypass this call, resulting in a reference leak.
Fix this by using the __free(device_node) cleanup handler to release the reference when the variable goes out of scope.
--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +2 -3
@@ -2640,7 +2640,6 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev)struct msm_drm_private *priv = dev->dev_private;struct platform_device *pdev = priv->gpu_pdev;struct adreno_platform_config *config = pdev->dev.platform_data; -struct device_node *node;struct a6xx_gpu *a6xx_gpu;struct adreno_gpu *adreno_gpu;struct msm_gpu *gpu;
@@ -2660,7 +2659,8 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) adreno_gpu->registers =NULL ;/* Check if there is a GMU phandle and set it up */ - node =of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 ); + struct device_node *node __free(device_node) = +of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 );/* FIXME: How do we gracefully handle this? */ BUG_ON (!node);
@@ -2702,7 +2702,6 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) ret =a6xx_gmu_wrapper_init (a6xx_gpu, node); else ret =a6xx_gmu_init (a6xx_gpu, node); -of_node_put (node);if (ret) {a6xx_destroy (&(a6xx_gpu->base.base));return ERR_PTR (ret);
---
base-commit: a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d
change-id: 20260123-a6xx_gpu-cbc095dbe423
Best regards,
Signature · 1 line
Felix Gu <[email protected]>
Quoted 26 lines · Felix Gu
In
a6xx_gpu_init(), node is obtained viaof_parse_phandle(). While there was a manualof_node_put()at the end of the common path, several early error returns would bypass this call, resulting in a reference leak.
Fix this by using the__free(device_node)cleanup handler to release the reference when the variable goes out of scope.Fixes 5a903a44a984 ("drm/msm/a6xx: Introduce GMU wrapper support")Signed-off-by Felix Gu <[email protected]>--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0
-1@@ -2640,7 +2640,6 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev)struct msm_drm_private *priv = dev->dev_private;struct platform_device *pdev = priv->gpu_pdev;struct adreno_platform_config *config = pdev->dev.platform_data; -struct device_node *node;struct a6xx_gpu *a6xx_gpu;struct adreno_gpu *adreno_gpu;struct msm_gpu *gpu;
drivers/gpu/drm/msm/adreno/a6xx_gpu.c static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) · line 2663
Quoted 6 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +2
-1@@ -2660,7 +2659,8 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) adreno_gpu->registers =NULL ;/* Check if there is a GMU phandle and set it up */ - node =of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 ); + struct device_node *node __free(device_node) = +of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 );
Missing include for cleanup.h.
Quoted 20 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0
-2/* FIXME: How do we gracefully handle this? */ BUG_ON (!node);@@ -2702,7 +2702,6 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) ret =a6xx_gmu_wrapper_init (a6xx_gpu, node); else ret =a6xx_gmu_init (a6xx_gpu, node); -of_node_put (node);if (ret) {a6xx_destroy (&(a6xx_gpu->base.base));return ERR_PTR (ret); ---base-commit:
a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d
change-id: 20260123-a6xx_gpu-cbc095dbe423Best regards,
Signature · 1 line
Felix Gu <[email protected]>
Signature · 2 lines
With best wishes Dmitry
Hi Dmitry,
Thanks for your review.linux/cleanup.h is included in linux/of.h.
So it should be included already.
Best regards,
Feix Gu
Quoted 61 lines · Dmitry Baryshkov
Quoted 26 lines · Felix Gu
In
a6xx_gpu_init(), node is obtained viaof_parse_phandle(). While there was a manualof_node_put()at the end of the common path, several early error returns would bypass this call, resulting in a reference leak.
Fix this by using the__free(device_node)cleanup handler to release the reference when the variable goes out of scope.Fixes 5a903a44a984 ("drm/msm/a6xx: Introduce GMU wrapper support")Signed-off-by Felix Gu <[email protected]>--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0
-1@@ -2640,7 +2640,6 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev)struct msm_drm_private *priv = dev->dev_private;struct platform_device *pdev = priv->gpu_pdev;struct adreno_platform_config *config = pdev->dev.platform_data; -struct device_node *node;struct a6xx_gpu *a6xx_gpu;struct adreno_gpu *adreno_gpu;struct msm_gpu *gpu;drivers/gpu/drm/msm/adreno/a6xx_gpu.c static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) · line 2663
Quoted 6 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +2
-1@@ -2660,7 +2659,8 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) adreno_gpu->registers =NULL ;/* Check if there is a GMU phandle and set it up */ - node =of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 ); + struct device_node *node __free(device_node) = +of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 );Missing include for
cleanup.h.Quoted 16 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0
-2/* FIXME: How do we gracefully handle this? */ BUG_ON (!node);@@ -2702,7 +2702,6 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) ret =a6xx_gmu_wrapper_init (a6xx_gpu, node); else ret =a6xx_gmu_init (a6xx_gpu, node); -of_node_put (node);if (ret) {a6xx_destroy (&(a6xx_gpu->base.base));return ERR_PTR (ret); ---base-commit:
a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d
change-id: 20260123-a6xx_gpu-cbc095dbe423Quoted 4 lines
Best regards,
--
Felix Gu <[email protected]>--
With best wishes
Dmitry
Quoted 4 lines · Felix Gu
Hi Dmitry,
Thanks for your review.linux/cleanup.his included inlinux/of.h.
So it should be included already.
Yes. However we should not depend on include files being provided by other kernel-wide includes.
Also, please don't top-post when replying to the emails on public MLs.
Quoted 67 lines
Best regards,
Feix GuQuoted 61 lines · Dmitry Baryshkov
Quoted 26 lines · Felix Gu
In
a6xx_gpu_init(), node is obtained viaof_parse_phandle(). While there was a manualof_node_put()at the end of the common path, several early error returns would bypass this call, resulting in a reference leak.
Fix this by using the__free(device_node)cleanup handler to release the reference when the variable goes out of scope.Fixes 5a903a44a984 ("drm/msm/a6xx: Introduce GMU wrapper support")Signed-off-by Felix Gu <[email protected]>--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0
-1@@ -2640,7 +2640,6 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev)struct msm_drm_private *priv = dev->dev_private;struct platform_device *pdev = priv->gpu_pdev;struct adreno_platform_config *config = pdev->dev.platform_data; -struct device_node *node;struct a6xx_gpu *a6xx_gpu;struct adreno_gpu *adreno_gpu;struct msm_gpu *gpu;drivers/gpu/drm/msm/adreno/a6xx_gpu.c static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) · line 2663
Quoted 6 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +2
-1@@ -2660,7 +2659,8 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) adreno_gpu->registers =NULL ;/* Check if there is a GMU phandle and set it up */ - node =of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 ); + struct device_node *node __free(device_node) = +of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 );Missing include for
cleanup.h.Quoted 16 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0
-2/* FIXME: How do we gracefully handle this? */ BUG_ON (!node);@@ -2702,7 +2702,6 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) ret =a6xx_gmu_wrapper_init (a6xx_gpu, node); else ret =a6xx_gmu_init (a6xx_gpu, node); -of_node_put (node);if (ret) {a6xx_destroy (&(a6xx_gpu->base.base));return ERR_PTR (ret); ---base-commit:
a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d
change-id: 20260123-a6xx_gpu-cbc095dbe423Quoted 4 lines
Best regards,
--
Felix Gu <[email protected]>--
With best wishes
Dmitry
Signature · 2 lines
With best wishes Dmitry
Quoted 9 lines · Dmitry Baryshkov
Quoted 4 lines · Felix Gu
Hi Dmitry,
Thanks for your review.linux/cleanup.his included inlinux/of.h.
So it should be included already.Yes. However we should not depend on include files being provided by other kernel-wide includes.
Understood, I will send out V2 to fix it.
Quoted 2 lines
Also, please don't top-post when replying to the emails on public MLs.
Sorry for that, thanks for coaching.
Best regards,
Felix Gu
Quoted 73 lines
Quoted 68 lines
Best regards,
Feix GuQuoted 61 lines · Dmitry Baryshkov
Quoted 26 lines · Felix Gu
In
a6xx_gpu_init(), node is obtained viaof_parse_phandle(). While there was a manualof_node_put()at the end of the common path, several early error returns would bypass this call, resulting in a reference leak.
Fix this by using the__free(device_node)cleanup handler to release the reference when the variable goes out of scope.Fixes 5a903a44a984 ("drm/msm/a6xx: Introduce GMU wrapper support")Signed-off-by Felix Gu <[email protected]>--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0
-1@@ -2640,7 +2640,6 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev)struct msm_drm_private *priv = dev->dev_private;struct platform_device *pdev = priv->gpu_pdev;struct adreno_platform_config *config = pdev->dev.platform_data; -struct device_node *node;struct a6xx_gpu *a6xx_gpu;struct adreno_gpu *adreno_gpu;struct msm_gpu *gpu;drivers/gpu/drm/msm/adreno/a6xx_gpu.c static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) · line 2663
Quoted 6 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +2
-1@@ -2660,7 +2659,8 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) adreno_gpu->registers =NULL ;/* Check if there is a GMU phandle and set it up */ - node =of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 ); + struct device_node *node __free(device_node) = +of_parse_phandle (pdev->dev.of_node,"qcom,gmu" ,0 );Missing include for
cleanup.h.Quoted 16 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0
-2/* FIXME: How do we gracefully handle this? */ BUG_ON (!node);@@ -2702,7 +2702,6 @@ static struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) ret =a6xx_gmu_wrapper_init (a6xx_gpu, node); else ret =a6xx_gmu_init (a6xx_gpu, node); -of_node_put (node);if (ret) {a6xx_destroy (&(a6xx_gpu->base.base));return ERR_PTR (ret); ---base-commit:
a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d
change-id: 20260123-a6xx_gpu-cbc095dbe423Quoted 4 lines
Best regards,
--
Felix Gu <[email protected]>--
With best wishes
Dmitry--
With best wishes
Dmitry