Skip to content

Commit

Permalink
[TIPC]: Enhancements to message header writing
Browse files Browse the repository at this point in the history
This patch makes two enhancements to the routine used to
set bit fields within a TIPC message header:

 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: David S. Miller <davem@davemloft.net>
  • Loading branch information
Allan Stephens authored and David S. Miller committed Mar 6, 2008
1 parent 3769542 commit c0cb7ef
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions net/tipc/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ static inline void msg_set_bits(struct tipc_msg *m, u32 w,
u32 pos, u32 mask, u32 val)
{
val = (val & mask) << pos;
m->hdr[w] &= ~htonl(mask << pos);
m->hdr[w] |= htonl(val);
val = htonl(val);
mask = htonl(mask << pos);
m->hdr[w] &= ~mask;
m->hdr[w] |= val;
}

/*
Expand Down

0 comments on commit c0cb7ef

Please sign in to comment.