[Freedreno] [PATCH v2] 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") Signed-off-by: Miaoqian Lin --- 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(-) diff --git a/drivers/gpu/drm/msm/msm_mdss.c b/drivers/gpu/drm/msm/msm_mdss.c index e13c5c12b775..3b8d6991b04e 100644 --- a/drivers/gpu/drm/msm/msm_mdss.c +++ b/drivers/gpu/drm/msm/msm_mdss.c @@ -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++; -- 2.25.1
[Freedreno] [PATCH] 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. Add icc_put(path1) in the error path to fix this. Fixes: b9364eed9232 ("drm/msm/dpu: Move min BW request and full BW disable back to mdss") Signed-off-by: Miaoqian Lin --- drivers/gpu/drm/msm/msm_mdss.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/msm_mdss.c b/drivers/gpu/drm/msm/msm_mdss.c index e13c5c12b775..a38fa9a9a3d6 100644 --- a/drivers/gpu/drm/msm/msm_mdss.c +++ b/drivers/gpu/drm/msm/msm_mdss.c @@ -49,8 +49,10 @@ static int msm_mdss_parse_data_bus_icc_path(struct device *dev, struct icc_path *path0 = of_icc_get(dev, "mdp0-mem"); struct icc_path *path1 = of_icc_get(dev, "mdp1-mem"); - if (IS_ERR_OR_NULL(path0)) + if (IS_ERR_OR_NULL(path0)) { + icc_put(path1); return PTR_ERR_OR_ZERO(path0); + } msm_mdss->path[0] = path0; msm_mdss->num_paths = 1; -- 2.25.1
Re: [Freedreno] [PATCH] drm/msm/mdp4: Fix refcount leak in mdp4_modeset_init_intf
Hi, Abhinav On 2022/6/11 7:20, Abhinav Kumar wrote: > > > On 6/7/2022 4:08 AM, Miaoqian Lin wrote: >> of_graph_get_remote_node() returns remote device node pointer with >> refcount incremented, we should use of_node_put() on it >> when not need anymore. >> Add missing of_node_put() to avoid refcount leak. >> >> Fixes: 86418f90a4c1 ("drm: convert drivers to use of_graph_get_remote_node") >> Signed-off-by: Miaoqian Lin >> --- >> drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 2 ++ >> 1 file changed, 2 insertions(+) >> > > This patch itself looks fine and will cover the cases when there was an error > and we did not release the refcount. > > But, even in the normal cases I am not finding where we are releasing the > refcount for the panel_node. > > I dont see a of_node_put() on mdp4_lcdc_encoder->panel_node. > Thanks for your review. I don't see it either. It's a bit messy because the reference assigned to mdp4_lcdc_encoder->panel_node and mdp4_lvds_connector->panel_node both. > Am i missing something? > >> diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c >> b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c >> index fb48c8c19ec3..17cb1fc78379 100644 >> --- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c >> +++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c >> @@ -216,6 +216,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms >> *mdp4_kms, >> encoder = mdp4_lcdc_encoder_init(dev, panel_node); >> if (IS_ERR(encoder)) { >> DRM_DEV_ERROR(dev->dev, "failed to construct LCDC encoder\n"); >> + of_node_put(panel_node); >> return PTR_ERR(encoder); >> } >> @@ -225,6 +226,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms >> *mdp4_kms, >> connector = mdp4_lvds_connector_init(dev, panel_node, encoder); >> if (IS_ERR(connector)) { >> DRM_DEV_ERROR(dev->dev, "failed to initialize LVDS >> connector\n"); >> + of_node_put(panel_node); >> return PTR_ERR(connector); >> } >>
[Freedreno] [PATCH] drm/msm/mdp4: Fix refcount leak in mdp4_modeset_init_intf
of_graph_get_remote_node() returns remote device node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak. Fixes: 86418f90a4c1 ("drm: convert drivers to use of_graph_get_remote_node") Signed-off-by: Miaoqian Lin --- drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c index fb48c8c19ec3..17cb1fc78379 100644 --- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c @@ -216,6 +216,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms, encoder = mdp4_lcdc_encoder_init(dev, panel_node); if (IS_ERR(encoder)) { DRM_DEV_ERROR(dev->dev, "failed to construct LCDC encoder\n"); + of_node_put(panel_node); return PTR_ERR(encoder); } @@ -225,6 +226,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms, connector = mdp4_lvds_connector_init(dev, panel_node, encoder); if (IS_ERR(connector)) { DRM_DEV_ERROR(dev->dev, "failed to initialize LVDS connector\n"); + of_node_put(panel_node); return PTR_ERR(connector); } -- 2.25.1
[Freedreno] [PATCH] drm/msm/a6xx: Fix refcount leak in a6xx_gpu_init
of_parse_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. a6xx_gmu_init() passes the node to of_find_device_by_node() and of_dma_configure(), of_find_device_by_node() will takes its reference, of_dma_configure() doesn't need the node after usage. Add missing of_node_put() to avoid refcount leak. Fixes: 4b565ca5a2cb ("drm/msm: Add A6XX device support") Signed-off-by: Miaoqian Lin --- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c index ccc4fcf7a630..a8f6d73197b1 100644 --- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c @@ -1919,6 +1919,7 @@ struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) BUG_ON(!node); ret = a6xx_gmu_init(a6xx_gpu, node); + of_node_put(node); if (ret) { a6xx_destroy(&(a6xx_gpu->base.base)); return ERR_PTR(ret); -- 2.25.1
[Freedreno] [PATCH] drm/msm/hdmi: Fix missing put_device() call in msm_hdmi_get_phy
The reference taken by 'of_find_device_by_node()' must be released when not needed anymore. Add the corresponding 'put_device()' in the error handling path. Fixes: e00012b256d4 ("drm/msm/hdmi: Make HDMI core get its PHY") Signed-off-by: Miaoqian Lin --- drivers/gpu/drm/msm/hdmi/hdmi.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/hdmi/hdmi.c b/drivers/gpu/drm/msm/hdmi/hdmi.c index 75b64e6ae035..a439794a32e8 100644 --- a/drivers/gpu/drm/msm/hdmi/hdmi.c +++ b/drivers/gpu/drm/msm/hdmi/hdmi.c @@ -95,10 +95,15 @@ static int msm_hdmi_get_phy(struct hdmi *hdmi) of_node_put(phy_node); - if (!phy_pdev || !hdmi->phy) { + if (!phy_pdev) { DRM_DEV_ERROR(>dev, "phy driver is not ready\n"); return -EPROBE_DEFER; } + if (!hdmi->phy) { + DRM_DEV_ERROR(>dev, "phy driver is not ready\n"); + put_device(_pdev->dev); + return -EPROBE_DEFER; + } hdmi->phy_dev = get_device(_pdev->dev); -- 2.17.1
[Freedreno] [PATCH] drm/msm/dsi: Fix missing put_device() call in dsi_get_phy
If of_find_device_by_node() succeeds, dsi_get_phy() doesn't a corresponding put_device(). Thus add put_device() to fix the exception handling. Fixes: ec31abf ("drm/msm/dsi: Separate PHY to another platform device") Signed-off-by: Miaoqian Lin --- drivers/gpu/drm/msm/dsi/dsi.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/dsi/dsi.c b/drivers/gpu/drm/msm/dsi/dsi.c index 75ae3008b68f..35be526e907a 100644 --- a/drivers/gpu/drm/msm/dsi/dsi.c +++ b/drivers/gpu/drm/msm/dsi/dsi.c @@ -40,7 +40,12 @@ static int dsi_get_phy(struct msm_dsi *msm_dsi) of_node_put(phy_node); - if (!phy_pdev || !msm_dsi->phy) { + if (!phy_pdev) { + DRM_DEV_ERROR(>dev, "%s: phy driver is not ready\n", __func__); + return -EPROBE_DEFER; + } + if (!msm_dsi->phy) { + put_device(_pdev->dev); DRM_DEV_ERROR(>dev, "%s: phy driver is not ready\n", __func__); return -EPROBE_DEFER; } -- 2.17.1