Skip to contentSkip to conversation

drm/msm/dpu: Fix memory leak in msm_mdss_parse_data_bus_icc_path

PATCH In review Miaoqian Lin 3 participants 3 messages Dec 7, 2022 – Dec 28, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/msm/dpu: Fix memory leak in msm_mdss_parse_data_bus_icc_path

of_icc_get() alloc resources for path1, we should release it when not need anymore. Early return when IS_ERR_OR_NULL(path0) may leak path1. Defer getting path1 to fix this.

Fixes b9364eed9232 ("drm/msm/dpu: Move min BW request and full BW disable back to mdss")

---
changes in v2:
- move getting path1 after error check for path0.

---
 drivers/gpu/drm/msm/msm_mdss.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/msm_mdss.c +4 -2
index e13c5c12b775..3b8d6991b04e 100644
@@ -46,15 +46,17 @@ struct msm_mdss {
 static int msm_mdss_parse_data_bus_icc_path(struct device *dev,
 					    struct msm_mdss *msm_mdss)
 {
-	struct icc_path *path0 = of_icc_get(dev, "mdp0-mem");
-	struct icc_path *path1 = of_icc_get(dev, "mdp1-mem");
+	struct icc_path *path0;
+	struct icc_path *path1;
 
+	path0 = of_icc_get(dev, "mdp0-mem");
 	if (IS_ERR_OR_NULL(path0))
 		return PTR_ERR_OR_ZERO(path0);
 
 	msm_mdss->path[0] = path0;
 	msm_mdss->num_paths = 1;
 
+	path1 = of_icc_get(dev, "mdp1-mem");
 	if (!IS_ERR_OR_NULL(path1)) {
 		msm_mdss->path[1] = path1;
 		msm_mdss->num_paths++;
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw

Hi,

Quoted 5 lines · Miaoqian Lin

of_icc_get() alloc resources for path1, we should release it when not need anymore. Early return when IS_ERR_OR_NULL(path0) may leak path1. Defer getting path1 to fix this.

Quoted 8 lines
Fixes b9364eed9232 ("drm/msm/dpu: Move min BW request and full BW disable back to mdss")

---
changes in v2:
- move getting path1 after error check for path0.

---
 drivers/gpu/drm/msm/msm_mdss.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Reviewed-by on v2 1/1
#2 lore raw
In reply to Miaoqian Lin
Quoted 6 lines · Miaoqian Lin

of_icc_get() alloc resources for path1, we should release it when not need anymore. Early return when IS_ERR_OR_NULL(path0) may leak path1. Defer getting path1 to fix this.

Fixes b9364eed9232 ("drm/msm/dpu: Move min BW request and full BW disable back to mdss")
Quoted 31 lines

---
changes in v2:
- move getting path1 after error check for path0.

---
  drivers/gpu/drm/msm/msm_mdss.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/msm_mdss.c +4 -2
index e13c5c12b775..3b8d6991b04e 100644
@@ -46,15 +46,17 @@ struct msm_mdss {
  static int msm_mdss_parse_data_bus_icc_path(struct device *dev,
  					    struct msm_mdss *msm_mdss)
  {
-	struct icc_path *path0 = of_icc_get(dev, "mdp0-mem");
-	struct icc_path *path1 = of_icc_get(dev, "mdp1-mem");
+	struct icc_path *path0;
+	struct icc_path *path1;
 
+	path0 = of_icc_get(dev, "mdp0-mem");
  	if (IS_ERR_OR_NULL(path0))
  		return PTR_ERR_OR_ZERO(path0);
 
  	msm_mdss->path[0] = path0;
  	msm_mdss->num_paths = 1;
 
+	path1 = of_icc_get(dev, "mdp1-mem");
  	if (!IS_ERR_OR_NULL(path1)) {
  		msm_mdss->path[1] = path1;
  		msm_mdss->num_paths++;