Skip to content

Commit 35cff7a

Browse files
Sakari Ailusgregkh
authored andcommitted
container_of: Document container_of() is not to be used in new code
There is a warning in the kerneldoc documentation of container_of() that constness of its ptr argument is lost. While this is a valid suggestion container_of_const() should be used instead, the vast majority of new code still uses container_of(): $ git diff v6.13 v6.14|grep container_of\(|wc -l 646 $ git diff v6.13 v6.14|grep container_of_const|wc -l 9 Make an explicit recommendation to use container_of_const(). Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Link: https://lore.kernel.org/r/20250520103437.468691-1-sakari.ailus@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6beb4ec commit 35cff7a

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

include/linux/container_of.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @member: the name of the member within the struct.
1515
*
1616
* WARNING: any const qualifier of @ptr is lost.
17+
* Do not use container_of() in new code.
1718
*/
1819
#define container_of(ptr, type, member) ({ \
1920
void *__mptr = (void *)(ptr); \
@@ -28,6 +29,8 @@
2829
* @ptr: the pointer to the member
2930
* @type: the type of the container struct this is embedded in.
3031
* @member: the name of the member within the struct.
32+
*
33+
* Always prefer container_of_const() instead of container_of() in new code.
3134
*/
3235
#define container_of_const(ptr, type, member) \
3336
_Generic(ptr, \

0 commit comments

Comments
 (0)