Skip to contentSkip to conversation

drm/etnaviv: Fix missing mutex_destroy()

PATCH Applied Sui Jingfeng 3 participants 3 messages Aug 25, 2024 – Oct 28, 2024

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

PATCH 1/1 drm/etnaviv: Fix missing mutex_destroy()

Currently, the calling of mutex_destroy() is ignored on error handling code path. It is safe for now, since mutex_destroy() actually does nothing in non-debug builds. But the mutex_destroy() is used to mark the mutex uninitialized on debug builds, and any subsequent use of the mutex is forbidden.

It also could lead to problems if mutex_destroy() gets extended, add missing mutex_destroy() to eliminate potential concerns.

---
 drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c | 3 +++
 drivers/gpu/drm/etnaviv/etnaviv_drv.c    | 1 +
 drivers/gpu/drm/etnaviv/etnaviv_gem.c    | 1 +
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c    | 5 +++++
 drivers/gpu/drm/etnaviv/etnaviv_mmu.c    | 2 +-
 5 files changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c +3 -0
index 721d633aece9..1edc02022be4 100644
@@ -79,6 +79,9 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc)
 {
 	dma_free_wc(suballoc->dev, SUBALLOC_SIZE, suballoc->vaddr,
 		    suballoc->paddr);
+
+	mutex_destroy(&suballoc->lock);
+
 	kfree(suballoc);
 }
 
drivers/gpu/drm/etnaviv/etnaviv_drv.c +1 -0
index 6500f3999c5f..7844cd961a29 100644
@@ -564,6 +564,7 @@ static int etnaviv_bind(struct device *dev)
 out_destroy_suballoc:
 	etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc);
 out_free_priv:
+	mutex_destroy(&priv->gem_lock);
 	kfree(priv);
 out_put:
 	drm_dev_put(drm);
drivers/gpu/drm/etnaviv/etnaviv_gem.c +1 -0
index fe665ca20c02..b68e3b235a7d 100644
@@ -515,6 +515,7 @@ void etnaviv_gem_free_object(struct drm_gem_object *obj)
 	etnaviv_obj->ops->release(etnaviv_obj);
 	drm_gem_object_release(obj);
 
+	mutex_destroy(&etnaviv_obj->lock);
 	kfree(etnaviv_obj);
 }
 
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +5 -0
index af52922ff494..d6acc4c68102 100644
@@ -1929,8 +1929,13 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
 
 static void etnaviv_gpu_platform_remove(struct platform_device *pdev)
 {
+	struct etnaviv_gpu *gpu = dev_get_drvdata(&pdev->dev);
+
 	component_del(&pdev->dev, &gpu_ops);
 	pm_runtime_disable(&pdev->dev);
+
+	mutex_destroy(&gpu->lock);
+	mutex_destroy(&gpu->sched_lock);
 }
 
 static int etnaviv_gpu_rpm_suspend(struct device *dev)
drivers/gpu/drm/etnaviv/etnaviv_mmu.c +1 -1
index e3be16165c86..ed6c42384856 100644
@@ -361,7 +361,7 @@ static void etnaviv_iommu_context_free(struct kref *kref)
 		container_of(kref, struct etnaviv_iommu_context, refcount);
 
 	etnaviv_cmdbuf_suballoc_unmap(context, &context->cmdbuf_mapping);
-
+	mutex_destroy(&context->lock);
 	context->global->ops->free(context);
 }
 void etnaviv_iommu_context_put(struct etnaviv_iommu_context *context)
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw

Am So., 25. Aug. 2024 um 14:15 Uhr schrieb Sui Jingfeng <[email protected]>:

Quoted 11 lines

Currently, the calling of mutex_destroy() is ignored on error handling code path. It is safe for now, since mutex_destroy() actually does nothing in non-debug builds. But the mutex_destroy() is used to mark the mutex uninitialized on debug builds, and any subsequent use of the mutex is forbidden.

It also could lead to problems if mutex_destroy() gets extended, add missing mutex_destroy() to eliminate potential concerns.

Quoted 80 lines
---
 drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c | 3 +++
 drivers/gpu/drm/etnaviv/etnaviv_drv.c    | 1 +
 drivers/gpu/drm/etnaviv/etnaviv_gem.c    | 1 +
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c    | 5 +++++
 drivers/gpu/drm/etnaviv/etnaviv_mmu.c    | 2 +-
 5 files changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c +3 -0
index 721d633aece9..1edc02022be4 100644
@@ -79,6 +79,9 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc)
 {
        dma_free_wc(suballoc->dev, SUBALLOC_SIZE, suballoc->vaddr,
                    suballoc->paddr);
+
+       mutex_destroy(&suballoc->lock);
+
        kfree(suballoc);
 }
 
drivers/gpu/drm/etnaviv/etnaviv_drv.c +1 -0
index 6500f3999c5f..7844cd961a29 100644
@@ -564,6 +564,7 @@ static int etnaviv_bind(struct device *dev)
 out_destroy_suballoc:
        etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc);
 out_free_priv:
+       mutex_destroy(&priv->gem_lock);
        kfree(priv);
 out_put:
        drm_dev_put(drm);
drivers/gpu/drm/etnaviv/etnaviv_gem.c +1 -0
index fe665ca20c02..b68e3b235a7d 100644
@@ -515,6 +515,7 @@ void etnaviv_gem_free_object(struct drm_gem_object *obj)
        etnaviv_obj->ops->release(etnaviv_obj);
        drm_gem_object_release(obj);
 
+       mutex_destroy(&etnaviv_obj->lock);
        kfree(etnaviv_obj);
 }
 
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +5 -0
index af52922ff494..d6acc4c68102 100644
@@ -1929,8 +1929,13 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
 
 static void etnaviv_gpu_platform_remove(struct platform_device *pdev)
 {
+       struct etnaviv_gpu *gpu = dev_get_drvdata(&pdev->dev);
+
        component_del(&pdev->dev, &gpu_ops);
        pm_runtime_disable(&pdev->dev);
+
+       mutex_destroy(&gpu->lock);
+       mutex_destroy(&gpu->sched_lock);
 }
 
 static int etnaviv_gpu_rpm_suspend(struct device *dev)
drivers/gpu/drm/etnaviv/etnaviv_mmu.c +1 -2
index e3be16165c86..ed6c42384856 100644
@@ -361,7 +361,7 @@ static void etnaviv_iommu_context_free(struct kref *kref)
                container_of(kref, struct etnaviv_iommu_context, refcount);
 
        etnaviv_cmdbuf_suballoc_unmap(context, &context->cmdbuf_mapping);
-
+       mutex_destroy(&context->lock);
        context->global->ops->free(context);
 }
 void etnaviv_iommu_context_put(struct etnaviv_iommu_context *context)
--

2.34.1

Signature · 5 lines
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info/privacypolicy
maintainer Applied
#2 lore raw
In reply to Sui Jingfeng

Am Sonntag, dem 25.08.2024 um 20:14 +0800 schrieb Sui Jingfeng:

Quoted 10 lines

Currently, the calling of mutex_destroy() is ignored on error handling code path. It is safe for now, since mutex_destroy() actually does nothing in non-debug builds. But the mutex_destroy() is used to mark the mutex uninitialized on debug builds, and any subsequent use of the mutex is forbidden.

It also could lead to problems if mutex_destroy() gets extended, add missing mutex_destroy() to eliminate potential concerns.

Thanks, applied to etnaviv/next.

Quoted 77 lines
---
 drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c | 3 +++
 drivers/gpu/drm/etnaviv/etnaviv_drv.c    | 1 +
 drivers/gpu/drm/etnaviv/etnaviv_gem.c    | 1 +
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c    | 5 +++++
 drivers/gpu/drm/etnaviv/etnaviv_mmu.c    | 2 +-
 5 files changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c +3 -0
index 721d633aece9..1edc02022be4 100644
@@ -79,6 +79,9 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc)
 {
 	dma_free_wc(suballoc->dev, SUBALLOC_SIZE, suballoc->vaddr,
 		    suballoc->paddr);
+
+	mutex_destroy(&suballoc->lock);
+
 	kfree(suballoc);
 }
 
drivers/gpu/drm/etnaviv/etnaviv_drv.c +1 -0
index 6500f3999c5f..7844cd961a29 100644
@@ -564,6 +564,7 @@ static int etnaviv_bind(struct device *dev)
 out_destroy_suballoc:
 	etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc);
 out_free_priv:
+	mutex_destroy(&priv->gem_lock);
 	kfree(priv);
 out_put:
 	drm_dev_put(drm);
drivers/gpu/drm/etnaviv/etnaviv_gem.c +1 -0
index fe665ca20c02..b68e3b235a7d 100644
@@ -515,6 +515,7 @@ void etnaviv_gem_free_object(struct drm_gem_object *obj)
 	etnaviv_obj->ops->release(etnaviv_obj);
 	drm_gem_object_release(obj);
 
+	mutex_destroy(&etnaviv_obj->lock);
 	kfree(etnaviv_obj);
 }
 
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +5 -0
index af52922ff494..d6acc4c68102 100644
@@ -1929,8 +1929,13 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
 
 static void etnaviv_gpu_platform_remove(struct platform_device *pdev)
 {
+	struct etnaviv_gpu *gpu = dev_get_drvdata(&pdev->dev);
+
 	component_del(&pdev->dev, &gpu_ops);
 	pm_runtime_disable(&pdev->dev);
+
+	mutex_destroy(&gpu->lock);
+	mutex_destroy(&gpu->sched_lock);
 }
 
 static int etnaviv_gpu_rpm_suspend(struct device *dev)
drivers/gpu/drm/etnaviv/etnaviv_mmu.c +1 -1
index e3be16165c86..ed6c42384856 100644
@@ -361,7 +361,7 @@ static void etnaviv_iommu_context_free(struct kref *kref)
 		container_of(kref, struct etnaviv_iommu_context, refcount);
 
 	etnaviv_cmdbuf_suballoc_unmap(context, &context->cmdbuf_mapping);
-
+	mutex_destroy(&context->lock);
 	context->global->ops->free(context);
 }
 void etnaviv_iommu_context_put(struct etnaviv_iommu_context *context)