diff mbox series

[2/3] drm/msm/dpu: Avoid a null de-ref while recovering from kms init fail

Message ID 1557256691-25798-3-git-send-email-jcrouse@codeaurora.org (mailing list archive)
State New, archived
Headers show
Series drm/msm: Handle component bind failures a bit better | expand

Commit Message

Jordan Crouse May 7, 2019, 7:18 p.m. UTC
In the failure path for dpu_kms_init() it is possible to get to the MMU
destroy function with uninitialized MMU structs. Check for NULl and skip
if needed.

Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
---

 drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Kristian Høgsberg May 9, 2019, 3:44 p.m. UTC | #1
On Tue, May 7, 2019 at 12:18 PM Jordan Crouse <jcrouse@codeaurora.org> wrote:
>
> In the failure path for dpu_kms_init() it is possible to get to the MMU
> destroy function with uninitialized MMU structs. Check for NULl and skip

s/NULl/NULL

> if needed.
>
> Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>

> ---
>
>  drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
> index 885bf88..1beaf29 100644
> --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
> +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
> @@ -56,7 +56,7 @@ static const char * const iommu_ports[] = {
>  #define DPU_DEBUGFS_HWMASKNAME "hw_log_mask"
>
>  static int dpu_kms_hw_init(struct msm_kms *kms);
> -static int _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms);
> +static void _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms);
>
>  static unsigned long dpu_iomap_size(struct platform_device *pdev,
>                                     const char *name)
> @@ -725,17 +725,20 @@ static const struct msm_kms_funcs kms_funcs = {
>  #endif
>  };
>
> -static int _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms)
> +static void _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms)
>  {
>         struct msm_mmu *mmu;
>
> +       if (!dpu_kms->base.aspace)
> +               return;
> +
>         mmu = dpu_kms->base.aspace->mmu;
>
>         mmu->funcs->detach(mmu, (const char **)iommu_ports,
>                         ARRAY_SIZE(iommu_ports));
>         msm_gem_address_space_put(dpu_kms->base.aspace);
>
> -       return 0;
> +       dpu_kms->base.aspace = NULL;
>  }
>
>  static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms)
> --
> 2.7.4
>
> _______________________________________________
> Freedreno mailing list
> Freedreno@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/freedreno
diff mbox series

Patch

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
index 885bf88..1beaf29 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
@@ -56,7 +56,7 @@  static const char * const iommu_ports[] = {
 #define DPU_DEBUGFS_HWMASKNAME "hw_log_mask"
 
 static int dpu_kms_hw_init(struct msm_kms *kms);
-static int _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms);
+static void _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms);
 
 static unsigned long dpu_iomap_size(struct platform_device *pdev,
 				    const char *name)
@@ -725,17 +725,20 @@  static const struct msm_kms_funcs kms_funcs = {
 #endif
 };
 
-static int _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms)
+static void _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms)
 {
 	struct msm_mmu *mmu;
 
+	if (!dpu_kms->base.aspace)
+		return;
+
 	mmu = dpu_kms->base.aspace->mmu;
 
 	mmu->funcs->detach(mmu, (const char **)iommu_ports,
 			ARRAY_SIZE(iommu_ports));
 	msm_gem_address_space_put(dpu_kms->base.aspace);
 
-	return 0;
+	dpu_kms->base.aspace = NULL;
 }
 
 static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms)