[PATCH trivial] kernel.h: Make container_of_safe type safe

From: Jason Gunthorpe
Date: Thu Jan 24 2019 - 15:55:11 EST


The final ternary expression is given void * and type * as arguments, so
the resulting type of the macro ends up being void *.

container_of returns a type which maches the argument, this provides type
safety and allows the expression to be immediately used as the target
type.

Explicitly cast ERR_CAST() to get the correct type.

Fixes: 05e6557b8ed8 ("staging: lustre: add container_of_safe()")
Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
---
include/linux/kernel.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Jiri, can you take this? Thanks

Jason

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 8f0e68e250a760..7b85aa607eb876 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -1013,7 +1013,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
!__same_type(*(ptr), void), \
"pointer type mismatch in container_of()"); \
- IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) : \
+ IS_ERR_OR_NULL(__mptr) ? ((type *)ERR_CAST(__mptr)) : \
((type *)(__mptr - offsetof(type, member))); })

/* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
--
2.20.1