lkml.org 
[lkml]   [2021]   [Nov]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 12/17] linux/container_of.h: Remove unnecessary cast to (void *)
Date
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@gmail.com>
---
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
\
 
 \ /
  Last update: 2021-11-19 12:39    [W:0.572 / U:0.176 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site