dma-buf: include exp_name to anon file name
authorCho KyongHo <pullip.cho@samsung.com>
Tue, 3 Apr 2018 11:33:37 +0000 (20:33 +0900)
committerhskang <hs1218.kang@samsung.com>
Wed, 29 Aug 2018 07:34:05 +0000 (16:34 +0900)
exp_name is introduced for debugging purpose. And we often list the
open file descriptors under /proc/<pid>/fd to find the list of anon
files of dma-buf optained by the process of <pid>. However it is not
possible to associate a specific open file descriptor listed in
/proc/<pid>/fd with the buffer list scrapped from
debugfs/dma-buf/bufinfo.

Attaching exp_name to the anon file name of dma-buf helps identifying
the exported module of the the buffers listed in /proc/<pid>/fd.

dma_buf.exp_name also has the copy of the string instead of pointing
where the string given by the exporter. This gives the exporter chances
to set different exp_name to the different buffers. Therefore we can
identify exact buffers from /proc/<pid>/fd and find the properties of
the buffers. The properties are defined by the exporter and never
exported elsewhere.

Change-Id: Ia3222d1c90b40739cf2e19805a11f366a3b73089
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
drivers/dma-buf/dma-buf.c

index 074fae795c190ac1218d00633f1633202683cf07..bd45a2e91facca631a3a2ea698b62669a8d3f442 100644 (file)
@@ -79,6 +79,7 @@ static int dma_buf_release(struct inode *inode, struct file *file)
                reservation_object_fini(dmabuf->resv);
 
        module_put(dmabuf->owner);
+       kfree(dmabuf->exp_name);
        kfree(dmabuf);
        return 0;
 }
@@ -349,6 +350,8 @@ static inline int is_dma_buf_file(struct file *file)
        return file->f_op == &dma_buf_fops;
 }
 
+#define MAX_EXP_FILE_NAME (DNAME_INLINE_LEN - 7) /* 7: strlen("dmabuf_") */
+
 /**
  * DOC: dma buf device access
  *
@@ -403,6 +406,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
        struct reservation_object *resv = exp_info->resv;
        struct file *file;
        size_t alloc_size = sizeof(struct dma_buf);
+       char filename[MAX_EXP_FILE_NAME];
        int ret;
 
        if (!exp_info->resv)
@@ -431,10 +435,17 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
                goto err_module;
        }
 
+       dmabuf->exp_name = kstrdup(exp_info->exp_name, GFP_KERNEL);
+       if (!dmabuf->exp_name) {
+               ret = -ENOMEM;
+               goto err_expname;
+       }
+
+       snprintf(filename, MAX_EXP_FILE_NAME, "dmabuf_%s", dmabuf->exp_name);
+
        dmabuf->priv = exp_info->priv;
        dmabuf->ops = exp_info->ops;
        dmabuf->size = exp_info->size;
-       dmabuf->exp_name = exp_info->exp_name;
        dmabuf->owner = exp_info->owner;
        init_waitqueue_head(&dmabuf->poll);
        dmabuf->cb_excl.poll = dmabuf->cb_shared.poll = &dmabuf->poll;
@@ -446,7 +457,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
        }
        dmabuf->resv = resv;
 
-       file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf,
+       file = anon_inode_getfile(filename, &dma_buf_fops, dmabuf,
                                        exp_info->flags);
        if (IS_ERR(file)) {
                ret = PTR_ERR(file);
@@ -466,6 +477,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
        return dmabuf;
 
 err_dmabuf:
+       kfree(dmabuf->exp_name);
+err_expname:
        kfree(dmabuf);
 err_module:
        module_put(exp_info->owner);