Skip to content

Commit 0c6b522

Browse files
dma-buf: cleanup dma-resv shared fence debugging a bit v2
Make that a function instead of inline. v2: improve the kerneldoc wording as suggested by Daniel Signed-off-by: Christian König <[email protected]> Reviewed-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 068d9d7 commit 0c6b522

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

drivers/dma-buf/dma-resv.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)
208208
}
209209
EXPORT_SYMBOL(dma_resv_reserve_shared);
210210

211+
#ifdef CONFIG_DEBUG_MUTEXES
212+
/**
213+
* dma_resv_reset_shared_max - reset shared fences for debugging
214+
* @obj: the dma_resv object to reset
215+
*
216+
* Reset the number of pre-reserved shared slots to test that drivers do
217+
* correct slot allocation using dma_resv_reserve_shared(). See also
218+
* &dma_resv_list.shared_max.
219+
*/
220+
void dma_resv_reset_shared_max(struct dma_resv *obj)
221+
{
222+
/* Test shared fence slot reservation */
223+
if (rcu_access_pointer(obj->fence)) {
224+
struct dma_resv_list *fence = dma_resv_get_list(obj);
225+
226+
fence->shared_max = fence->shared_count;
227+
}
228+
}
229+
#endif
230+
211231
/**
212232
* dma_resv_add_shared_fence - Add a fence to a shared slot
213233
* @obj: the reservation object

include/linux/dma-resv.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ static inline struct dma_resv_list *dma_resv_get_list(struct dma_resv *obj)
9292
dma_resv_held(obj));
9393
}
9494

95+
#ifdef CONFIG_DEBUG_MUTEXES
96+
void dma_resv_reset_shared_max(struct dma_resv *obj);
97+
#else
98+
static inline void dma_resv_reset_shared_max(struct dma_resv *obj) {}
99+
#endif
100+
95101
/**
96102
* dma_resv_lock - lock the reservation object
97103
* @obj: the reservation object
@@ -215,14 +221,7 @@ static inline struct ww_acquire_ctx *dma_resv_locking_ctx(struct dma_resv *obj)
215221
*/
216222
static inline void dma_resv_unlock(struct dma_resv *obj)
217223
{
218-
#ifdef CONFIG_DEBUG_MUTEXES
219-
/* Test shared fence slot reservation */
220-
if (rcu_access_pointer(obj->fence)) {
221-
struct dma_resv_list *fence = dma_resv_get_list(obj);
222-
223-
fence->shared_max = fence->shared_count;
224-
}
225-
#endif
224+
dma_resv_reset_shared_max(obj);
226225
ww_mutex_unlock(&obj->lock);
227226
}
228227

0 commit comments

Comments
 (0)