This patch is a largely cosmetic cleanup of the TIPC reference
table code. Variable naming has been made more consistent,
useless #includes have been eliminated, and the object reference
field in each table entry is no longer implemented using an
unnecessary structure union. In addition, error checking has
been enhanced to detect accidental access to reference table
entries that are on the free list.
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
---
net/tipc/ref.c | 80 +++++++++++++++++++++++--------------------------------
1 files changed, 34 insertions(+), 46 deletions(-)
diff --git a/net/tipc/ref.c b/net/tipc/ref.c
index 75cfb8d..b7ef559 100644
--- a/net/tipc/ref.c
+++ b/net/tipc/ref.c
@@ -36,30 +36,18 @@
#include "core.h"
#include "ref.h"
-#include "port.h"
-#include "subscr.h"
-#include "name_distr.h"
-#include "name_table.h"
-#include "config.h"
-#include "discover.h"
-#include "bearer.h"
-#include "node.h"
-#include "bcast.h"
/**
* struct reference - TIPC object reference entry
* @object: pointer to object associated with reference entry
* @lock: spinlock controlling access to object
- * @data: reference value for object (combines instance & array index info)
+ * @ref: reference value for object (combines instance & array index info)
*/
struct reference {
void *object;
spinlock_t lock;
- union {
- u32 next_plus_upper;
- u32 reference;
- } data;
+ u32 ref;
};
/**
@@ -163,7 +151,7 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
u32 index;
u32 index_mask;
u32 next_plus_upper;
- u32 reference;
+ u32 ref;
if (unlikely(object == NULL)) {
err("Attempt to acquire reference to non-existent object\n");
@@ -183,10 +171,10 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
index_mask = tipc_ref_table.index_mask;
/* take lock in case a previous user of entry still holds it */
spin_lock_bh(&entry->lock);
- next_plus_upper = entry->data.next_plus_upper;
+ next_plus_upper = entry->ref;
tipc_ref_table.first_free = next_plus_upper & index_mask;
- reference = (next_plus_upper & ~index_mask) + index;
- entry->data.reference = reference;
+ ref = (next_plus_upper & ~index_mask) + index;
+ entry->ref = ref;
entry->object = object;
spin_unlock_bh(&entry->lock);
*lock = &entry->lock;
@@ -195,17 +183,17 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
index = tipc_ref_table.init_point++;
entry = &(tipc_ref_table.entries[index]);
spin_lock_init(&entry->lock);
- reference = tipc_ref_table.start_mask + index;
- entry->data.reference = reference;
+ ref = tipc_ref_table.start_mask + index;
+ entry->ref = ref;
entry->object = object;
*lock = &entry->lock;
}
else {
- reference = 0;
+ ref = 0;
}
write_unlock_bh(&ref_table_lock);
- return reference;
+ return ref;
}
/**
@@ -236,26 +224,25 @@ void tipc_ref_discard(u32 ref)
err("Attempt to discard reference to non-existent object\n");
goto exit;
}
- if (unlikely(entry->data.reference != ref)) {
+ if (unlikely(entry->ref != ref)) {
err("Attempt to discard non-existent reference\n");
goto exit;
}
/*
- * mark entry as unused; increment upper bits of entry's data field
+ * mark entry as unused; increment instance part of entry's reference
* to invalidate any subsequent references
*/
entry->object = NULL;
- entry->data.next_plus_upper = (ref & ~index_mask) + (index_mask + 1);
+ entry->ref = (ref & ~index_mask) + (index_mask + 1);
/* append entry to free entry list */
if (tipc_ref_table.first_free == 0)
tipc_ref_table.first_free = index;
else
- tipc_ref_table.entries[tipc_ref_table.last_free].
- data.next_plus_upper |= index;
+ tipc_ref_table.entries[tipc_ref_table.last_free].ref |= index;
tipc_ref_table.last_free = index;
exit:
@@ -269,15 +256,16 @@ exit:
void *tipc_ref_lock(u32 ref)
{
if (likely(tipc_ref_table.entries != NULL)) {
- struct reference *r;
-
- r = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask];
-
- if (likely(r->data.reference != 0)) {
- spin_lock_bh(&r->lock);
- if (likely(r->data.reference == ref))
- return r->object;
- spin_unlock_bh(&r->lock);
+ struct reference *entry;
+
+ entry = &tipc_ref_table.entries[ref &
+ tipc_ref_table.index_mask];
+ if (likely(entry->ref != 0)) {
+ spin_lock_bh(&entry->lock);
+ if (likely((entry->ref == ref) &&
+ (entry->object != NULL)))
+ return entry->object;
+ spin_unlock_bh(&entry->lock);
}
}
return NULL;
@@ -290,13 +278,12 @@ void *tipc_ref_lock(u32 ref)
void tipc_ref_unlock(u32 ref)
{
if (likely(tipc_ref_table.entries != NULL)) {
- struct reference *r;
-
- r = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask];
+ struct reference *entry;
- if (likely((r->data.reference == ref) &&
- (r->data.reference != 0)))
- spin_unlock_bh(&r->lock);
+ entry = &tipc_ref_table.entries[ref &
+ tipc_ref_table.index_mask];
+ if (likely((entry->ref == ref) && (entry->object != NULL)))
+ spin_unlock_bh(&entry->lock);
else
err("tipc_ref_unlock() invoked using "
"invalid reference\n");
@@ -310,11 +297,12 @@ void tipc_ref_unlock(u32 ref)
void *tipc_ref_deref(u32 ref)
{
if (likely(tipc_ref_table.entries != NULL)) {
- struct reference *r;
+ struct reference *entry;
- r = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask];
- if (likely(r->data.reference == ref))
- return r->object;
+ entry = &tipc_ref_table.entries[ref &
+ tipc_ref_table.index_mask];
+ if (likely(entry->ref == ref))
+ return entry->object;
}
return NULL;
}
--
1.5.3.2
--
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
| Karl Meyer | PROBLEM: 2.6.23-rc "NETDEV WATCHDOG: eth0: transmit timed out" |
| David Miller | Slow DOWN, please!!! |
| Mark Fasheh | [PATCH 0/39] Ocfs2 updates for 2.6.28 |
| Bart Van Assche | Integration of SCST in the mainstream Linux kernel |
git: | |
| Shawn O. Pearce | Re: pack operation is thrashing my server |
| Pierre Habouzit | git send-email improvements |
| Matthieu Moy | git push to a non-bare repository |
| Shawn O. Pearce | libgit2 - a true git library |
| Elad Efrat | Integrating securelevel and kauth(9) |
| Hubert Feyrer | Re: Compressed vnd handling tested successfully |
| Lord Isildur | Re: Fork bomb protection patch |
| Matt Thomas | Re: FFS journal |
| Will Maier | cron doesn't run commands in /etc/crontab? |
| Richard Stallman | Real men don't attack straw men |
| Harald Dunkel | Re: Packet Filter: how to keep device names on hardware failure? |
| Jordi Espasa Clofent | Resolving dependencies with pkg_add |
| Question on swap as ramdisk partition | 1 hour ago | Linux kernel |
| Netfilter kernel module | 11 hours ago | Linux kernel |
| serial driver xmit problem | 14 hours ago | Linux kernel |
| Why Windows is better than Linux | 14 hours ago | Linux general |
| How can I see my kernel messages in vt12? | 21 hours ago | Linux kernel |
| Grub | 1 day ago | Linux general |
| vmalloc_fault handling in x86_64 | 1 day ago | Linux kernel |
| epoll_wait()ing on epoll FD | 1 day ago | Linux kernel |
| Framebuffer in x86_64 causes problems to multiseat | 1 day ago | Linux kernel |
| Difference between 2.4 and 2.6 regarding thread creation | 2 days ago | Linux general |
