b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Use kernel facilities for bit operations
Date: Sun, 12 Dec 2010 21:39:11 +0100	[thread overview]
Message-ID: <1292186352-24624-1-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <201012122136.48156.sven@narfation.org>

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@narfation.org>
---
 batman-adv/bitarray.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/batman-adv/bitarray.c b/batman-adv/bitarray.c
index 814274f..5dad5e8 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. */
-- 
1.7.2.3


  reply	other threads:[~2010-12-12 20:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-01 19:59 [B.A.T.M.A.N.] [PATCH] batman-adv: Use kernel facilities for bit operations Sven Eckelmann
2010-12-12 19:29 ` Marek Lindner
2010-12-12 20:33   ` Marek Lindner
2010-12-12 20:43     ` Sven Eckelmann
2010-12-12 20:46       ` [B.A.T.M.A.N.] [PATCHv3 1/2] batman-adv: Remove line over 80 characters Sven Eckelmann
2010-12-12 21:57         ` Marek Lindner
2010-12-12 20:46       ` [B.A.T.M.A.N.] [PATCHv3 2/2] batman-adv: Remove TYPE_OF_WORD define Sven Eckelmann
2010-12-12 21:58         ` Marek Lindner
2010-12-12 20:36   ` [B.A.T.M.A.N.] [PATCH] batman-adv: Use kernel facilities for bit operations Sven Eckelmann
2010-12-12 20:39     ` Sven Eckelmann [this message]
2010-12-12 20:39     ` [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: Remove TYPE_OF_WORD define Sven Eckelmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1292186352-24624-1-git-send-email-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).