Commit 8d0d16a3 authored by Pranjal Ramajor Asha Kanojiya's avatar Pranjal Ramajor Asha Kanojiya Committed by Jeffrey Hugo

accel/qaic: Call DRM helper function to destroy prime GEM

smatch warning:
	drivers/accel/qaic/qaic_data.c:620 qaic_free_object() error:
		dereferencing freed memory 'obj->import_attach'

obj->import_attach is detached and freed using dma_buf_detach().
But used after free to decrease the dmabuf ref count using
dma_buf_put().

drm_prime_gem_destroy() handles this issue and performs the proper clean
up instead of open coding it in the driver.

Fixes: ff13be83 ("accel/qaic: Add datapath")
Reported-by: default avatarSukrut Bellary <sukrut.bellary@linux.com>
Closes: https://lore.kernel.org/all/20230610021200.377452-1-sukrut.bellary@linux.com/Suggested-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarPranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
Reviewed-by: default avatarCarl Vanderlip <quic_carlv@quicinc.com>
Reviewed-by: default avatarJeffrey Hugo <quic_jhugo@quicinc.com>
Signed-off-by: default avatarJeffrey Hugo <quic_jhugo@quicinc.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230614161528.11710-1-quic_jhugo@quicinc.com
parent 45a3e24f
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/wait.h> #include <linux/wait.h>
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/drm_gem.h> #include <drm/drm_gem.h>
#include <drm/drm_prime.h>
#include <drm/drm_print.h> #include <drm/drm_print.h>
#include <uapi/drm/qaic_accel.h> #include <uapi/drm/qaic_accel.h>
...@@ -616,8 +617,7 @@ static void qaic_free_object(struct drm_gem_object *obj) ...@@ -616,8 +617,7 @@ static void qaic_free_object(struct drm_gem_object *obj)
if (obj->import_attach) { if (obj->import_attach) {
/* DMABUF/PRIME Path */ /* DMABUF/PRIME Path */
dma_buf_detach(obj->import_attach->dmabuf, obj->import_attach); drm_prime_gem_destroy(obj, NULL);
dma_buf_put(obj->import_attach->dmabuf);
} else { } else {
/* Private buffer allocation path */ /* Private buffer allocation path */
qaic_free_sgt(bo->sgt); qaic_free_sgt(bo->sgt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment