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

netfilter: nf_ct_generic: add generic_kmemdup_sysctl_table function

This patch is a cleanup. It adds generic_kmemdup_sysctl_table to
split code into smaller chunks. Yet it prepares introduction
of nf_conntrack_proto_*_sysctl.c.

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Gao feng and committed by
Pablo Neira Ayuso
22ac0377 f42c4183

+32 -9
+32 -9
net/netfilter/nf_conntrack_proto_generic.c
··· 135 135 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ 136 136 #endif /* CONFIG_SYSCTL */ 137 137 138 - static int generic_init_net(struct net *net, u_int16_t proto) 138 + static int generic_kmemdup_sysctl_table(struct nf_proto_net *pn, 139 + struct nf_generic_net *gn) 139 140 { 140 - struct nf_generic_net *gn = generic_pernet(net); 141 - struct nf_proto_net *pn = (struct nf_proto_net *)gn; 142 - gn->timeout = nf_ct_generic_timeout; 143 141 #ifdef CONFIG_SYSCTL 144 142 pn->ctl_table = kmemdup(generic_sysctl_table, 145 143 sizeof(generic_sysctl_table), 146 144 GFP_KERNEL); 147 145 if (!pn->ctl_table) 148 146 return -ENOMEM; 149 - pn->ctl_table[0].data = &gn->timeout; 150 147 148 + pn->ctl_table[0].data = &gn->timeout; 149 + #endif 150 + return 0; 151 + } 152 + 153 + static int generic_kmemdup_compat_sysctl_table(struct nf_proto_net *pn, 154 + struct nf_generic_net *gn) 155 + { 156 + #ifdef CONFIG_SYSCTL 151 157 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 152 158 pn->ctl_compat_table = kmemdup(generic_compat_sysctl_table, 153 159 sizeof(generic_compat_sysctl_table), 154 160 GFP_KERNEL); 155 - if (!pn->ctl_compat_table) { 156 - kfree(pn->ctl_table); 157 - pn->ctl_table = NULL; 161 + if (!pn->ctl_compat_table) 158 162 return -ENOMEM; 159 - } 163 + 160 164 pn->ctl_compat_table[0].data = &gn->timeout; 161 165 #endif 162 166 #endif 163 167 return 0; 168 + } 169 + 170 + static int generic_init_net(struct net *net, u_int16_t proto) 171 + { 172 + int ret; 173 + struct nf_generic_net *gn = generic_pernet(net); 174 + struct nf_proto_net *pn = &gn->pn; 175 + 176 + gn->timeout = nf_ct_generic_timeout; 177 + 178 + ret = generic_kmemdup_compat_sysctl_table(pn, gn); 179 + if (ret < 0) 180 + return ret; 181 + 182 + ret = generic_kmemdup_sysctl_table(pn, gn); 183 + if (ret < 0) 184 + nf_ct_kfree_compat_sysctl_table(pn); 185 + 186 + return ret; 164 187 } 165 188 166 189 struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly =