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

netfilter: Remove checks of seq_printf() return values

The return value of seq_printf() is soon to be removed. Remove the
checks from seq_printf() in favor of seq_has_overflowed().

Link: http://lkml.kernel.org/r/20141104142236.GA10239@salvia
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Patrick McHardy <kaber@trash.net>
Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Cc: netfilter-devel@vger.kernel.org
Cc: coreteam@netfilter.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

+97 -97
+16 -20
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
··· 94 94 } 95 95 96 96 #ifdef CONFIG_NF_CONNTRACK_SECMARK 97 - static int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) 97 + static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) 98 98 { 99 99 int ret; 100 100 u32 len; ··· 102 102 103 103 ret = security_secid_to_secctx(ct->secmark, &secctx, &len); 104 104 if (ret) 105 - return 0; 105 + return; 106 106 107 - ret = seq_printf(s, "secctx=%s ", secctx); 107 + seq_printf(s, "secctx=%s ", secctx); 108 108 109 109 security_release_secctx(secctx, len); 110 - return ret; 111 110 } 112 111 #else 113 - static inline int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) 112 + static inline void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) 114 113 { 115 - return 0; 116 114 } 117 115 #endif 118 116 ··· 139 141 NF_CT_ASSERT(l4proto); 140 142 141 143 ret = -ENOSPC; 142 - if (seq_printf(s, "%-8s %u %ld ", 143 - l4proto->name, nf_ct_protonum(ct), 144 - timer_pending(&ct->timeout) 145 - ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0) 146 - goto release; 144 + seq_printf(s, "%-8s %u %ld ", 145 + l4proto->name, nf_ct_protonum(ct), 146 + timer_pending(&ct->timeout) 147 + ? (long)(ct->timeout.expires - jiffies)/HZ : 0); 147 148 148 149 if (l4proto->print_conntrack) 149 150 l4proto->print_conntrack(s, ct); ··· 160 163 goto release; 161 164 162 165 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) 163 - if (seq_printf(s, "[UNREPLIED] ")) 164 - goto release; 166 + seq_printf(s, "[UNREPLIED] "); 165 167 166 168 print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, 167 169 l3proto, l4proto); ··· 172 176 goto release; 173 177 174 178 if (test_bit(IPS_ASSURED_BIT, &ct->status)) 175 - if (seq_printf(s, "[ASSURED] ")) 176 - goto release; 179 + seq_printf(s, "[ASSURED] "); 177 180 178 181 #ifdef CONFIG_NF_CONNTRACK_MARK 179 - if (seq_printf(s, "mark=%u ", ct->mark)) 180 - goto release; 182 + seq_printf(s, "mark=%u ", ct->mark); 181 183 #endif 182 184 183 - if (ct_show_secctx(s, ct)) 185 + ct_show_secctx(s, ct); 186 + 187 + seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)); 188 + 189 + if (seq_has_overflowed(s)) 184 190 goto release; 185 191 186 - if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use))) 187 - goto release; 188 192 ret = 0; 189 193 release: 190 194 nf_ct_put(ct);
+29 -31
net/netfilter/nf_conntrack_standalone.c
··· 120 120 } 121 121 122 122 #ifdef CONFIG_NF_CONNTRACK_SECMARK 123 - static int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) 123 + static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) 124 124 { 125 125 int ret; 126 126 u32 len; ··· 128 128 129 129 ret = security_secid_to_secctx(ct->secmark, &secctx, &len); 130 130 if (ret) 131 - return 0; 131 + return; 132 132 133 - ret = seq_printf(s, "secctx=%s ", secctx); 133 + seq_printf(s, "secctx=%s ", secctx); 134 134 135 135 security_release_secctx(secctx, len); 136 - return ret; 137 136 } 138 137 #else 139 - static inline int ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) 138 + static inline void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) 140 139 { 141 - return 0; 142 140 } 143 141 #endif 144 142 145 143 #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP 146 - static int ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct) 144 + static void ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct) 147 145 { 148 146 struct ct_iter_state *st = s->private; 149 147 struct nf_conn_tstamp *tstamp; ··· 155 157 else 156 158 delta_time = 0; 157 159 158 - return seq_printf(s, "delta-time=%llu ", 159 - (unsigned long long)delta_time); 160 + seq_printf(s, "delta-time=%llu ", 161 + (unsigned long long)delta_time); 160 162 } 161 - return 0; 163 + return; 162 164 } 163 165 #else 164 - static inline int 166 + static inline void 165 167 ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct) 166 168 { 167 - return 0; 168 169 } 169 170 #endif 170 171 ··· 190 193 NF_CT_ASSERT(l4proto); 191 194 192 195 ret = -ENOSPC; 193 - if (seq_printf(s, "%-8s %u %-8s %u %ld ", 194 - l3proto->name, nf_ct_l3num(ct), 195 - l4proto->name, nf_ct_protonum(ct), 196 - timer_pending(&ct->timeout) 197 - ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0) 198 - goto release; 196 + seq_printf(s, "%-8s %u %-8s %u %ld ", 197 + l3proto->name, nf_ct_l3num(ct), 198 + l4proto->name, nf_ct_protonum(ct), 199 + timer_pending(&ct->timeout) 200 + ? (long)(ct->timeout.expires - jiffies)/HZ : 0); 199 201 200 202 if (l4proto->print_conntrack) 201 203 l4proto->print_conntrack(s, ct); ··· 202 206 print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, 203 207 l3proto, l4proto); 204 208 209 + if (seq_has_overflowed(s)) 210 + goto release; 211 + 205 212 if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL)) 206 213 goto release; 207 214 208 215 if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status))) 209 - if (seq_printf(s, "[UNREPLIED] ")) 210 - goto release; 216 + seq_printf(s, "[UNREPLIED] "); 211 217 212 218 print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, 213 219 l3proto, l4proto); ··· 218 220 goto release; 219 221 220 222 if (test_bit(IPS_ASSURED_BIT, &ct->status)) 221 - if (seq_printf(s, "[ASSURED] ")) 222 - goto release; 223 + seq_printf(s, "[ASSURED] "); 224 + 225 + if (seq_has_overflowed(s)) 226 + goto release; 223 227 224 228 #if defined(CONFIG_NF_CONNTRACK_MARK) 225 - if (seq_printf(s, "mark=%u ", ct->mark)) 226 - goto release; 229 + seq_printf(s, "mark=%u ", ct->mark); 227 230 #endif 228 231 229 - if (ct_show_secctx(s, ct)) 230 - goto release; 232 + ct_show_secctx(s, ct); 231 233 232 234 #ifdef CONFIG_NF_CONNTRACK_ZONES 233 - if (seq_printf(s, "zone=%u ", nf_ct_zone(ct))) 234 - goto release; 235 + seq_printf(s, "zone=%u ", nf_ct_zone(ct)); 235 236 #endif 236 237 237 - if (ct_show_delta_time(s, ct)) 238 - goto release; 238 + ct_show_delta_time(s, ct); 239 239 240 - if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use))) 240 + seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)); 241 + 242 + if (seq_has_overflowed(s)) 241 243 goto release; 242 244 243 245 ret = 0;
+16 -14
net/netfilter/nf_log.c
··· 294 294 { 295 295 loff_t *pos = v; 296 296 const struct nf_logger *logger; 297 - int i, ret; 297 + int i; 298 298 struct net *net = seq_file_net(s); 299 299 300 300 logger = rcu_dereference_protected(net->nf.nf_loggers[*pos], 301 301 lockdep_is_held(&nf_log_mutex)); 302 302 303 303 if (!logger) 304 - ret = seq_printf(s, "%2lld NONE (", *pos); 304 + seq_printf(s, "%2lld NONE (", *pos); 305 305 else 306 - ret = seq_printf(s, "%2lld %s (", *pos, logger->name); 306 + seq_printf(s, "%2lld %s (", *pos, logger->name); 307 307 308 - if (ret < 0) 309 - return ret; 308 + if (seq_has_overflowed(s)) 309 + return -ENOSPC; 310 310 311 311 for (i = 0; i < NF_LOG_TYPE_MAX; i++) { 312 312 if (loggers[*pos][i] == NULL) ··· 314 314 315 315 logger = rcu_dereference_protected(loggers[*pos][i], 316 316 lockdep_is_held(&nf_log_mutex)); 317 - ret = seq_printf(s, "%s", logger->name); 318 - if (ret < 0) 319 - return ret; 320 - if (i == 0 && loggers[*pos][i + 1] != NULL) { 321 - ret = seq_printf(s, ","); 322 - if (ret < 0) 323 - return ret; 324 - } 317 + seq_printf(s, "%s", logger->name); 318 + if (i == 0 && loggers[*pos][i + 1] != NULL) 319 + seq_printf(s, ","); 320 + 321 + if (seq_has_overflowed(s)) 322 + return -ENOSPC; 325 323 } 326 324 327 - return seq_printf(s, ")\n"); 325 + seq_printf(s, ")\n"); 326 + 327 + if (seq_has_overflowed(s)) 328 + return -ENOSPC; 329 + return 0; 328 330 } 329 331 330 332 static const struct seq_operations nflog_seq_ops = {
+12 -7
net/netfilter/x_tables.c
··· 947 947 { 948 948 struct xt_table *table = list_entry(v, struct xt_table, list); 949 949 950 - if (strlen(table->name)) 951 - return seq_printf(seq, "%s\n", table->name); 952 - else 950 + if (strlen(table->name)) { 951 + seq_printf(seq, "%s\n", table->name); 952 + return seq_has_overflowed(seq); 953 + } else 953 954 return 0; 954 955 } 955 956 ··· 1087 1086 if (trav->curr == trav->head) 1088 1087 return 0; 1089 1088 match = list_entry(trav->curr, struct xt_match, list); 1090 - return (*match->name == '\0') ? 0 : 1091 - seq_printf(seq, "%s\n", match->name); 1089 + if (*match->name == '\0') 1090 + return 0; 1091 + seq_printf(seq, "%s\n", match->name); 1092 + return seq_has_overflowed(seq); 1092 1093 } 1093 1094 return 0; 1094 1095 } ··· 1142 1139 if (trav->curr == trav->head) 1143 1140 return 0; 1144 1141 target = list_entry(trav->curr, struct xt_target, list); 1145 - return (*target->name == '\0') ? 0 : 1146 - seq_printf(seq, "%s\n", target->name); 1142 + if (*target->name == '\0') 1143 + return 0; 1144 + seq_printf(seq, "%s\n", target->name); 1145 + return seq_has_overflowed(seq); 1147 1146 } 1148 1147 return 0; 1149 1148 }
+17 -19
net/netfilter/xt_hashlimit.c
··· 789 789 static int dl_seq_real_show(struct dsthash_ent *ent, u_int8_t family, 790 790 struct seq_file *s) 791 791 { 792 - int res; 793 792 const struct xt_hashlimit_htable *ht = s->private; 794 793 795 794 spin_lock(&ent->lock); ··· 797 798 798 799 switch (family) { 799 800 case NFPROTO_IPV4: 800 - res = seq_printf(s, "%ld %pI4:%u->%pI4:%u %u %u %u\n", 801 - (long)(ent->expires - jiffies)/HZ, 802 - &ent->dst.ip.src, 803 - ntohs(ent->dst.src_port), 804 - &ent->dst.ip.dst, 805 - ntohs(ent->dst.dst_port), 806 - ent->rateinfo.credit, ent->rateinfo.credit_cap, 807 - ent->rateinfo.cost); 801 + seq_printf(s, "%ld %pI4:%u->%pI4:%u %u %u %u\n", 802 + (long)(ent->expires - jiffies)/HZ, 803 + &ent->dst.ip.src, 804 + ntohs(ent->dst.src_port), 805 + &ent->dst.ip.dst, 806 + ntohs(ent->dst.dst_port), 807 + ent->rateinfo.credit, ent->rateinfo.credit_cap, 808 + ent->rateinfo.cost); 808 809 break; 809 810 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES) 810 811 case NFPROTO_IPV6: 811 - res = seq_printf(s, "%ld %pI6:%u->%pI6:%u %u %u %u\n", 812 - (long)(ent->expires - jiffies)/HZ, 813 - &ent->dst.ip6.src, 814 - ntohs(ent->dst.src_port), 815 - &ent->dst.ip6.dst, 816 - ntohs(ent->dst.dst_port), 817 - ent->rateinfo.credit, ent->rateinfo.credit_cap, 818 - ent->rateinfo.cost); 812 + seq_printf(s, "%ld %pI6:%u->%pI6:%u %u %u %u\n", 813 + (long)(ent->expires - jiffies)/HZ, 814 + &ent->dst.ip6.src, 815 + ntohs(ent->dst.src_port), 816 + &ent->dst.ip6.dst, 817 + ntohs(ent->dst.dst_port), 818 + ent->rateinfo.credit, ent->rateinfo.credit_cap, 819 + ent->rateinfo.cost); 819 820 break; 820 821 #endif 821 822 default: 822 823 BUG(); 823 - res = 0; 824 824 } 825 825 spin_unlock(&ent->lock); 826 - return res; 826 + return seq_has_overflowed(s); 827 827 } 828 828 829 829 static int dl_seq_show(struct seq_file *s, void *v)