History

locking/qrwlock: Fix write unlock bug on big endian systems

This patch aims to get rid of endianness in queued_write_unlock(). We want to set __qrwlock->wmode to NULL, however the address is not &lock->cnts in big endian machine. That causes queued_write_unlock() write NULL to the wrong field of __qrwlock. So implement __qrwlock_write_byte() which returns the correct __qrwlock->wmode address.

pan xinhui committed 10 years ago

Commit 2db34e81 parent a2071cd1 file · +25 −2Browse files

Showing the changes to include (1 of 1 file). Show all

Unified · Split

include/asm-generic/qrwlock.h+25−2
@@ -25,7 +25,20 @@ · 24 unmodified lines
2525 #include <asm-generic/qrwlock_types.h>
2626
2727 /*
28− * Writer states & reader shift and bias
28+ * Writer states & reader shift and bias.
29+ *
30+ * | +0 | +1 | +2 | +3 |
31+ * ----+----+----+----+----+
32+ * LE | 78 | 56 | 34 | 12 | 0x12345678
33+ * ----+----+----+----+----+
34+ * | wr | rd |
35+ * +----+----+----+----+
36+ *
37+ * ----+----+----+----+----+
38+ * BE | 12 | 34 | 56 | 78 | 0x12345678
39+ * ----+----+----+----+----+
40+ * | rd | wr |
41+ * +----+----+----+----+
2942 */
3043 #define _QW_WAITING 1 /* A writer is waiting */
3144 #define _QW_LOCKED 0xff /* A writer holds the lock */
@@ -133,13 +146,23 @@ static inline void queued_read_unlock(struct qrwlock *lock) · 101 unmodified lines
133146 (void)atomic_sub_return_release(_QR_BIAS, &lock->cnts);
134147 }
135148
149+/**
150+ * __qrwlock_write_byte - retrieve the write byte address of a queue rwlock
151+ * @lock : Pointer to queue rwlock structure
152+ * Return: the write byte address of a queue rwlock
153+ */
154+static inline u8 *__qrwlock_write_byte(struct qrwlock *lock)
155+{
156+ return (u8 *)lock + 3 * IS_BUILTIN(CONFIG_CPU_BIG_ENDIAN);
157+}
158+
136159 /**
137160 * queued_write_unlock - release write lock of a queue rwlock
138161 * @lock : Pointer to queue rwlock structure
139162 */
140163 static inline void queued_write_unlock(struct qrwlock *lock)
141164 {
142− smp_store_release((u8 *)&lock->cnts, 0);
165+ smp_store_release(__qrwlock_write_byte(lock), 0);
143166 }
144167
145168 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t