Message ID | 1289373771.2700.110.camel@edumazet-laptop |
---|---|
State | Accepted, archived |
Delegated to: | David Miller |
Headers | show |
Just I thought... > unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int flen) > { > struct sock_filter *fentry; /* We walk down these */ Can't this be "const struct sock_filter *"? > (...snipped...) > for (pc = 0; pc < flen; pc++) { > fentry = &filter[pc]; Can't we do u32 f_k = fentry->k; and replace 27 repetition of fentry->k with f_k? -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Date: Wed, 10 Nov 2010 23:25:08 +0900 > Just I thought... > >> unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int flen) >> { >> struct sock_filter *fentry; /* We walk down these */ > Can't this be "const struct sock_filter *"? >> (...snipped...) >> for (pc = 0; pc < flen; pc++) { >> fentry = &filter[pc]; > Can't we do > u32 f_k = fentry->k; > and replace 27 repetition of fentry->k with f_k? Yes, this feedback seems reasonable, I'll make these changes when I apply Eric's patch, thanks! -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/net/core/filter.c b/net/core/filter.c index 7beaec3..4d84dc2 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -117,10 +117,12 @@ unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int u32 A = 0; /* Accumulator */ u32 X = 0; /* Index Register */ u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */ + unsigned long memvalid = 0; u32 tmp; int k; int pc; + BUILD_BUG_ON(BPF_MEMWORDS > BITS_PER_LONG); /* * Process array of filter instructions. */ @@ -264,10 +266,12 @@ load_b: X = fentry->k; continue; case BPF_S_LD_MEM: - A = mem[fentry->k]; + A = (memvalid & (1UL << fentry->k)) ? + mem[fentry->k] : 0; continue; case BPF_S_LDX_MEM: - X = mem[fentry->k]; + X = (memvalid & (1UL << fentry->k)) ? + mem[fentry->k] : 0; continue; case BPF_S_MISC_TAX: X = A; @@ -280,9 +284,11 @@ load_b: case BPF_S_RET_A: return A; case BPF_S_ST: + memvalid |= 1UL << fentry->k; mem[fentry->k] = A; continue; case BPF_S_STX: + memvalid |= 1UL << fentry->k; mem[fentry->k] = X; continue; default: