Commit 63039946 authored by Mark Rutland's avatar Mark Rutland Committed by Peter Zijlstra
Browse files

locking/atomic: scripts: simplify raw_atomic_long*() definitions



Currently, atomic-long is split into two sections, one defining the
raw_atomic_long_*() ops for CONFIG_64BIT, and one defining the raw
atomic_long_*() ops for !CONFIG_64BIT.

With many lines elided, this looks like:

| #ifdef CONFIG_64BIT
| ...
| static __always_inline bool
| raw_atomic_long_try_cmpxchg(atomic_long_t *v, long *old, long new)
| {
|         return raw_atomic64_try_cmpxchg(v, (s64 *)old, new);
| }
| ...
| #else /* CONFIG_64BIT */
| ...
| static __always_inline bool
| raw_atomic_long_try_cmpxchg(atomic_long_t *v, long *old, long new)
| {
|         return raw_atomic_try_cmpxchg(v, (int *)old, new);
| }
| ...
| #endif

The two definitions are spread far apart in the file, and duplicate the
prototype, making it hard to have a legible set of kerneldoc comments.

Make this simpler by defining the C prototype once, and writing the two
definitions inline. For example, the above becomes:

| static __always_inline bool
| raw_atomic_long_try_cmpxchg(atomic_long_t *v, long *old, long new)
| {
| #ifdef CONFIG_64BIT
|         return raw_atomic64_try_cmpxchg(v, (s64 *)old, new);
| #else
|         return raw_atomic_try_cmpxchg(v, (int *)old, new);
| #endif
| }

As we now always have a single copy of the C prototype wrapping all the
potential definitions, we now have an obvious single location for kerneldoc
comments. As a bonus, both the script and the generated file are
somewhat shorter.

There should be no functional change as a result of this patch.

Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230605070124.3741859-23-mark.rutland@arm.com
parent b916a8c7
Loading
Loading
Loading
Loading
+341 −516

File changed.

Preview size limit exceeded, changes collapsed.

+9 −18
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ gen_args_cast()
	done
}

#gen_proto_order_variant(meta, pfx, name, sfx, order, atomic, int, arg...)
#gen_proto_order_variant(meta, pfx, name, sfx, order, arg...)
gen_proto_order_variant()
{
	local meta="$1"; shift
@@ -40,21 +40,24 @@ gen_proto_order_variant()
	local name="$1"; shift
	local sfx="$1"; shift
	local order="$1"; shift
	local atomic="$1"; shift
	local int="$1"; shift

	local atomicname="${pfx}${name}${sfx}${order}"

	local ret="$(gen_ret_type "${meta}" "long")"
	local params="$(gen_params "long" "atomic_long" "$@")"
	local argscast="$(gen_args_cast "${int}" "${atomic}" "$@")"
	local argscast_32="$(gen_args_cast "int" "atomic" "$@")"
	local argscast_64="$(gen_args_cast "s64" "atomic64" "$@")"
	local retstmt="$(gen_ret_stmt "${meta}")"

cat <<EOF
static __always_inline ${ret}
raw_atomic_long_${atomicname}(${params})
{
	${retstmt}raw_${atomic}_${atomicname}(${argscast});
#ifdef CONFIG_64BIT
	${retstmt}raw_atomic64_${atomicname}(${argscast_64});
#else
	${retstmt}raw_atomic_${atomicname}(${argscast_32});
#endif
}

EOF
@@ -84,24 +87,12 @@ typedef atomic_t atomic_long_t;
#define atomic_long_cond_read_relaxed	atomic_cond_read_relaxed
#endif

#ifdef CONFIG_64BIT

EOF

grep '^[a-z]' "$1" | while read name meta args; do
	gen_proto "${meta}" "${name}" "atomic64" "s64" ${args}
done

cat <<EOF
#else /* CONFIG_64BIT */

EOF

grep '^[a-z]' "$1" | while read name meta args; do
	gen_proto "${meta}" "${name}" "atomic" "int" ${args}
	gen_proto "${meta}" "${name}" ${args}
done

cat <<EOF
#endif /* CONFIG_64BIT */
#endif /* _LINUX_ATOMIC_LONG_H */
EOF