diff options
| author | Vincent Mailhol <mailhol@kernel.org> | 2026-07-14 20:18:01 +0200 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2026-07-15 07:15:26 +0200 |
| commit | f810b41defc44535715afa978dbcba8b3b9b9d99 (patch) | |
| tree | c6da264f65393db90cd74110b620e5f50863f231 /include/linux | |
| parent | a10639966fd72fff8f7fbf3c8e733307daabd38f (diff) | |
container_of: apply typeof_member() to container_of()
container_of() uses the construct below:
((type *)0)->member
to retrieve the type of the structure's member and then ensure that it
matches the type of the given pointer.
This construct being rather difficult to understand, the typeof_member()
macro was created to encapsulate it and give it a descriptive name.
Apply typeof_member() to container_of() to make it easier to read and
understand what this macro does.
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20260714-containerof_refactor-v1-1-b5c31164d2ad@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/container_of.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/include/linux/container_of.h b/include/linux/container_of.h index 1f6ebf27d962..28500a62ab7e 100644 --- a/include/linux/container_of.h +++ b/include/linux/container_of.h @@ -18,7 +18,7 @@ */ #define container_of(ptr, type, member) ({ \ void *__mptr = (void *)(ptr); \ - static_assert(__same_type(*(ptr), ((type *)0)->member) || \ + static_assert(__same_type(*(ptr), typeof_member(type, member)) || \ __same_type(*(ptr), void), \ "pointer type mismatch in container_of()"); \ ((type *)(__mptr - offsetof(type, member))); }) |
