Hi Sumit,
Here are 4 dma-buf patches that fix small issues.
Laurent Pinchart (4): dma-buf: Constify ops argument to dma_buf_export() dma-buf: Remove unneeded sanity checks dma-buf: Return error instead of using a goto statement when possible dma-buf: Move code out of mutex-protected section in dma_buf_attach()
drivers/base/dma-buf.c | 26 +++++++++++--------------- include/linux/dma-buf.h | 8 ++++---- 2 files changed, 15 insertions(+), 19 deletions(-)
This allows drivers to make the dma buf operations structure constant.
Signed-off-by: Laurent Pinchart laurent.pinchart@ideasonboard.com --- drivers/base/dma-buf.c | 2 +- include/linux/dma-buf.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index e38ad24..965833ac 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -71,7 +71,7 @@ static inline int is_dma_buf_file(struct file *file) * ops, or error in allocating struct dma_buf, will return negative error. * */ -struct dma_buf *dma_buf_export(void *priv, struct dma_buf_ops *ops, +struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, size_t size, int flags) { struct dma_buf *dmabuf; diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index f8ac076..86f6241 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -114,8 +114,8 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, struct device *dev); void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *dmabuf_attach); -struct dma_buf *dma_buf_export(void *priv, struct dma_buf_ops *ops, - size_t size, int flags); +struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, + size_t size, int flags); int dma_buf_fd(struct dma_buf *dmabuf); struct dma_buf *dma_buf_get(int fd); void dma_buf_put(struct dma_buf *dmabuf); @@ -138,8 +138,8 @@ static inline void dma_buf_detach(struct dma_buf *dmabuf, }
static inline struct dma_buf *dma_buf_export(void *priv, - struct dma_buf_ops *ops, - size_t size, int flags) + const struct dma_buf_ops *ops, + size_t size, int flags) { return ERR_PTR(-ENODEV); }
On Thu, Jan 26, 2012 at 12:27:22PM +0100, Laurent Pinchart wrote:
This allows drivers to make the dma buf operations structure constant.
Signed-off-by: Laurent Pinchart laurent.pinchart@ideasonboard.com
Reviewed-by: Daniel Vetter daniel.vetter@ffwll.ch
ops, ops->map_dma_buf and ops->unmap_dma_buf are guaranteed to be non-NULL by a check in dma_buf_export(). Remove NULL checks on those variables in the other API functions.
Signed-off-by: Laurent Pinchart laurent.pinchart@ideasonboard.com --- drivers/base/dma-buf.c | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 965833ac..198edd8 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -185,7 +185,7 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach; int ret;
- if (WARN_ON(!dmabuf || !dev || !dmabuf->ops)) + if (WARN_ON(!dmabuf || !dev)) return ERR_PTR(-EINVAL);
attach = kzalloc(sizeof(struct dma_buf_attachment), GFP_KERNEL); @@ -224,7 +224,7 @@ EXPORT_SYMBOL_GPL(dma_buf_attach); */ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) { - if (WARN_ON(!dmabuf || !attach || !dmabuf->ops)) + if (WARN_ON(!dmabuf || !attach)) return;
mutex_lock(&dmabuf->lock); @@ -255,12 +255,11 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
might_sleep();
- if (WARN_ON(!attach || !attach->dmabuf || !attach->dmabuf->ops)) + if (WARN_ON(!attach || !attach->dmabuf)) return ERR_PTR(-EINVAL);
mutex_lock(&attach->dmabuf->lock); - if (attach->dmabuf->ops->map_dma_buf) - sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); + sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); mutex_unlock(&attach->dmabuf->lock);
return sg_table; @@ -278,13 +277,11 @@ EXPORT_SYMBOL_GPL(dma_buf_map_attachment); void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, struct sg_table *sg_table) { - if (WARN_ON(!attach || !attach->dmabuf || !sg_table - || !attach->dmabuf->ops)) + if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) return;
mutex_lock(&attach->dmabuf->lock); - if (attach->dmabuf->ops->unmap_dma_buf) - attach->dmabuf->ops->unmap_dma_buf(attach, sg_table); + attach->dmabuf->ops->unmap_dma_buf(attach, sg_table); mutex_unlock(&attach->dmabuf->lock);
}
On Thu, Jan 26, 2012 at 12:27:23PM +0100, Laurent Pinchart wrote:
ops, ops->map_dma_buf and ops->unmap_dma_buf are guaranteed to be non-NULL by a check in dma_buf_export(). Remove NULL checks on those variables in the other API functions.
Signed-off-by: Laurent Pinchart laurent.pinchart@ideasonboard.com
Reviewed-by: Daniel Vetter daniel.vetter@ffwll.ch
Remove an error label in dma_buf_attach() that just returns an error code.
Signed-off-by: Laurent Pinchart laurent.pinchart@ideasonboard.com --- drivers/base/dma-buf.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 198edd8..97450a5 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -190,7 +190,7 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
attach = kzalloc(sizeof(struct dma_buf_attachment), GFP_KERNEL); if (attach == NULL) - goto err_alloc; + return ERR_PTR(-ENOMEM);
mutex_lock(&dmabuf->lock);
@@ -206,8 +206,6 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, mutex_unlock(&dmabuf->lock); return attach;
-err_alloc: - return ERR_PTR(-ENOMEM); err_attach: kfree(attach); mutex_unlock(&dmabuf->lock);
On Thu, Jan 26, 2012 at 12:27:24PM +0100, Laurent Pinchart wrote:
Remove an error label in dma_buf_attach() that just returns an error code.
Signed-off-by: Laurent Pinchart laurent.pinchart@ideasonboard.com
Reviewed-by: Daniel Vetter daniel.vetter@ffwll.ch
Some fields can be set without mutex protection. Initialize them before locking the mutex.
Signed-off-by: Laurent Pinchart laurent.pinchart@ideasonboard.com --- drivers/base/dma-buf.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 97450a5..8afe2dd 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -192,10 +192,11 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, if (attach == NULL) return ERR_PTR(-ENOMEM);
- mutex_lock(&dmabuf->lock); - attach->dev = dev; attach->dmabuf = dmabuf; + + mutex_lock(&dmabuf->lock); + if (dmabuf->ops->attach) { ret = dmabuf->ops->attach(dmabuf, dev, attach); if (ret)
On Thu, Jan 26, 2012 at 12:27:25PM +0100, Laurent Pinchart wrote:
Some fields can be set without mutex protection. Initialize them before locking the mutex.
Signed-off-by: Laurent Pinchart laurent.pinchart@ideasonboard.com
Reviewed-by: Daniel Vetter daniel.vetter@ffwll.ch
On Thu, 26 Jan 2012 12:27:25 +0100, Laurent Pinchart laurent.pinchart@ideasonboard.com wrote:
Some fields can be set without mutex protection. Initialize them before locking the mutex.
struct mutex lock is described as
/* mutex to serialize list manipulation and other ops */
maybe now is a good time to be a little more descriptive in what that mutex is meant to protect and sprinkle enforcement throughout the code as a means of documentation. -Chris
On Thu, Jan 26, 2012 at 12:11:57PM +0000, Chris Wilson wrote:
On Thu, 26 Jan 2012 12:27:25 +0100, Laurent Pinchart laurent.pinchart@ideasonboard.com wrote:
Some fields can be set without mutex protection. Initialize them before locking the mutex.
struct mutex lock is described as
/* mutex to serialize list manipulation and other ops */
maybe now is a good time to be a little more descriptive in what that mutex is meant to protect and sprinkle enforcement throughout the code as a means of documentation.
As, sore spot there. I think the current locking scheme is rather much still in flux. I think we need to pull out callbacks to the exporter out from the dma_buf mutex because otherwise we won't be able to avoid deadlocks.
I think we'll need to wait for 1-2 exporters to show up in upstream until we can clarify this. But it is very much on my list. -Daniel
On 26 January 2012 16:57, Laurent Pinchart laurent.pinchart@ideasonboard.com wrote:
Hi Sumit,
Hi Laurent,
Here are 4 dma-buf patches that fix small issues.
Thanks; merged to 'dev' branch on git://git.linaro.org/people/sumitsemwal/linux-3.x.git.
Laurent Pinchart (4): dma-buf: Constify ops argument to dma_buf_export() dma-buf: Remove unneeded sanity checks dma-buf: Return error instead of using a goto statement when possible dma-buf: Move code out of mutex-protected section in dma_buf_attach()
drivers/base/dma-buf.c | 26 +++++++++++--------------- include/linux/dma-buf.h | 8 ++++---- 2 files changed, 15 insertions(+), 19 deletions(-)
-- Regards,
Laurent Pinchart
Best regards, ~Sumit.
Hi Sumit,
On Friday 27 January 2012 10:49:24 Sumit Semwal wrote:
On 26 January 2012 16:57, Laurent Pinchart wrote:
Hi Sumit,
Hi Laurent,
Here are 4 dma-buf patches that fix small issues.
Thanks; merged to 'dev' branch on git://git.linaro.org/people/sumitsemwal/linux-3.x.git.
Thank you. It would be even nicer if you could push them to mainline at some point :-)
Laurent Pinchart (4): dma-buf: Constify ops argument to dma_buf_export() dma-buf: Remove unneeded sanity checks dma-buf: Return error instead of using a goto statement when possible dma-buf: Move code out of mutex-protected section in dma_buf_attach()
drivers/base/dma-buf.c | 26 +++++++++++--------------- include/linux/dma-buf.h | 8 ++++---- 2 files changed, 15 insertions(+), 19 deletions(-)
On 21 March 2012 16:50, Laurent Pinchart laurent.pinchart@ideasonboard.com wrote:
Hi Sumit,
On Friday 27 January 2012 10:49:24 Sumit Semwal wrote:
On 26 January 2012 16:57, Laurent Pinchart wrote:
Hi Sumit,
Hi Laurent,
Here are 4 dma-buf patches that fix small issues.
Thanks; merged to 'dev' branch on git://git.linaro.org/people/sumitsemwal/linux-3.x.git.
Thank you. It would be even nicer if you could push them to mainline at some point :-)
:) - Laurent, this set is already part of for-next, and will be part of my pull request to Linus.
best regards, ~Sumit. <snip>
-- Regards,
Laurent Pinchart
linaro-mm-sig@lists.linaro.org