Commit 481af03b authored by Akinobu Mita's avatar Akinobu Mita Committed by David S. Miller

mISDN: improve bitops usage

This improves bitops usages in several points:

- Convert u64 to a proper bitmap declaration.  This enables to remove
  superfluous typecasting from 'u64' to 'unsigned long *'.

- Convert superfluous atomic bitops to non atomic bitops.  The bitmap
  is allocated on the stack and it is not accessed by any other threads,
  so using atomic bitops is not necessary.

- Use find_next_zero_bit and find_next_zero_bit instead of calling
  test_bit() for each bit.
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: netdev@vger.kernel.org
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6e22ce2c
...@@ -250,7 +250,7 @@ tei_debug(struct FsmInst *fi, char *fmt, ...) ...@@ -250,7 +250,7 @@ tei_debug(struct FsmInst *fi, char *fmt, ...)
static int static int
get_free_id(struct manager *mgr) get_free_id(struct manager *mgr)
{ {
u64 ids = 0; DECLARE_BITMAP(ids, 64) = { [0 ... BITS_TO_LONGS(64) - 1] = 0 };
int i; int i;
struct layer2 *l2; struct layer2 *l2;
...@@ -261,10 +261,10 @@ get_free_id(struct manager *mgr) ...@@ -261,10 +261,10 @@ get_free_id(struct manager *mgr)
__func__); __func__);
return -EBUSY; return -EBUSY;
} }
test_and_set_bit(l2->ch.nr, (u_long *)&ids); __set_bit(l2->ch.nr, ids);
} }
for (i = 1; i < 64; i++) i = find_next_zero_bit(ids, 64, 1);
if (!test_bit(i, (u_long *)&ids)) if (i < 64)
return i; return i;
printk(KERN_WARNING "%s: more as 63 layer2 for one device\n", printk(KERN_WARNING "%s: more as 63 layer2 for one device\n",
__func__); __func__);
...@@ -274,7 +274,7 @@ get_free_id(struct manager *mgr) ...@@ -274,7 +274,7 @@ get_free_id(struct manager *mgr)
static int static int
get_free_tei(struct manager *mgr) get_free_tei(struct manager *mgr)
{ {
u64 ids = 0; DECLARE_BITMAP(ids, 64) = { [0 ... BITS_TO_LONGS(64) - 1] = 0 };
int i; int i;
struct layer2 *l2; struct layer2 *l2;
...@@ -288,10 +288,10 @@ get_free_tei(struct manager *mgr) ...@@ -288,10 +288,10 @@ get_free_tei(struct manager *mgr)
continue; continue;
i -= 64; i -= 64;
test_and_set_bit(i, (u_long *)&ids); __set_bit(i, ids);
} }
for (i = 0; i < 64; i++) i = find_first_zero_bit(ids, 64);
if (!test_bit(i, (u_long *)&ids)) if (i < 64)
return i + 64; return i + 64;
printk(KERN_WARNING "%s: more as 63 dynamic tei for one device\n", printk(KERN_WARNING "%s: more as 63 dynamic tei for one device\n",
__func__); __func__);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment