aboutsummaryrefslogtreecommitdiff
path: root/drivers/tty/tty_ldsem.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-12-18 14:34:27 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2013-12-18 14:34:27 -0800
commite5233658201924fbcffa9a6886ebb08c4cee65f2 (patch)
treec096aaede3e675245102199eea8bbec32f2fec0e /drivers/tty/tty_ldsem.c
parent1aba038bbb2c7663cb80d785423694780a6dd72e (diff)
parentc2db11eca089b60148ded7467b956a547e8a2ae0 (diff)
Merge tag 'tty-3.13-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
Pull tty/serial fixes from Greg KH: "Here are a few fixes for 3.13-rc5 that resolve a number of reported tty and serial driver issues" * tag 'tty-3.13-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: tty: xuartps: Properly guard sysrq specific code n_tty: Fix apparent order of echoed output serial: 8250_dw: add new ACPI IDs serial: 8250_dw: Fix LCR workaround regression tty: Fix hang at ldsem_down_read()
Diffstat (limited to 'drivers/tty/tty_ldsem.c')
-rw-r--r--drivers/tty/tty_ldsem.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/drivers/tty/tty_ldsem.c b/drivers/tty/tty_ldsem.c
index 22fad8ad5ac..d8a55e87877 100644
--- a/drivers/tty/tty_ldsem.c
+++ b/drivers/tty/tty_ldsem.c
@@ -86,11 +86,21 @@ static inline long ldsem_atomic_update(long delta, struct ld_semaphore *sem)
return atomic_long_add_return(delta, (atomic_long_t *)&sem->count);
}
+/*
+ * ldsem_cmpxchg() updates @*old with the last-known sem->count value.
+ * Returns 1 if count was successfully changed; @*old will have @new value.
+ * Returns 0 if count was not changed; @*old will have most recent sem->count
+ */
static inline int ldsem_cmpxchg(long *old, long new, struct ld_semaphore *sem)
{
- long tmp = *old;
- *old = atomic_long_cmpxchg(&sem->count, *old, new);
- return *old == tmp;
+ long tmp = atomic_long_cmpxchg(&sem->count, *old, new);
+ if (tmp == *old) {
+ *old = new;
+ return 1;
+ } else {
+ *old = tmp;
+ return 0;
+ }
}
/*