Commit 99409b93 authored by Xiaoming Ni's avatar Xiaoming Ni Committed by Peter Zijlstra

locking/semaphore: Add might_sleep() to down_*() family

Semaphore is sleeping lock. Add might_sleep() to down*() family
(with exception of down_trylock()) to detect atomic context sleep.
Signed-off-by: default avatarXiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: default avatarWill Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210809021215.19991-1-nixiaoming@huawei.com
parent b857174e
...@@ -54,6 +54,7 @@ void down(struct semaphore *sem) ...@@ -54,6 +54,7 @@ void down(struct semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
might_sleep();
raw_spin_lock_irqsave(&sem->lock, flags); raw_spin_lock_irqsave(&sem->lock, flags);
if (likely(sem->count > 0)) if (likely(sem->count > 0))
sem->count--; sem->count--;
...@@ -77,6 +78,7 @@ int down_interruptible(struct semaphore *sem) ...@@ -77,6 +78,7 @@ int down_interruptible(struct semaphore *sem)
unsigned long flags; unsigned long flags;
int result = 0; int result = 0;
might_sleep();
raw_spin_lock_irqsave(&sem->lock, flags); raw_spin_lock_irqsave(&sem->lock, flags);
if (likely(sem->count > 0)) if (likely(sem->count > 0))
sem->count--; sem->count--;
...@@ -103,6 +105,7 @@ int down_killable(struct semaphore *sem) ...@@ -103,6 +105,7 @@ int down_killable(struct semaphore *sem)
unsigned long flags; unsigned long flags;
int result = 0; int result = 0;
might_sleep();
raw_spin_lock_irqsave(&sem->lock, flags); raw_spin_lock_irqsave(&sem->lock, flags);
if (likely(sem->count > 0)) if (likely(sem->count > 0))
sem->count--; sem->count--;
...@@ -157,6 +160,7 @@ int down_timeout(struct semaphore *sem, long timeout) ...@@ -157,6 +160,7 @@ int down_timeout(struct semaphore *sem, long timeout)
unsigned long flags; unsigned long flags;
int result = 0; int result = 0;
might_sleep();
raw_spin_lock_irqsave(&sem->lock, flags); raw_spin_lock_irqsave(&sem->lock, flags);
if (likely(sem->count > 0)) if (likely(sem->count > 0))
sem->count--; sem->count--;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment