diff mbox series

[2/2] dma-buf: clarify dma_fence_add_callback documentation

Message ID 20210901120240.7339-3-christian.koenig@amd.com
State New
Headers show
Series [1/2] dma-buf: clarify dma_fence_ops->wait documentation | expand

Commit Message

Christian König Sept. 1, 2021, 12:02 p.m. UTC
That the caller doesn't need to keep a reference is rather
risky and not defensive at all.

Especially dma_buf_poll got that horrible wrong, so better
remove that sentence and also clarify that the callback
might be called in atomic or interrupt context.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/dma-buf/dma-fence.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Daniel Vetter Sept. 2, 2021, 2:42 p.m. UTC | #1
On Wed, Sep 01, 2021 at 02:02:40PM +0200, Christian König wrote:
> That the caller doesn't need to keep a reference is rather

> risky and not defensive at all.

> 

> Especially dma_buf_poll got that horrible wrong, so better

> remove that sentence and also clarify that the callback

> might be called in atomic or interrupt context.

> 

> Signed-off-by: Christian König <christian.koenig@amd.com>


Still on the fence between documenting the precise rules and documenting
the safe rules, but this is tricky enough that you got me convinced. Plus
shorter, simpler, clearer kerneldoc has much better chances of being read,
understood and followed.

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>


> ---

>  drivers/dma-buf/dma-fence.c | 13 +++++--------

>  1 file changed, 5 insertions(+), 8 deletions(-)

> 

> diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c

> index ce0f5eff575d..1e82ecd443fa 100644

> --- a/drivers/dma-buf/dma-fence.c

> +++ b/drivers/dma-buf/dma-fence.c

> @@ -616,20 +616,17 @@ EXPORT_SYMBOL(dma_fence_enable_sw_signaling);

>   * @cb: the callback to register

>   * @func: the function to call

>   *

> + * Add a software callback to the fence. The caller should keep a reference to

> + * the fence.

> + *

>   * @cb will be initialized by dma_fence_add_callback(), no initialization

>   * by the caller is required. Any number of callbacks can be registered

>   * to a fence, but a callback can only be registered to one fence at a time.

>   *

> - * Note that the callback can be called from an atomic context.  If

> - * fence is already signaled, this function will return -ENOENT (and

> + * If fence is already signaled, this function will return -ENOENT (and

>   * *not* call the callback).

>   *

> - * Add a software callback to the fence. Same restrictions apply to

> - * refcount as it does to dma_fence_wait(), however the caller doesn't need to

> - * keep a refcount to fence afterward dma_fence_add_callback() has returned:

> - * when software access is enabled, the creator of the fence is required to keep

> - * the fence alive until after it signals with dma_fence_signal(). The callback

> - * itself can be called from irq context.

> + * Note that the callback can be called from an atomic context or irq context.

>   *

>   * Returns 0 in case of success, -ENOENT if the fence is already signaled

>   * and -EINVAL in case of error.

> -- 

> 2.25.1

> 


-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Christian König Sept. 3, 2021, 8:22 a.m. UTC | #2
Am 02.09.21 um 16:42 schrieb Daniel Vetter:
> On Wed, Sep 01, 2021 at 02:02:40PM +0200, Christian König wrote:

>> That the caller doesn't need to keep a reference is rather

>> risky and not defensive at all.

>>

>> Especially dma_buf_poll got that horrible wrong, so better

>> remove that sentence and also clarify that the callback

>> might be called in atomic or interrupt context.

>>

>> Signed-off-by: Christian König <christian.koenig@amd.com>

> Still on the fence between documenting the precise rules and documenting

> the safe rules, but this is tricky enough that you got me convinced. Plus

> shorter, simpler, clearer kerneldoc has much better chances of being read,

> understood and followed.


I think that for documentation we should apply the same rules we have 
for code.

E.g. keep it simple until you absolutely have to make it complex and 
keep it defensive with the least probability for something to go wrong.

> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>


Thanks,
Christian.

>

>> ---

>>   drivers/dma-buf/dma-fence.c | 13 +++++--------

>>   1 file changed, 5 insertions(+), 8 deletions(-)

>>

>> diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c

>> index ce0f5eff575d..1e82ecd443fa 100644

>> --- a/drivers/dma-buf/dma-fence.c

>> +++ b/drivers/dma-buf/dma-fence.c

>> @@ -616,20 +616,17 @@ EXPORT_SYMBOL(dma_fence_enable_sw_signaling);

>>    * @cb: the callback to register

>>    * @func: the function to call

>>    *

>> + * Add a software callback to the fence. The caller should keep a reference to

>> + * the fence.

>> + *

>>    * @cb will be initialized by dma_fence_add_callback(), no initialization

>>    * by the caller is required. Any number of callbacks can be registered

>>    * to a fence, but a callback can only be registered to one fence at a time.

>>    *

>> - * Note that the callback can be called from an atomic context.  If

>> - * fence is already signaled, this function will return -ENOENT (and

>> + * If fence is already signaled, this function will return -ENOENT (and

>>    * *not* call the callback).

>>    *

>> - * Add a software callback to the fence. Same restrictions apply to

>> - * refcount as it does to dma_fence_wait(), however the caller doesn't need to

>> - * keep a refcount to fence afterward dma_fence_add_callback() has returned:

>> - * when software access is enabled, the creator of the fence is required to keep

>> - * the fence alive until after it signals with dma_fence_signal(). The callback

>> - * itself can be called from irq context.

>> + * Note that the callback can be called from an atomic context or irq context.

>>    *

>>    * Returns 0 in case of success, -ENOENT if the fence is already signaled

>>    * and -EINVAL in case of error.

>> -- 

>> 2.25.1

>>
diff mbox series

Patch

diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index ce0f5eff575d..1e82ecd443fa 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -616,20 +616,17 @@  EXPORT_SYMBOL(dma_fence_enable_sw_signaling);
  * @cb: the callback to register
  * @func: the function to call
  *
+ * Add a software callback to the fence. The caller should keep a reference to
+ * the fence.
+ *
  * @cb will be initialized by dma_fence_add_callback(), no initialization
  * by the caller is required. Any number of callbacks can be registered
  * to a fence, but a callback can only be registered to one fence at a time.
  *
- * Note that the callback can be called from an atomic context.  If
- * fence is already signaled, this function will return -ENOENT (and
+ * If fence is already signaled, this function will return -ENOENT (and
  * *not* call the callback).
  *
- * Add a software callback to the fence. Same restrictions apply to
- * refcount as it does to dma_fence_wait(), however the caller doesn't need to
- * keep a refcount to fence afterward dma_fence_add_callback() has returned:
- * when software access is enabled, the creator of the fence is required to keep
- * the fence alive until after it signals with dma_fence_signal(). The callback
- * itself can be called from irq context.
+ * Note that the callback can be called from an atomic context or irq context.
  *
  * Returns 0 in case of success, -ENOENT if the fence is already signaled
  * and -EINVAL in case of error.