diff options
author | David Laight <David.Laight@ACULAB.COM> | 2014-07-04 10:35:57 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-07-08 17:39:00 -0400 |
commit | d1a3fe26e97c0f17579c39f8a446c50f7cc3154a (patch) | |
tree | 8f30dc91827100ae42c0a90edc9cb00bb0fa56b4 | |
parent | b9420e1c87838bcb354ae3495852430413dd9e4b (diff) |
net: sctp: Use pointers (not array indexes) to access sctp_cmd_seq_t.cmds[].
Using pointers into sctp_cmd_seq_t.cmds[] lets the compiler generate much
better code.
Use the last entry first to optimise the overflow check.
Signed-off-by: David Laight <david.laight@aculab.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/sctp/command.h | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/include/net/sctp/command.h b/include/net/sctp/command.h index 589a1918ad55..f22538e68245 100644 --- a/include/net/sctp/command.h +++ b/include/net/sctp/command.h | |||
@@ -203,8 +203,8 @@ typedef struct { | |||
203 | 203 | ||
204 | typedef struct { | 204 | typedef struct { |
205 | sctp_cmd_t cmds[SCTP_MAX_NUM_COMMANDS]; | 205 | sctp_cmd_t cmds[SCTP_MAX_NUM_COMMANDS]; |
206 | __u8 next_free_slot; | 206 | sctp_cmd_t *last_used_slot; |
207 | __u8 next_cmd; | 207 | sctp_cmd_t *next_cmd; |
208 | } sctp_cmd_seq_t; | 208 | } sctp_cmd_seq_t; |
209 | 209 | ||
210 | 210 | ||
@@ -213,8 +213,9 @@ typedef struct { | |||
213 | */ | 213 | */ |
214 | static inline int sctp_init_cmd_seq(sctp_cmd_seq_t *seq) | 214 | static inline int sctp_init_cmd_seq(sctp_cmd_seq_t *seq) |
215 | { | 215 | { |
216 | seq->next_free_slot = 0; | 216 | /* cmds[] is filled backwards to simplify the overflow BUG() check */ |
217 | seq->next_cmd = 0; | 217 | seq->last_used_slot = seq->cmds + SCTP_MAX_NUM_COMMANDS; |
218 | seq->next_cmd = seq->last_used_slot; | ||
218 | return 1; /* We always succeed. */ | 219 | return 1; /* We always succeed. */ |
219 | } | 220 | } |
220 | 221 | ||
@@ -227,10 +228,13 @@ static inline int sctp_init_cmd_seq(sctp_cmd_seq_t *seq) | |||
227 | static inline void sctp_add_cmd_sf(sctp_cmd_seq_t *seq, sctp_verb_t verb, | 228 | static inline void sctp_add_cmd_sf(sctp_cmd_seq_t *seq, sctp_verb_t verb, |
228 | sctp_arg_t obj) | 229 | sctp_arg_t obj) |
229 | { | 230 | { |
230 | BUG_ON(seq->next_free_slot >= SCTP_MAX_NUM_COMMANDS); | 231 | sctp_cmd_t *cmd = seq->last_used_slot - 1; |
231 | 232 | ||
232 | seq->cmds[seq->next_free_slot].verb = verb; | 233 | BUG_ON(cmd < seq->cmds); |
233 | seq->cmds[seq->next_free_slot++].obj = obj; | 234 | |
235 | cmd->verb = verb; | ||
236 | cmd->obj = obj; | ||
237 | seq->last_used_slot = cmd; | ||
234 | } | 238 | } |
235 | 239 | ||
236 | /* Return the next command structure in an sctp_cmd_seq. | 240 | /* Return the next command structure in an sctp_cmd_seq. |
@@ -238,12 +242,10 @@ static inline void sctp_add_cmd_sf(sctp_cmd_seq_t *seq, sctp_verb_t verb, | |||
238 | */ | 242 | */ |
239 | static inline sctp_cmd_t *sctp_next_cmd(sctp_cmd_seq_t *seq) | 243 | static inline sctp_cmd_t *sctp_next_cmd(sctp_cmd_seq_t *seq) |
240 | { | 244 | { |
241 | sctp_cmd_t *retval = NULL; | 245 | if (seq->next_cmd <= seq->last_used_slot) |
242 | 246 | return NULL; | |
243 | if (seq->next_cmd < seq->next_free_slot) | ||
244 | retval = &seq->cmds[seq->next_cmd++]; | ||
245 | 247 | ||
246 | return retval; | 248 | return --seq->next_cmd; |
247 | } | 249 | } |
248 | 250 | ||
249 | #endif /* __net_sctp_command_h__ */ | 251 | #endif /* __net_sctp_command_h__ */ |