Skip to content

Commit e1f1ee0

Browse files
hormsummakynes
authored andcommitted
netfilter: ctnetlink: compile ctnetlink_label_size with CONFIG_NF_CONNTRACK_EVENTS
Only provide ctnetlink_label_size when it is used, which is when CONFIG_NF_CONNTRACK_EVENTS is configured. Flagged by clang-18 W=1 builds as: .../nf_conntrack_netlink.c:385:19: warning: unused function 'ctnetlink_label_size' [-Wunused-function] 385 | static inline int ctnetlink_label_size(const struct nf_conn *ct) | ^~~~~~~~~~~~~~~~~~~~ The condition on CONFIG_NF_CONNTRACK_LABELS being removed by this patch guards compilation of non-trivial implementations of ctnetlink_dump_labels() and ctnetlink_label_size(). However, this is not necessary as each of these functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not defined as each function starts with the equivalent of: struct nf_conn_labels *labels = nf_ct_labels_find(ct); if (!labels) return 0; And nf_ct_labels_find always returns NULL if CONFIG_NF_CONNTRACK_LABELS is not enabled. So I believe that the compiler optimises the code away in such cases anyway. Found by inspection. Compile tested only. Originally splitted in two patches, Pablo Neira Ayuso collapsed them and added Fixes: tag. Fixes: 0ceabd8 ("netfilter: ctnetlink: deliver labels to userspace") Link: https://lore.kernel.org/netfilter-devel/[email protected]/ Signed-off-by: Simon Horman <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent fc56878 commit e1f1ee0

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

net/netfilter/nf_conntrack_netlink.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)
382382
#define ctnetlink_dump_secctx(a, b) (0)
383383
#endif
384384

385-
#ifdef CONFIG_NF_CONNTRACK_LABELS
385+
#ifdef CONFIG_NF_CONNTRACK_EVENTS
386386
static inline int ctnetlink_label_size(const struct nf_conn *ct)
387387
{
388388
struct nf_conn_labels *labels = nf_ct_labels_find(ct);
@@ -391,6 +391,7 @@ static inline int ctnetlink_label_size(const struct nf_conn *ct)
391391
return 0;
392392
return nla_total_size(sizeof(labels->bits));
393393
}
394+
#endif
394395

395396
static int
396397
ctnetlink_dump_labels(struct sk_buff *skb, const struct nf_conn *ct)
@@ -411,10 +412,6 @@ ctnetlink_dump_labels(struct sk_buff *skb, const struct nf_conn *ct)
411412

412413
return 0;
413414
}
414-
#else
415-
#define ctnetlink_dump_labels(a, b) (0)
416-
#define ctnetlink_label_size(a) (0)
417-
#endif
418415

419416
#define master_tuple(ct) &(ct->master->tuplehash[IP_CT_DIR_ORIGINAL].tuple)
420417

0 commit comments

Comments
 (0)