Skip to contentSkip to conversation

container_of: remove container_of_safe()

PATCH In review Greg Kroah-Hartman 4 participants 4 messages Oct 24, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 container_of: remove container_of_safe()

It came in from a staging driver that has been long removed from the tree, and there are no in-kernel users of the macro, and it's very dubious if anyone should ever use this thing, so just remove it entirely.

Cc Sakari Ailus <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 include/linux/container_of.h | 16 ----------------
 1 file changed, 16 deletions(-)
include/linux/container_of.h +0 -16
index 2f4944b791b8..a6f242137b11 100644
@@ -21,20 +21,4 @@
 		      "pointer type mismatch in container_of()");	\
 	((type *)(__mptr - offsetof(type, member))); })
 
-/**
- * container_of_safe - cast a member of a structure out to the containing structure
- * @ptr:	the pointer to the member.
- * @type:	the type of the container struct this is embedded in.
- * @member:	the name of the member within the struct.
- *
- * If IS_ERR_OR_NULL(ptr), ptr is returned unchanged.
- */
-#define container_of_safe(ptr, type, member) ({				\
-	void *__mptr = (void *)(ptr);					\
-	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
-		      __same_type(*(ptr), void),			\
-		      "pointer type mismatch in container_of_safe()");	\
-	IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) :			\
-		((type *)(__mptr - offsetof(type, member))); })
-
 #endif	/* _LINUX_CONTAINER_OF_H */
Signature · 1 line
2.38.1
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Greg Kroah-Hartman

It came in from a staging driver that has been long removed from the tree, and there are no in-kernel users of the macro, and it's very dubious if anyone should ever use this thing, so just remove it entirely.

Cc Sakari Ailus <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 32 lines
---
 include/linux/container_of.h | 16 ----------------
 1 file changed, 16 deletions(-)
include/linux/container_of.h +0 -17
index 2f4944b791b8..a6f242137b11 100644
@@ -21,20 +21,4 @@
                      "pointer type mismatch in container_of()");       \
        ((type *)(__mptr - offsetof(type, member))); })
 
-/**
- * container_of_safe - cast a member of a structure out to the containing structure
- * @ptr:       the pointer to the member.
- * @type:      the type of the container struct this is embedded in.
- * @member:    the name of the member within the struct.
- *
- * If IS_ERR_OR_NULL(ptr), ptr is returned unchanged.
- */
-#define container_of_safe(ptr, type, member) ({                                \
-       void *__mptr = (void *)(ptr);                                   \
-       static_assert(__same_type(*(ptr), ((type *)0)->member) ||       \
-                     __same_type(*(ptr), void),                        \
-                     "pointer type mismatch in container_of_safe()");  \
-       IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) :                     \
-               ((type *)(__mptr - offsetof(type, member))); })
-
 #endif /* _LINUX_CONTAINER_OF_H */
--

2.38.1

Acked-by on v1 1/1
#2 lore raw
In reply to Greg Kroah-Hartman
Quoted 4 lines · Greg Kroah-Hartman

It came in from a staging driver that has been long removed from the tree, and there are no in-kernel users of the macro, and it's very dubious if anyone should ever use this thing, so just remove it entirely.

Quoted 36 lines
Cc Sakari Ailus <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 include/linux/container_of.h | 16 ----------------
 1 file changed, 16 deletions(-)
include/linux/container_of.h +0 -16
index 2f4944b791b8..a6f242137b11 100644
@@ -21,20 +21,4 @@
 		      "pointer type mismatch in container_of()");	\
 	((type *)(__mptr - offsetof(type, member))); })
 
-/**
- * container_of_safe - cast a member of a structure out to the containing structure
- * @ptr:	the pointer to the member.
- * @type:	the type of the container struct this is embedded in.
- * @member:	the name of the member within the struct.
- *
- * If IS_ERR_OR_NULL(ptr), ptr is returned unchanged.
- */
-#define container_of_safe(ptr, type, member) ({				\
-	void *__mptr = (void *)(ptr);					\
-	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
-		      __same_type(*(ptr), void),			\
-		      "pointer type mismatch in container_of_safe()");	\
-	IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) :			\
-		((type *)(__mptr - offsetof(type, member))); })
-
 #endif	/* _LINUX_CONTAINER_OF_H */
Signature · 1 line
2.38.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v1 1/1
#3 lore raw
In reply to Greg Kroah-Hartman
Quoted 9 lines · Greg Kroah-Hartman

It came in from a staging driver that has been long removed from the tree, and there are no in-kernel users of the macro, and it's very dubious if anyone should ever use this thing, so just remove it entirely.

Cc Sakari Ailus <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

Thanks!

Signature · 1 line
Sakari Ailus