[PATCH v2 10/20] linux/container_of.h: Remove unnecessary cast

From: Alejandro Colomar
Date: Sat Nov 20 2021 - 08:01:43 EST


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@xxxxxxxxx>
---
include/linux/container_of.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index d1a66e72d246..682a2a606ee9 100644
--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -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()"); \
--
2.33.1