From: Zijie Zhao <[email protected]>

drm_gem_dma_get_unmapped_area() reads dma_obj->vaddr after
drm_gem_object_put(), which may have dropped the last reference and
freed the object. Read it before the put.

Found by a static analysis tool.

Fixes: 62a0d98a188c ("drm: allow to use mmuless SoC")
Signed-off-by: Zijie Zhao <[email protected]>
---
The fix and the changelog were drafted with AI assistance (Claude Code,
with a second review by OpenAI Codex), then reviewed by the submitter.

Testing:
- Compile-tested on x86_64 (allmodconfig, W=1):
  drivers/gpu/drm/drm_gem_dma_helper.o; no new warnings.
- checkpatch.pl --strict: no errors or warnings.
---
 drivers/gpu/drm/drm_gem_dma_helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_gem_dma_helper.c 
b/drivers/gpu/drm/drm_gem_dma_helper.c
index 7d9612075d31..8c305f7ad969 100644
--- a/drivers/gpu/drm/drm_gem_dma_helper.c
+++ b/drivers/gpu/drm/drm_gem_dma_helper.c
@@ -355,6 +355,7 @@ unsigned long drm_gem_dma_get_unmapped_area(struct file 
*filp,
        struct drm_file *priv = filp->private_data;
        struct drm_device *dev = priv->minor->dev;
        struct drm_vma_offset_node *node;
+       unsigned long ret;
 
        if (drm_dev_is_unplugged(dev))
                return -ENODEV;
@@ -390,10 +391,11 @@ unsigned long drm_gem_dma_get_unmapped_area(struct file 
*filp,
        }
 
        dma_obj = to_drm_gem_dma_obj(obj);
+       ret = dma_obj->vaddr ? (unsigned long)dma_obj->vaddr : -EINVAL;
 
        drm_gem_object_put(obj);
 
-       return dma_obj->vaddr ? (unsigned long)dma_obj->vaddr : -EINVAL;
+       return ret;
 }
 EXPORT_SYMBOL_GPL(drm_gem_dma_get_unmapped_area);
 #endif

---
base-commit: 4d6d0a4639a335df10598e6a4373299bc3f167c0
change-id: 20261202-kbug-l955-5e3659d1c551

Best regards,
--  
Zijie Zhao <[email protected]>


Reply via email to