| From | Alejandro Colomar <> | Subject | [PATCH 12/17] linux/container_of.h: Remove unnecessary cast to (void *) | Date | Fri, 19 Nov 2021 12:36:40 +0100 |
| |
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
|