[COMMON] media: scaler: wait device stop running locklessly
authorCho KyongHo <pullip.cho@samsung.com>
Wed, 28 Dec 2016 14:17:15 +0000 (23:17 +0900)
committerSeungchul Kim <sc377.kim@samsung.com>
Mon, 28 May 2018 05:28:20 +0000 (14:28 +0900)
commit652b24591ad3da33edca108d006d9219dd109dc9
treee9adc44b8973440aafff7749ca4930e367d25776
parent246bdf7a11db1b373fa6bdbbf1765a0aedcc9809
[COMMON] media: scaler: wait device stop running locklessly

Since "fec3dab [8895] media: scaler: add mutex lock" patch has been
applied, the following problem is reported:

BUG: sleeping function called from invalid context at kernel/locking/mutex.c:617
in_atomic(): 1, irqs_disabled(): 128, pid: 0, name: swapper/0
CPU: 0 MPIDR: 80000100 PID: 0 Comm: swapper/0 Tainted: G        W       4.4.13-10228462-eng #1
Hardware name: Samsung SM-G955F rev00 board based on EXYNOS8895 (DT)
Call trace:
[<ffffffc00008a254>] dump_backtrace+0x0/0x110
[<ffffffc00008a378>] show_stack+0x14/0x20
[<ffffffc0003892b4>] dump_stack+0xa8/0xe4
[<ffffffc0000d5220>] ___might_sleep+0x244/0x258
[<ffffffc0000d52ac>] __might_sleep+0x78/0x8c
[<ffffffc000c240ec>] mutex_lock_nested+0x3c/0x3bc
[<ffffffc00075490c>] sc_m2m1shot_device_run+0x30/0xd4
[<ffffffc000746b74>] m2m1shot_task_schedule+0x90/0xd8
[<ffffffc00074735c>] m2m1shot_task_finish+0x78/0x90
[<ffffffc000752338>] sc_irq_handler+0x4a4/0x4f4
[<ffffffc00010b84c>] handle_irq_event_percpu+0x15c/0x418
[<ffffffc00010bb4c>] handle_irq_event+0x44/0x78
[<ffffffc00010ef04>] handle_fasteoi_irq+0xc4/0x138
[<ffffffc00010af80>] generic_handle_irq+0x1c/0x30
[<ffffffc00010b060>] __handle_domain_irq+0xcc/0x11c
[<ffffffc0000814f8>] gic_handle_irq+0x70/0xcc

It is caused by the mutex lock introduced by the above patch and the
mutex is required for modifying DEV_SUSPEND and testing DEV_RUN
atomically.

However, the problem that a new task starts running between testing
DEV_SUSPEND and testing DEV_RUN in sc_suspend() and sc_shutdown() is
basically caused by the sc_irq_handler() that clears DEV_RUN before
testing DEV_SUSPEND. Therefore, the problem of running an unexpected
task is simply solved by moving clearing DEV_RUN after testing
DEV_SUSPEND.

Change-Id: I7deed59fc636868d062a63ba8c5b2bd5b9f3c753
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
drivers/media/platform/exynos/scaler/scaler-core.c