: Enhancements to msg_set_bits() routine
Subsystems (3)
PATCH 1/1 : 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.
Apply the attached patch, or pull from:
git://tipc.cslab.ericsson.net/pub/git/tipc.git
(rebased on linux/kernel/git/davem/net-2.6.git)
Summary:
net/tipc/msg.h | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
///Jon
Quoted 1 line
From
1c3c79c4c79aa8a665ddf41c08b4363cbb946950Mon Sep 17 00:00:00 2001
From: Jon Paul Maloy <[email protected]>
Date: Mon, 23 Apr 2007 11:49:07 -0400
Subject: [PATCH 1/1] [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.
--- net/tipc/msg.h | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
net/tipc/msg.h +7 -4
@@ -1,8 +1,8 @@/* * net/tipc/msg.h: Include file for TIPC message header routines * -* Copyright (c) 2000-2006, Ericsson AB -* Copyright (c) 2005, Wind River Systems +* Copyright (c) 2000-2007, Ericsson AB +* Copyright (c) 2005-2007, Wind River Systems * All rights reserved. * * 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)static inline void msg_set_bits (struct tipc_msg *m,u32 w,u32 pos,u32 mask,u32 val) { -u32 word =msg_word (m,w) & ~(mask << pos); -msg_set_word (m, w, (word |= (val << pos))); + val = (val & mask) << pos; + val =htonl (val); + mask =htonl (mask << pos); + m->hdr[w] &= ~mask; + m->hdr[w] |= val; }/*
Signature · 1 line
1.5.0.5
From: Jon Paul Maloy <[email protected]>
Date: Tue, 24 Apr 2007 13:21:40 -0400
Quoted 1 line
This patch makes two enhancements to
msg_set_bits():
Applied, thanks a lot.