batman-adv: Use kernel facilities for bit operations

Message ID 1291233547-9437-1-git-send-email-sven.eckelmann@gmx.de (mailing list archive)
State Superseded, archived
Headers

Commit Message

Sven Eckelmann Dec. 1, 2010, 7:59 p.m. UTC
  set_bit and test_bit provide an efficient way to set and test bits of an
unsigned long.

This also fixes the problem that a very old ogm got not recorded as
received due to the missing constant definition "1" as unsigned long
inside the bit_mark operation - also known as "1UL".

Reported-by: David Miller <davem@davemloft.net>
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
 batman-adv/bitarray.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
  

Comments

Marek Lindner Dec. 12, 2010, 7:29 p.m. UTC | #1
On Wednesday 01 December 2010 20:59:07 Sven Eckelmann wrote:
> set_bit and test_bit provide an efficient way to set and test bits of an
> unsigned long.

Since test_bit() / set_bit() expect 32Bit values we should at least add a 
comment next to TYPE_OF_WORD, so that nobody changes this define ?!

Cheers,
Marek
  
Marek Lindner Dec. 12, 2010, 8:33 p.m. UTC | #2
On Sunday 12 December 2010 20:29:46 Marek Lindner wrote:
> On Wednesday 01 December 2010 20:59:07 Sven Eckelmann wrote:
> > set_bit and test_bit provide an efficient way to set and test bits of an
> > unsigned long.
> 
> Since test_bit() / set_bit() expect 32Bit values we should at least add a
> comment next to TYPE_OF_WORD, so that nobody changes this define ?!

I applied the patch including a comment in revision 1889.

Thanks,
Marek
  
Sven Eckelmann Dec. 12, 2010, 8:36 p.m. UTC | #3
Marek Lindner wrote:
> On Wednesday 01 December 2010 20:59:07 Sven Eckelmann wrote:
> > set_bit and test_bit provide an efficient way to set and test bits of an
> > unsigned long.
> 
> Since test_bit() / set_bit() expect 32Bit values we should at least add a
> comment next to TYPE_OF_WORD, so that nobody changes this define ?!

unsigned long is not always 32 bit.... I will send a patch which completely 
replaces TYPE_OF_WORD

Best regards,
	Sven
  
Sven Eckelmann Dec. 12, 2010, 8:43 p.m. UTC | #4
Marek Lindner wrote:
> On Sunday 12 December 2010 20:29:46 Marek Lindner wrote:
> > On Wednesday 01 December 2010 20:59:07 Sven Eckelmann wrote:
> > > set_bit and test_bit provide an efficient way to set and test bits of
> > > an unsigned long.
> > 
> > Since test_bit() / set_bit() expect 32Bit values we should at least add a
> > comment next to TYPE_OF_WORD, so that nobody changes this define ?!
> 
> I applied the patch including a comment in revision 1889.

Ok, since there were a race condition, please ignore the v2 version of the 
patches. v3 will be delivered in some minutes.

Best regards,
	Sven
  
Marek Lindner Dec. 12, 2010, 9:57 p.m. UTC | #5
On Sunday 12 December 2010 21:46:58 Sven Eckelmann wrote:
> "Use kernel facilities for bit operations" increased accidently the
> character count on a line to more than 80 characters when counting a tab
> as 8 characters.

Applied in revision 1893.

Thanks,
Marek
  

Patch

diff --git a/batman-adv/bitarray.c b/batman-adv/bitarray.c
index 814274f..14606fc 100644
--- a/batman-adv/bitarray.c
+++ b/batman-adv/bitarray.c
@@ -40,7 +40,7 @@  uint8_t get_bit_status(TYPE_OF_WORD *seq_bits, uint32_t last_seqno,
 		/* which position in the selected word */
 		word_offset = (last_seqno - curr_seqno) % WORD_BIT_SIZE;
 
-		if (seq_bits[word_num] & 1 << word_offset)
+		if (test_bit(word_offset, &seq_bits[word_num]))
 			return 1;
 		else
 			return 0;
@@ -61,7 +61,7 @@  void bit_mark(TYPE_OF_WORD *seq_bits, int32_t n)
 	/* which position in the selected word */
 	word_offset = n % WORD_BIT_SIZE;
 
-	seq_bits[word_num] |= 1 << word_offset;	/* turn the position on */
+	set_bit(word_offset, &seq_bits[word_num]);	/* turn the position on */
 }
 
 /* shift the packet array by n places. */