Skip to content

Commit 99409b9

Browse files
nixiaomingPeter Zijlstra
authored andcommitted
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: Xiaoming Ni <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b857174 commit 99409b9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/locking/semaphore.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void down(struct semaphore *sem)
5454
{
5555
unsigned long flags;
5656

57+
might_sleep();
5758
raw_spin_lock_irqsave(&sem->lock, flags);
5859
if (likely(sem->count > 0))
5960
sem->count--;
@@ -77,6 +78,7 @@ int down_interruptible(struct semaphore *sem)
7778
unsigned long flags;
7879
int result = 0;
7980

81+
might_sleep();
8082
raw_spin_lock_irqsave(&sem->lock, flags);
8183
if (likely(sem->count > 0))
8284
sem->count--;
@@ -103,6 +105,7 @@ int down_killable(struct semaphore *sem)
103105
unsigned long flags;
104106
int result = 0;
105107

108+
might_sleep();
106109
raw_spin_lock_irqsave(&sem->lock, flags);
107110
if (likely(sem->count > 0))
108111
sem->count--;
@@ -157,6 +160,7 @@ int down_timeout(struct semaphore *sem, long timeout)
157160
unsigned long flags;
158161
int result = 0;
159162

163+
might_sleep();
160164
raw_spin_lock_irqsave(&sem->lock, flags);
161165
if (likely(sem->count > 0))
162166
sem->count--;

0 commit comments

Comments
 (0)