Skip to content

Commit 6ab9539

Browse files
jc-kynesimpelwell
authored andcommitted
media: rpivid: Ensure IRQs have completed before uniniting context
Before uniniting the decode context sync with the IRQ queues to ensure that decode no longer has any buffers in use. This fixes a problem that manifested as ffmpeg leaking CMA buffers when it did a stream off on OUTPUT before CAPTURE, though in reality it was probably much more dangerous than that. Signed-off-by: John Cox <[email protected]>
1 parent 562ee10 commit 6ab9539

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

drivers/staging/media/rpivid/rpivid_h265.c

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,12 +2365,50 @@ static void dec_state_delete(struct rpivid_ctx *const ctx)
23652365
kfree(s);
23662366
}
23672367

2368-
static void rpivid_h265_stop(struct rpivid_ctx *ctx)
2368+
struct irq_sync {
2369+
atomic_t done;
2370+
wait_queue_head_t wq;
2371+
struct rpivid_hw_irq_ent irq_ent;
2372+
};
2373+
2374+
static void phase2_sync_claimed(struct rpivid_dev *const dev, void *v)
23692375
{
2370-
struct rpivid_dev *const dev = ctx->dev;
2371-
unsigned int i;
2376+
struct irq_sync *const sync = v;
23722377

2373-
v4l2_info(&dev->v4l2_dev, "%s\n", __func__);
2378+
atomic_set(&sync->done, 1);
2379+
wake_up(&sync->wq);
2380+
}
2381+
2382+
static void phase1_sync_claimed(struct rpivid_dev *const dev, void *v)
2383+
{
2384+
struct irq_sync *const sync = v;
2385+
2386+
rpivid_hw_irq_active1_enable_claim(dev, 1);
2387+
rpivid_hw_irq_active2_claim(dev, &sync->irq_ent, phase2_sync_claimed, sync);
2388+
}
2389+
2390+
/* Sync with IRQ operations
2391+
*
2392+
* Claims phase1 and phase2 in turn and waits for the phase2 claim so any
2393+
* pending IRQ ops will have completed by the time this returns
2394+
*
2395+
* phase1 has counted enables so must reenable once claimed
2396+
* phase2 has unlimited enables
2397+
*/
2398+
static void irq_sync(struct rpivid_dev *const dev)
2399+
{
2400+
struct irq_sync sync;
2401+
2402+
atomic_set(&sync.done, 0);
2403+
init_waitqueue_head(&sync.wq);
2404+
2405+
rpivid_hw_irq_active1_claim(dev, &sync.irq_ent, phase1_sync_claimed, &sync);
2406+
wait_event(sync.wq, atomic_read(&sync.done));
2407+
}
2408+
2409+
static void h265_ctx_uninit(struct rpivid_dev *const dev, struct rpivid_ctx *ctx)
2410+
{
2411+
unsigned int i;
23742412

23752413
dec_env_uninit(ctx);
23762414
dec_state_delete(ctx);
@@ -2387,6 +2425,16 @@ static void rpivid_h265_stop(struct rpivid_ctx *ctx)
23872425
gptr_free(dev, ctx->coeff_bufs + i);
23882426
}
23892427

2428+
static void rpivid_h265_stop(struct rpivid_ctx *ctx)
2429+
{
2430+
struct rpivid_dev *const dev = ctx->dev;
2431+
2432+
v4l2_info(&dev->v4l2_dev, "%s\n", __func__);
2433+
2434+
irq_sync(dev);
2435+
h265_ctx_uninit(dev, ctx);
2436+
}
2437+
23902438
static int rpivid_h265_start(struct rpivid_ctx *ctx)
23912439
{
23922440
struct rpivid_dev *const dev = ctx->dev;
@@ -2448,7 +2496,7 @@ static int rpivid_h265_start(struct rpivid_ctx *ctx)
24482496
return 0;
24492497

24502498
fail:
2451-
rpivid_h265_stop(ctx);
2499+
h265_ctx_uninit(dev, ctx);
24522500
return -ENOMEM;
24532501
}
24542502

0 commit comments

Comments
 (0)