[1/6] batman-adv: unify the three starting fields of the tt_local/global_entry structures

Message ID 1309879385-21224-2-git-send-email-ordex@autistici.org (mailing list archive)
State Rejected, archived
Headers

Commit Message

Antonio Quartulli July 5, 2011, 3:23 p.m. UTC
  Now the three starting fields of the tt_local/global_entry structures are
unified. This allows to write generalised functions that operate on the
flags and refcount field.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 types.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
  

Comments

Sven Eckelmann July 6, 2011, 7:31 a.m. UTC | #1
On Tuesday 05 July 2011 17:23:00 Antonio Quartulli wrote:
> Now the three starting fields of the tt_local/global_entry structures are
> unified. This allows to write generalised functions that operate on the
> flags and refcount field.
> 
> Signed-off-by: Antonio Quartulli <ordex@autistici.org>
> ---


Ehrm, this is wrong (or at least undefined behaviour). Please read C99 6.5.2.3 
point 5

Kind regards,
	Sven
  
Sven Eckelmann July 6, 2011, 7:43 a.m. UTC | #2
On Wednesday 06 July 2011 09:31:11 Sven Eckelmann wrote:
> On Tuesday 05 July 2011 17:23:00 Antonio Quartulli wrote:
> > Now the three starting fields of the tt_local/global_entry structures
> > are
> > unified. This allows to write generalised functions that operate on the
> > flags and refcount field.
> > 
> > Signed-off-by: Antonio Quartulli <ordex@autistici.org>
> > ---
> 
> Ehrm, this is wrong (or at least undefined behaviour). Please read C99
> 6.5.2.3 point 5

Found an extreme nice example [1] for you. Please read it together with the 
C99 paragraph mentioned above.

Kind regards,
	Sven

[1] 
http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2007-05/msg03192.html
  

Patch

diff --git a/types.h b/types.h
index 25bd1db..b32ae5a 100644
--- a/types.h
+++ b/types.h
@@ -223,20 +223,20 @@  struct socket_packet {
 
 struct tt_local_entry {
 	uint8_t addr[ETH_ALEN];
-	unsigned long last_seen;
 	uint16_t flags;
 	atomic_t refcount;
+	unsigned long last_seen;
 	struct rcu_head rcu;
 	struct hlist_node hash_entry;
 };
 
 struct tt_global_entry {
 	uint8_t addr[ETH_ALEN];
+	uint16_t flags; /* only TT_GLOBAL_ROAM is used */
+	atomic_t refcount;
 	struct orig_node *orig_node;
 	uint8_t ttvn;
-	uint16_t flags; /* only TT_GLOBAL_ROAM is used */
 	unsigned long roam_at; /* time at which TT_GLOBAL_ROAM was set */
-	atomic_t refcount;
 	struct rcu_head rcu;
 	struct hlist_node hash_entry; /* entry in the global table */
 };