netlink: add macro for checking dump ctx size
authorJakub Kicinski <kuba@kernel.org>
Thu, 5 Jan 2023 04:05:21 +0000 (20:05 -0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 6 Jan 2023 06:13:39 +0000 (22:13 -0800)
We encourage casting struct netlink_callback::ctx to a local
struct (in a comment above the field). Provide a convenience
macro for checking if the local struct fits into the ctx.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/netlink.h
net/netfilter/nf_conntrack_netlink.c

index d81bde5..38f6334 100644 (file)
@@ -263,6 +263,10 @@ struct netlink_callback {
        };
 };
 
+#define NL_ASSET_DUMP_CTX_FITS(type_name)                              \
+       BUILD_BUG_ON(sizeof(type_name) >                                \
+                    sizeof_field(struct netlink_callback, ctx))
+
 struct netlink_notify {
        struct net *net;
        u32 portid;
index 1286ae7..90672e2 100644 (file)
@@ -3866,7 +3866,7 @@ static int __init ctnetlink_init(void)
 {
        int ret;
 
-       BUILD_BUG_ON(sizeof(struct ctnetlink_list_dump_ctx) > sizeof_field(struct netlink_callback, ctx));
+       NL_ASSET_DUMP_CTX_FITS(struct ctnetlink_list_dump_ctx);
 
        ret = nfnetlink_subsys_register(&ctnl_subsys);
        if (ret < 0) {