Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nf_tables: Fix percpu address space issues in nf_tables_api.c

Compiling nf_tables_api.c results in several sparse warnings:

nf_tables_api.c:2077:31: warning: incorrect type in return expression (different address spaces)
nf_tables_api.c:2080:31: warning: incorrect type in return expression (different address spaces)
nf_tables_api.c:2084:31: warning: incorrect type in return expression (different address spaces)

nf_tables_api.c:2740:23: warning: incorrect type in assignment (different address spaces)
nf_tables_api.c:2752:38: warning: incorrect type in assignment (different address spaces)
nf_tables_api.c:2798:21: warning: incorrect type in argument 1 (different address spaces)

Use {ERR_PTR,IS_ERR,PTR_ERR}_PCPU() macros when crossing between generic
and percpu address spaces and add __percpu annotation to *stats pointer
to fix these warnings.

Found by GCC's named address space checks.

There were no changes in the resulting object files.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Uros Bizjak and committed by
Pablo Neira Ayuso
0741f555 6c959fd5

+8 -8
+8 -8
net/netfilter/nf_tables_api.c
··· 2082 2082 err = nla_parse_nested_deprecated(tb, NFTA_COUNTER_MAX, attr, 2083 2083 nft_counter_policy, NULL); 2084 2084 if (err < 0) 2085 - return ERR_PTR(err); 2085 + return ERR_PTR_PCPU(err); 2086 2086 2087 2087 if (!tb[NFTA_COUNTER_BYTES] || !tb[NFTA_COUNTER_PACKETS]) 2088 - return ERR_PTR(-EINVAL); 2088 + return ERR_PTR_PCPU(-EINVAL); 2089 2089 2090 2090 newstats = netdev_alloc_pcpu_stats(struct nft_stats); 2091 2091 if (newstats == NULL) 2092 - return ERR_PTR(-ENOMEM); 2092 + return ERR_PTR_PCPU(-ENOMEM); 2093 2093 2094 2094 /* Restore old counters on this cpu, no problem. Per-cpu statistics 2095 2095 * are not exposed to userspace. ··· 2533 2533 2534 2534 if (nla[NFTA_CHAIN_COUNTERS]) { 2535 2535 stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]); 2536 - if (IS_ERR(stats)) { 2536 + if (IS_ERR_PCPU(stats)) { 2537 2537 nft_chain_release_hook(&hook); 2538 2538 kfree(basechain); 2539 - return PTR_ERR(stats); 2539 + return PTR_ERR_PCPU(stats); 2540 2540 } 2541 2541 rcu_assign_pointer(basechain->stats, stats); 2542 2542 } ··· 2650 2650 struct nft_table *table = ctx->table; 2651 2651 struct nft_chain *chain = ctx->chain; 2652 2652 struct nft_chain_hook hook = {}; 2653 - struct nft_stats *stats = NULL; 2653 + struct nft_stats __percpu *stats = NULL; 2654 2654 struct nft_hook *h, *next; 2655 2655 struct nf_hook_ops *ops; 2656 2656 struct nft_trans *trans; ··· 2746 2746 } 2747 2747 2748 2748 stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]); 2749 - if (IS_ERR(stats)) { 2750 - err = PTR_ERR(stats); 2749 + if (IS_ERR_PCPU(stats)) { 2750 + err = PTR_ERR_PCPU(stats); 2751 2751 goto err_hooks; 2752 2752 } 2753 2753 }