diff options
author | Allan Stephens <allan.stephens@windriver.com> | 2007-04-24 17:51:55 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-04-26 01:29:49 -0400 |
commit | 1f9eda7e2b67898fb8e79b3aa3880211b51235e6 (patch) | |
tree | 4c8facf142531621f69b3b6c42e3370e94897260 | |
parent | 43fb45cb79e9441a79ece206cf741774500dd627 (diff) |
[TIPC]: Enhancements to msg_set_bits() routine
This patch makes two enhancements to msg_set_bits():
1) It now ignores any bits of the new field value that are not
covered by the mask being used. (Previously, if the new value
exceeded the size of the mask the extra bits could corrupt
other fields in the message header word being updated.)
2) The code has been optimized to minimize the number of run-time
endianness conversion operations by leveraging the fact that the
mask (and, in some cases, the value as well) is constant and the
necessary conversion can be performed by the compiler.
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Jon Paul Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/tipc/msg.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/net/tipc/msg.h b/net/tipc/msg.h index aec7ce7af875..35d5ba1d4f42 100644 --- a/net/tipc/msg.h +++ b/net/tipc/msg.h | |||
@@ -1,8 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/msg.h: Include file for TIPC message header routines | 2 | * net/tipc/msg.h: Include file for TIPC message header routines |
3 | * | 3 | * |
4 | * Copyright (c) 2000-2006, Ericsson AB | 4 | * Copyright (c) 2000-2007, Ericsson AB |
5 | * Copyright (c) 2005, Wind River Systems | 5 | * Copyright (c) 2005-2007, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
@@ -71,8 +71,11 @@ static inline void msg_set_word(struct tipc_msg *m, u32 w, u32 val) | |||
71 | static inline void msg_set_bits(struct tipc_msg *m, u32 w, | 71 | static inline void msg_set_bits(struct tipc_msg *m, u32 w, |
72 | u32 pos, u32 mask, u32 val) | 72 | u32 pos, u32 mask, u32 val) |
73 | { | 73 | { |
74 | u32 word = msg_word(m,w) & ~(mask << pos); | 74 | val = (val & mask) << pos; |
75 | msg_set_word(m, w, (word |= (val << pos))); | 75 | val = htonl(val); |
76 | mask = htonl(mask << pos); | ||
77 | m->hdr[w] &= ~mask; | ||
78 | m->hdr[w] |= val; | ||
76 | } | 79 | } |
77 | 80 | ||
78 | /* | 81 | /* |