[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211120130104.185699-11-alx.manpages@gmail.com>
Date: Sat, 20 Nov 2021 14:00:53 +0100
From: Alejandro Colomar <alx.manpages@...il.com>
To: LKML <linux-kernel@...r.kernel.org>
Cc: Alejandro Colomar <alx.manpages@...il.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Arnd Bergmann <arnd@...db.de>,
Alexey Dobriyan <adobriyan@...il.com>,
Jani Nikula <jani.nikula@...ux.intel.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Kees Cook <keescook@...omium.org>,
Joe Perches <joe@...ches.com>
Subject: [PATCH v2 10/20] 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@...il.com>
---
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
Powered by blists - more mailing lists