X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=libcfs%2Finclude%2Flibcfs%2Flinux%2Flinux-misc.h;h=ab1e2ffa476138e423a99f3227c6b0c4eb4b7674;hp=bff63ba0294590df42b39ab9c9ff8e78f30b411e;hb=da63a46c51e86953dc62db76b8fa4d1a0f1aef4d;hpb=e4d63c854d774792f8a77b8d1e575ccc2d8c3c8b diff --git a/libcfs/include/libcfs/linux/linux-misc.h b/libcfs/include/libcfs/linux/linux-misc.h index bff63ba..ab1e2ff 100644 --- a/libcfs/include/libcfs/linux/linux-misc.h +++ b/libcfs/include/libcfs/linux/linux-misc.h @@ -97,4 +97,21 @@ int kstrtobool_from_user(const char __user *s, size_t count, bool *res); void cfs_arch_init(void); +#ifndef container_of_safe +/** + * 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. + * + * Note: Copied from Linux 5.6, with BUILD_BUG_ON_MSG section removed. + */ +#define container_of_safe(ptr, type, member) ({ \ + void *__mptr = (void *)(ptr); \ + IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) : \ + ((type *)(__mptr - offsetof(type, member))); }) +#endif + #endif /* __LIBCFS_LINUX_MISC_H__ */