Skip to content

Commit e6115c6

Browse files
oleg-nesterovIngo Molnar
authored and
Ingo Molnar
committed
locking/seqlock: Change __seqprop() to return the function pointer
This simplifies the macro and makes it easy to add the new seqprop's with 2 or more args. Plus this way we do not lose the type info, the (void*) type cast is no longer needed. And the latter reveals the problem: a lot of seqcount_t helpers pass the "const seqcount_t *s" argument to __seqprop_ptr(seqcount_t *s) but (before this patch) "(void *)(s)" masked the problem. So this patch changes __seqprop_ptr() and __seqprop_##lockname##_ptr() to accept the "const LOCKNAME *s" argument. This is not nice either, they need to drop the constness on return because these helpers are used by both the readers and writers, but at least it is clear what's going on. Signed-off-by: Oleg Nesterov <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Waiman Long <[email protected]> Cc: Will Deacon <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Paul E. McKenney <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f995443 commit e6115c6

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

include/linux/seqlock.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ typedef struct seqcount_##lockname { \
200200
} seqcount_##lockname##_t; \
201201
\
202202
static __always_inline seqcount_t * \
203-
__seqprop_##lockname##_ptr(seqcount_##lockname##_t *s) \
203+
__seqprop_##lockname##_ptr(const seqcount_##lockname##_t *s) \
204204
{ \
205-
return &s->seqcount; \
205+
return (void *)&s->seqcount; /* drop const */ \
206206
} \
207207
\
208208
static __always_inline unsigned \
@@ -247,9 +247,9 @@ __seqprop_##lockname##_assert(const seqcount_##lockname##_t *s) \
247247
* __seqprop() for seqcount_t
248248
*/
249249

250-
static inline seqcount_t *__seqprop_ptr(seqcount_t *s)
250+
static inline seqcount_t *__seqprop_ptr(const seqcount_t *s)
251251
{
252-
return s;
252+
return (void *)s; /* drop const */
253253
}
254254

255255
static inline unsigned __seqprop_sequence(const seqcount_t *s)
@@ -292,19 +292,19 @@ SEQCOUNT_LOCKNAME(mutex, struct mutex, true, mutex)
292292
#define SEQCNT_WW_MUTEX_ZERO(name, lock) SEQCOUNT_LOCKNAME_ZERO(name, lock)
293293

294294
#define __seqprop_case(s, lockname, prop) \
295-
seqcount_##lockname##_t: __seqprop_##lockname##_##prop((void *)(s))
295+
seqcount_##lockname##_t: __seqprop_##lockname##_##prop
296296

297297
#define __seqprop(s, prop) _Generic(*(s), \
298-
seqcount_t: __seqprop_##prop((void *)(s)), \
298+
seqcount_t: __seqprop_##prop, \
299299
__seqprop_case((s), raw_spinlock, prop), \
300300
__seqprop_case((s), spinlock, prop), \
301301
__seqprop_case((s), rwlock, prop), \
302302
__seqprop_case((s), mutex, prop))
303303

304-
#define seqprop_ptr(s) __seqprop(s, ptr)
305-
#define seqprop_sequence(s) __seqprop(s, sequence)
306-
#define seqprop_preemptible(s) __seqprop(s, preemptible)
307-
#define seqprop_assert(s) __seqprop(s, assert)
304+
#define seqprop_ptr(s) __seqprop(s, ptr)(s)
305+
#define seqprop_sequence(s) __seqprop(s, sequence)(s)
306+
#define seqprop_preemptible(s) __seqprop(s, preemptible)(s)
307+
#define seqprop_assert(s) __seqprop(s, assert)(s)
308308

309309
/**
310310
* __read_seqcount_begin() - begin a seqcount_t read section w/o barrier

0 commit comments

Comments
 (0)