Skip to content
Permalink
Browse files
linux/container_of.h: Remove unnecessary cast
Casts are dangerous.
Moreover, (almost) everything converts to 'void *' implicitly,
with the exception of pointers to const.

Change the temporary to be const,
and therefore allow implicit conversion from everything.
Since we don't modify it,
this also adds safety.

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
  • Loading branch information
alejandro-colomar authored and intel-lab-lkp committed Nov 20, 2021
1 parent 055a4f5 commit ed03be33a3de1708b5a06ea31cc6cd8573890649
Showing 1 changed file with 1 addition and 1 deletion.
@@ -17,7 +17,7 @@
*
*/
#define container_of(ptr, type, member) ({ \
void *__mptr = (void *)(ptr); \
const void *__mptr = (ptr); \
static_assert(__same_type(*(ptr), memberof(type, member)) || \
__same_type(*(ptr), void), \
"pointer type mismatch in container_of()"); \

0 comments on commit ed03be3

Please sign in to comment.