Skip to content

Commit 001217d

Browse files
ubizjakakpm00
authored andcommitted
percpu: introduce PERCPU_PTR() macro
Introduce PERCPU_PTR() macro to cast the percpu pointer from the percpu address space to a generic (kernel) address space. Use it in per_cpu_ptr() and related SHIFT_PERCPU_PTR() macros. Also remove common knowledge from SHIFT_PERCPU_PTR() comment, "weird cast" is just a standard way to inform sparse of a cast from the percpu address space to a generic address space. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Uros Bizjak <[email protected]> Acked-by: Christoph Lameter <[email protected]> Cc: Dennis Zhou <[email protected]> Cc: Tejun Heo <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 74ef070 commit 001217d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

include/linux/percpu-defs.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,17 @@ do { \
220220
(void)__vpp_verify; \
221221
} while (0)
222222

223+
#define PERCPU_PTR(__p) \
224+
(typeof(*(__p)) __force __kernel *)(__p);
225+
223226
#ifdef CONFIG_SMP
224227

225228
/*
226-
* Add an offset to a pointer but keep the pointer as-is. Use RELOC_HIDE()
227-
* to prevent the compiler from making incorrect assumptions about the
228-
* pointer value. The weird cast keeps both GCC and sparse happy.
229+
* Add an offset to a pointer. Use RELOC_HIDE() to prevent the compiler
230+
* from making incorrect assumptions about the pointer value.
229231
*/
230232
#define SHIFT_PERCPU_PTR(__p, __offset) \
231-
RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
233+
RELOC_HIDE(PERCPU_PTR(__p), (__offset))
232234

233235
#define per_cpu_ptr(ptr, cpu) \
234236
({ \
@@ -258,7 +260,7 @@ do { \
258260
({ \
259261
(void)(cpu); \
260262
__verify_pcpu_ptr(ptr); \
261-
(typeof(*(ptr)) __kernel __force *)(ptr); \
263+
PERCPU_PTR(ptr); \
262264
})
263265

264266
#define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0)

0 commit comments

Comments
 (0)