[PATCH v2] drivers:staging:android:ashmem: Changing return type from int to loff_t

2018-03-15 Thread Rohit Kumar
Changing return type from int to loff_t. Actual return type of the
function (vfs_llseek) is loff_t (long long). Here due to implicit
converion from long long to int, result will be implementation defined.

Signed-off-by: Rohit Kumar <rohit12tec...@gmail.com>
---
 drivers/staging/android/ashmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 86580b6..a1a0025 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -321,7 +321,7 @@ static ssize_t ashmem_read_iter(struct kiocb *iocb, struct 
iov_iter *iter)
 static loff_t ashmem_llseek(struct file *file, loff_t offset, int origin)
 {
struct ashmem_area *asma = file->private_data;
-   int ret;
+   loff_t ret;
 
mutex_lock(_mutex);
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[no subject]

2018-03-15 Thread Rohit Kumar
de...@driverdev.osuosl.org
Bcc: 
Subject: [PATCH v2] drivers:staging:android:ashmem: Changing return type from
 int to loff_t
Reply-To: 

Changing return type from int to loff_t. Actual return type of the
function (vfs_llseek) is loff_t (long long). Here due to implicit
converion from long long to int, result will be implementation defined.

Signed-off-by: Rohit Kumar <rohit12tec...@gmail.com>
---
 drivers/staging/android/ashmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 86580b6..a1a0025 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -321,7 +321,7 @@ static ssize_t ashmem_read_iter(struct kiocb *iocb, struct 
iov_iter *iter)
 static loff_t ashmem_llseek(struct file *file, loff_t offset, int origin)
 {
struct ashmem_area *asma = file->private_data;
-   int ret;
+   loff_t ret;
 
mutex_lock(_mutex);
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv3 1/1] staging/ion: Add support to get ion handle from dma buf

2016-01-11 Thread Rohit kumar
Currently we can only import dma buf fd's to get ion_handle.
Adding support to import dma buf handles to support kernel
specific use cases.

An example use case is in linux platforms such as Tizen, in which
DRM-GEM is used for buffer management for graphics. It has gem_handle
corresponding to a buffer and uses gem_name for sharing the buffer
with other processes. However,it also uses dma_buf fd for 3d operations.
For wayland, there are multiple calls for gem_handle to dma_buf fd
conversion. So, we store dma_buf associated with buffer. But, there is
no api for getting ion_handle from dma_buf. This patch exposes api to
retrieve the ion handle from dma_buf for similar use cases. With this
patch, we can integrate ION within DRM-GEM for buffer management and
dma_buf sharing.

Signed-off-by: Rohit kumar <rohit...@samsung.com>
---
v2: Updated commit message with use case explanation, as suggested by
Laura Abbott<labb...@redhat.com>
v3: Fixed dmabuf refcount issue in ion_import_dma_buf. dma_buf_put()
was being called without dma_buf_get(), so moving it to
ion_import_dma_buf_fd().

 drivers/staging/android/ion/ion.c |   26 ++
 drivers/staging/android/ion/ion.h |   20 
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index e237e9f..7e86e18 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -1151,22 +1151,18 @@ int ion_share_dma_buf_fd(struct ion_client *client, 
struct ion_handle *handle)
 }
 EXPORT_SYMBOL(ion_share_dma_buf_fd);
 
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+ struct dma_buf *dmabuf)
 {
-   struct dma_buf *dmabuf;
struct ion_buffer *buffer;
struct ion_handle *handle;
int ret;
 
-   dmabuf = dma_buf_get(fd);
-   if (IS_ERR(dmabuf))
-   return ERR_CAST(dmabuf);
/* if this memory came from ion */
 
if (dmabuf->ops != _buf_ops) {
pr_err("%s: can not import dmabuf from another exporter\n",
   __func__);
-   dma_buf_put(dmabuf);
return ERR_PTR(-EINVAL);
}
buffer = dmabuf->priv;
@@ -1194,11 +1190,25 @@ struct ion_handle *ion_import_dma_buf(struct ion_client 
*client, int fd)
}
 
 end:
-   dma_buf_put(dmabuf);
return handle;
 }
 EXPORT_SYMBOL(ion_import_dma_buf);
 
+struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd)
+{
+   struct dma_buf *dmabuf;
+   struct ion_handle *handle;
+
+   dmabuf = dma_buf_get(fd);
+   if (IS_ERR(dmabuf))
+   return ERR_CAST(dmabuf);
+
+   handle = ion_import_dma_buf(client, dmabuf);
+   dma_buf_put(dmabuf);
+   return handle;
+}
+EXPORT_SYMBOL(ion_import_dma_buf_fd);
+
 static int ion_sync_for_device(struct ion_client *client, int fd)
 {
struct dma_buf *dmabuf;
@@ -1306,7 +1316,7 @@ static long ion_ioctl(struct file *filp, unsigned int 
cmd, unsigned long arg)
{
struct ion_handle *handle;
 
-   handle = ion_import_dma_buf(client, data.fd.fd);
+   handle = ion_import_dma_buf_fd(client, data.fd.fd);
if (IS_ERR(handle))
ret = PTR_ERR(handle);
else
diff --git a/drivers/staging/android/ion/ion.h 
b/drivers/staging/android/ion/ion.h
index b860c5f..a1331fc 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -192,14 +192,26 @@ struct dma_buf *ion_share_dma_buf(struct ion_client 
*client,
 int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
 
 /**
- * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
+ * ion_import_dma_buf() - get ion_handle from dma-buf
+ * @client:the client
+ * @dmabuf:the dma-buf
+ *
+ * Get the ion_buffer associated with the dma-buf and return the ion_handle.
+ * If no ion_handle exists for this buffer, return newly created ion_handle.
+ * If dma-buf from another exporter is passed, return ERR_PTR(-EINVAL)
+ */
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+ struct dma_buf *dmabuf);
+
+/**
+ * ion_import_dma_buf_fd() - given a dma-buf fd from the ion exporter get 
handle
  * @client:the client
  * @fd:the dma-buf fd
  *
- * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf,
- * import that fd and return a handle representing it.  If a dma-buf from
+ * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf_fd,
+ * import that fd and return a handle representing it. If a dma-buf from
  * another exporter is passed in this function will return ERR_PTR(-EINVAL)
  */
-struct ion_handl

[PATCHv2 1/1] staging/ion: Add support to get ion handle from dma buf

2016-01-05 Thread Rohit kumar
Currently we can only import dma buf fd's to get ion_handle.
Adding support to import dma buf handles to support kernel
specific use cases.

An example use case is in linux platforms such as Tizen, in which
DRM-GEM is used for buffer management for graphics. It has gem_handle
corresponding to a buffer and uses gem_name for sharing the buffer
with other processes. However,it also uses dma_buf fd for 3d operations.
For wayland, there are multiple calls for gem_handle to dma_buf fd
conversion. So, we store dma_buf associated with buffer. But, there is
no api for getting ion_handle from dma_buf. This patch exposes api to
retrieve the ion handle from dma_buf for similar use cases. With this
patch, we can integrate ION within DRM-GEM for buffer management and
dma_buf sharing.

Signed-off-by: Rohit kumar <rohit...@samsung.com>
---
v2: Updated commit message with use case explanation, as suggested by
Laura Abbott<labb...@redhat.com>

 drivers/staging/android/ion/ion.c |   21 +++--
 drivers/staging/android/ion/ion.h |   20 
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index e237e9f..5509716 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -1151,16 +1151,13 @@ int ion_share_dma_buf_fd(struct ion_client *client, 
struct ion_handle *handle)
 }
 EXPORT_SYMBOL(ion_share_dma_buf_fd);
 
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+ struct dma_buf *dmabuf)
 {
-   struct dma_buf *dmabuf;
struct ion_buffer *buffer;
struct ion_handle *handle;
int ret;
 
-   dmabuf = dma_buf_get(fd);
-   if (IS_ERR(dmabuf))
-   return ERR_CAST(dmabuf);
/* if this memory came from ion */
 
if (dmabuf->ops != _buf_ops) {
@@ -1199,6 +1196,18 @@ end:
 }
 EXPORT_SYMBOL(ion_import_dma_buf);
 
+struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd)
+{
+   struct dma_buf *dmabuf;
+
+   dmabuf = dma_buf_get(fd);
+   if (IS_ERR(dmabuf))
+   return ERR_CAST(dmabuf);
+
+   return ion_import_dma_buf(client, dmabuf);
+}
+EXPORT_SYMBOL(ion_import_dma_buf_fd);
+
 static int ion_sync_for_device(struct ion_client *client, int fd)
 {
struct dma_buf *dmabuf;
@@ -1306,7 +1315,7 @@ static long ion_ioctl(struct file *filp, unsigned int 
cmd, unsigned long arg)
{
struct ion_handle *handle;
 
-   handle = ion_import_dma_buf(client, data.fd.fd);
+   handle = ion_import_dma_buf_fd(client, data.fd.fd);
if (IS_ERR(handle))
ret = PTR_ERR(handle);
else
diff --git a/drivers/staging/android/ion/ion.h 
b/drivers/staging/android/ion/ion.h
index b860c5f..a1331fc 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -192,14 +192,26 @@ struct dma_buf *ion_share_dma_buf(struct ion_client 
*client,
 int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
 
 /**
- * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
+ * ion_import_dma_buf() - get ion_handle from dma-buf
+ * @client:the client
+ * @dmabuf:the dma-buf
+ *
+ * Get the ion_buffer associated with the dma-buf and return the ion_handle.
+ * If no ion_handle exists for this buffer, return newly created ion_handle.
+ * If dma-buf from another exporter is passed, return ERR_PTR(-EINVAL)
+ */
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+ struct dma_buf *dmabuf);
+
+/**
+ * ion_import_dma_buf_fd() - given a dma-buf fd from the ion exporter get 
handle
  * @client:the client
  * @fd:the dma-buf fd
  *
- * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf,
- * import that fd and return a handle representing it.  If a dma-buf from
+ * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf_fd,
+ * import that fd and return a handle representing it. If a dma-buf from
  * another exporter is passed in this function will return ERR_PTR(-EINVAL)
  */
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);
+struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd);
 
 #endif /* _LINUX_ION_H */
-- 
1.7.9.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging/ion: Add support to get ion handle from dma buf

2016-01-05 Thread Rohit kumar
Currently we can only import dma buf fd's to get ion_handle.
Adding support to import dma buf handles to support kernel
specific use cases.

Signed-off-by: Rohit kumar <rohit...@samsung.com>
---
Currently, ION is the memory manager for graphics in android. However,
in other linux platforms such as Tizen, DRM-GEM is used for buffer 
management for graphics. It has gem_handle corresponding to a buffer
and uses gem_name for sharing the buffer with other processes. However,
it also uses dma_buf fd for 3d operations. For wayland, there are
multiple calls for gem_handle to dma_buf fd conversion. So, we store
dma_buf associated with buffer. But, there is no api for getting
ion_handle from dma_buf. This patch exposes api to retrieve the ion
handle from dma_buf for similar use cases. With this patch, we can
integrate ION within DRM-GEM for buffer management and dma_buf sharing.

 drivers/staging/android/ion/ion.c |   21 +++--
 drivers/staging/android/ion/ion.h |   20 
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index e237e9f..5509716 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -1151,16 +1151,13 @@ int ion_share_dma_buf_fd(struct ion_client *client, 
struct ion_handle *handle)
 }
 EXPORT_SYMBOL(ion_share_dma_buf_fd);
 
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+ struct dma_buf *dmabuf)
 {
-   struct dma_buf *dmabuf;
struct ion_buffer *buffer;
struct ion_handle *handle;
int ret;
 
-   dmabuf = dma_buf_get(fd);
-   if (IS_ERR(dmabuf))
-   return ERR_CAST(dmabuf);
/* if this memory came from ion */
 
if (dmabuf->ops != _buf_ops) {
@@ -1199,6 +1196,18 @@ end:
 }
 EXPORT_SYMBOL(ion_import_dma_buf);
 
+struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd)
+{
+   struct dma_buf *dmabuf;
+
+   dmabuf = dma_buf_get(fd);
+   if (IS_ERR(dmabuf))
+   return ERR_CAST(dmabuf);
+
+   return ion_import_dma_buf(client, dmabuf);
+}
+EXPORT_SYMBOL(ion_import_dma_buf_fd);
+
 static int ion_sync_for_device(struct ion_client *client, int fd)
 {
struct dma_buf *dmabuf;
@@ -1306,7 +1315,7 @@ static long ion_ioctl(struct file *filp, unsigned int 
cmd, unsigned long arg)
{
struct ion_handle *handle;
 
-   handle = ion_import_dma_buf(client, data.fd.fd);
+   handle = ion_import_dma_buf_fd(client, data.fd.fd);
if (IS_ERR(handle))
ret = PTR_ERR(handle);
else
diff --git a/drivers/staging/android/ion/ion.h 
b/drivers/staging/android/ion/ion.h
index b860c5f..a1331fc 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -192,14 +192,26 @@ struct dma_buf *ion_share_dma_buf(struct ion_client 
*client,
 int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
 
 /**
- * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
+ * ion_import_dma_buf() - get ion_handle from dma-buf
+ * @client:the client
+ * @dmabuf:the dma-buf
+ *
+ * Get the ion_buffer associated with the dma-buf and return the ion_handle.
+ * If no ion_handle exists for this buffer, return newly created ion_handle.
+ * If dma-buf from another exporter is passed, return ERR_PTR(-EINVAL)
+ */
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+ struct dma_buf *dmabuf);
+
+/**
+ * ion_import_dma_buf_fd() - given a dma-buf fd from the ion exporter get 
handle
  * @client:the client
  * @fd:the dma-buf fd
  *
- * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf,
- * import that fd and return a handle representing it.  If a dma-buf from
+ * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf_fd,
+ * import that fd and return a handle representing it. If a dma-buf from
  * another exporter is passed in this function will return ERR_PTR(-EINVAL)
  */
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);
+struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd);
 
 #endif /* _LINUX_ION_H */
-- 
1.7.9.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/1] staging: ion: Fix error handling in ion_buffer_create

2015-09-29 Thread Rohit kumar
This patch fixes error handling case when buffer->pages allocation
fails. Also, it removes unreachable code of checking ret variable
although it is not updated.

Signed-off-by: Rohit kumar <rohit...@samsung.com>
---
 drivers/staging/android/ion/ion.c |   14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index 217aa53..af59e4a 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -213,10 +213,10 @@ static struct ion_buffer *ion_buffer_create(struct 
ion_heap *heap,
"heap->ops->map_dma should return ERR_PTR on error"))
table = ERR_PTR(-EINVAL);
if (IS_ERR(table)) {
-   heap->ops->free(buffer);
-   kfree(buffer);
-   return ERR_CAST(table);
+   ret = -EINVAL;
+   goto err1;
}
+
buffer->sg_table = table;
if (ion_buffer_fault_user_mappings(buffer)) {
int num_pages = PAGE_ALIGN(buffer->size) / PAGE_SIZE;
@@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap 
*heap,
buffer->pages = vmalloc(sizeof(struct page *) * num_pages);
if (!buffer->pages) {
ret = -ENOMEM;
-   goto err1;
+   goto err;
}
 
for_each_sg(table->sgl, sg, table->nents, i) {
@@ -235,9 +235,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap 
*heap,
for (j = 0; j < sg->length / PAGE_SIZE; j++)
buffer->pages[k++] = page++;
}
-
-   if (ret)
-   goto err;
}
 
buffer->dev = dev;
@@ -261,9 +258,8 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap 
*heap,
 
 err:
heap->ops->unmap_dma(heap, buffer);
-   heap->ops->free(buffer);
 err1:
-   vfree(buffer->pages);
+   heap->ops->free(buffer);
 err2:
kfree(buffer);
return ERR_PTR(ret);
-- 
1.7.9.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel