[PATCH 12/17] linux/container_of.h: Remove unnecessary cast to (void *)

From: Alejandro Colomar
Date: Fri Nov 19 2021 - 06:37:51 EST


Casts are dangerous.
Every pointer converts implicitly to (void *).
Remove the unnecessary cast.

Since this macro is used with some pointers-to-const,
removing the cast triggers warnings about that
(implicit conversion from poitner-to-const to pointer-to-void).

To solve it, since we don't use the pointer to modify its contents,
we can simply use a (const void *).

Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
---
include/linux/container_of.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index 2100adb9d109..62df2ba21c20 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), \
@@ -36,7 +36,7 @@
*/
#define container_of_safe(ptr, type, member) ( \
{ \
- void *__mptr = (void *)(ptr); \
+ const void *__mptr = (ptr); \
\
IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) : \
container_of(ptr, type, member); \
--
2.33.1