clear-pkgs-linux-iot-lts2018/1113-dma-buf-hyper_dmabuf-c...

84 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dongwon Kim <dongwon.kim@intel.com>
Date: Mon, 17 Jun 2019 22:58:49 -0700
Subject: [PATCH] dma-buf/hyper_dmabuf: check if 'imported' still exist in
ops_release
To prevent double-release, it checks if passed "imported" still exist
(making sure it is not yet relesed).
Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
---
drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_list.c | 14 ++++++++++++++
drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_list.h | 2 ++
drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_ops.c | 8 ++++++++
3 files changed, 24 insertions(+)
diff --git a/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_list.c b/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_list.c
index 7b6ce1f067a2..85e07789a58a 100644
--- a/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_list.c
+++ b/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_list.c
@@ -212,6 +212,20 @@ hyper_dmabuf_id_t hyper_dmabuf_find_hid_exported(struct dma_buf *dmabuf,
return hid;
}
+/* search for pre-imported sgt and return id of it if it exist */
+hyper_dmabuf_id_t hyper_dmabuf_find_hid_imported(struct imported_sgt_info *imported)
+{
+ struct list_entry_imported *info_entry;
+ hyper_dmabuf_id_t hid = {-1, {0, 0, 0} };
+ int bkt;
+
+ hash_for_each(hyper_dmabuf_hash_imported, bkt, info_entry, node)
+ if (info_entry->imported == imported)
+ return info_entry->imported->hid;
+
+ return hid;
+}
+
struct imported_sgt_info *hyper_dmabuf_find_imported(hyper_dmabuf_id_t hid)
{
struct list_entry_imported *info_entry;
diff --git a/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_list.h b/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_list.h
index 81250e5c5eab..715bfc1f3ec7 100644
--- a/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_list.h
+++ b/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_list.h
@@ -52,6 +52,8 @@ int hyper_dmabuf_register_exported(struct exported_sgt_info *info);
hyper_dmabuf_id_t hyper_dmabuf_find_hid_exported(struct dma_buf *dmabuf,
int domid);
+hyper_dmabuf_id_t hyper_dmabuf_find_hid_imported(struct imported_sgt_info *imported);
+
int hyper_dmabuf_register_imported(struct imported_sgt_info *info);
struct exported_sgt_info *hyper_dmabuf_find_exported(hyper_dmabuf_id_t hid);
diff --git a/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_ops.c b/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_ops.c
index 8426fbeefd76..8c3a830947e9 100644
--- a/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_ops.c
+++ b/drivers/dma-buf/hyper_dmabuf/hyper_dmabuf_ops.c
@@ -200,6 +200,7 @@ static void hyper_dmabuf_ops_release(struct dma_buf *dma_buf)
{
struct imported_sgt_info *imported;
struct hyper_dmabuf_bknd_ops *bknd_ops = hy_drv_priv->bknd_ops;
+ hyper_dmabuf_id_t hid;
int finish;
if (!dma_buf->priv)
@@ -209,6 +210,13 @@ static void hyper_dmabuf_ops_release(struct dma_buf *dma_buf)
imported = (struct imported_sgt_info *)dma_buf->priv;
+ /* check if imported still exists */
+ hid = hyper_dmabuf_find_hid_imported(imported);
+ if (hid.id == -1) {
+ mutex_unlock(&hy_drv_priv->lock);
+ return;
+ }
+
dev_dbg(hy_drv_priv->dev, "%s: {%x,%x} dmabuf:%p ref_c:%d\n", __func__,
imported->hid.id, imported->hid.rng_key[0],
imported->dma_buf, imported->importers);
--
https://clearlinux.org