@@ -67,12 +67,9 @@ static void dma_buf_release(struct dentry *dentry)
67
67
BUG_ON (dmabuf -> vmapping_counter );
68
68
69
69
/*
70
- * Any fences that a dma-buf poll can wait on should be signaled
71
- * before releasing dma-buf. This is the responsibility of each
72
- * driver that uses the reservation objects.
73
- *
74
- * If you hit this BUG() it means someone dropped their ref to the
75
- * dma-buf while still having pending operation to the buffer.
70
+ * If you hit this BUG() it could mean:
71
+ * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else
72
+ * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
76
73
*/
77
74
BUG_ON (dmabuf -> cb_in .active || dmabuf -> cb_out .active );
78
75
@@ -200,13 +197,16 @@ static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence)
200
197
static void dma_buf_poll_cb (struct dma_fence * fence , struct dma_fence_cb * cb )
201
198
{
202
199
struct dma_buf_poll_cb_t * dcb = (struct dma_buf_poll_cb_t * )cb ;
200
+ struct dma_buf * dmabuf = container_of (dcb -> poll , struct dma_buf , poll );
203
201
unsigned long flags ;
204
202
205
203
spin_lock_irqsave (& dcb -> poll -> lock , flags );
206
204
wake_up_locked_poll (dcb -> poll , dcb -> active );
207
205
dcb -> active = 0 ;
208
206
spin_unlock_irqrestore (& dcb -> poll -> lock , flags );
209
207
dma_fence_put (fence );
208
+ /* Paired with get_file in dma_buf_poll */
209
+ fput (dmabuf -> file );
210
210
}
211
211
212
212
static bool dma_buf_poll_add_cb (struct dma_resv * resv , bool write ,
@@ -259,6 +259,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
259
259
spin_unlock_irq (& dmabuf -> poll .lock );
260
260
261
261
if (events & EPOLLOUT ) {
262
+ /* Paired with fput in dma_buf_poll_cb */
263
+ get_file (dmabuf -> file );
264
+
262
265
if (!dma_buf_poll_add_cb (resv , true, dcb ))
263
266
/* No callback queued, wake up any other waiters */
264
267
dma_buf_poll_cb (NULL , & dcb -> cb );
@@ -279,6 +282,9 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
279
282
spin_unlock_irq (& dmabuf -> poll .lock );
280
283
281
284
if (events & EPOLLIN ) {
285
+ /* Paired with fput in dma_buf_poll_cb */
286
+ get_file (dmabuf -> file );
287
+
282
288
if (!dma_buf_poll_add_cb (resv , false, dcb ))
283
289
/* No callback queued, wake up any other waiters */
284
290
dma_buf_poll_cb (NULL , & dcb -> cb );
0 commit comments