Re: [PATCH v2 2/2] seqlock: change __seqprop() to return the function pointer

From: Ingo Molnar
Date: Thu Oct 12 2023 - 14:21:36 EST



* Oleg Nesterov <oleg@xxxxxxxxxx> wrote:

> 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.

> +__seqprop_##lockname##_ptr(const seqcount_##lockname##_t *s) \
> { \
> + return (void *)&s->seqcount; /* drop const */ \
> } \

> +static inline seqcount_t *__seqprop_ptr(const seqcount_t *s)
> {
> + return (void *)s; /* drop const */
> }

Okay, so dropping 'const' makes sense in terms of staying bug-compatible
with the previous API and not build-breaking the world - but could we
perhaps follow this up with fixups of the type misuse and then a removal
of the forced type casts from these APIs?

Meanwhile I'm applying your patches to tip:locking/core, unless someone objects.

Thanks,

Ingo