public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bluetooth: remove private bitrev16 implementation
@ 2008-06-03 17:55 Harvey Harrison
  2008-06-03 17:59 ` Marcel Holtmann
  0 siblings, 1 reply; 3+ messages in thread
From: Harvey Harrison @ 2008-06-03 17:55 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Marcel Holtmann, LKML

Expose bitrev16 from lib/bitrev.c and use it.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
 drivers/bluetooth/hci_bcsp.c |   28 ++++------------------------
 include/linux/bitrev.h       |    1 +
 lib/bitrev.c                 |    3 ++-
 3 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index 696f752..d8cd41b 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -39,6 +39,7 @@
 #include <linux/signal.h>
 #include <linux/ioctl.h>
 #include <linux/skbuff.h>
+#include <linux/bitrev.h>
 
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
@@ -124,27 +125,6 @@ static void bcsp_crc_update(u16 *crc, u8 d)
 	*crc = reg;
 }
 
-/*
-   Get reverse of generated crc
-
-   Implementation note
-        The crc generator (bcsp_crc_init() and bcsp_crc_update())
-        creates a reversed crc, so it needs to be swapped back before
-        being passed on.
-*/
-static u16 bcsp_crc_reverse(u16 crc)
-{
-	u16 b, rev;
-
-	for (b = 0, rev = 0; b < 16; b++) {
-		rev = rev << 1;
-		rev |= (crc & 1);
-		crc = crc >> 1;
-	}
-
-	return (rev);
-}
-
 /* ---- BCSP core ---- */
 
 static void bcsp_slip_msgdelim(struct sk_buff *skb)
@@ -296,7 +276,7 @@ static struct sk_buff *bcsp_prepare_pkt(struct bcsp_struct *bcsp, u8 *data,
 
 	/* Put CRC */
 	if (bcsp->use_crc) {
-		bcsp_txmsg_crc = bcsp_crc_reverse(bcsp_txmsg_crc);
+		bcsp_txmsg_crc = bitrev16(bcsp_txmsg_crc);
 		bcsp_slip_one_byte(nskb, (u8) ((bcsp_txmsg_crc >> 8) & 0x00ff));
 		bcsp_slip_one_byte(nskb, (u8) (bcsp_txmsg_crc & 0x00ff));
 	}
@@ -624,12 +604,12 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
 			continue;
 
 		case BCSP_W4_CRC:
-			if (bcsp_crc_reverse(bcsp->message_crc) !=
+			if (bitrev16(bcsp->message_crc) !=
 					(bcsp->rx_skb->data[bcsp->rx_skb->len - 2] << 8) +
 					bcsp->rx_skb->data[bcsp->rx_skb->len - 1]) {
 
 				BT_ERR ("Checksum failed: computed %04x received %04x",
-					bcsp_crc_reverse(bcsp->message_crc),
+					bitrev16(bcsp->message_crc),
 					(bcsp->rx_skb-> data[bcsp->rx_skb->len - 2] << 8) +
 					bcsp->rx_skb->data[bcsp->rx_skb->len - 1]);
 
diff --git a/include/linux/bitrev.h b/include/linux/bitrev.h
index 05e540d..7ffe03f 100644
--- a/include/linux/bitrev.h
+++ b/include/linux/bitrev.h
@@ -10,6 +10,7 @@ static inline u8 bitrev8(u8 byte)
 	return byte_rev_table[byte];
 }
 
+extern u16 bitrev16(u16 in);
 extern u32 bitrev32(u32 in);
 
 #endif /* _LINUX_BITREV_H */
diff --git a/lib/bitrev.c b/lib/bitrev.c
index 989aff7..3956203 100644
--- a/lib/bitrev.c
+++ b/lib/bitrev.c
@@ -42,10 +42,11 @@ const u8 byte_rev_table[256] = {
 };
 EXPORT_SYMBOL_GPL(byte_rev_table);
 
-static __always_inline u16 bitrev16(u16 x)
+u16 bitrev16(u16 x)
 {
 	return (bitrev8(x & 0xff) << 8) | bitrev8(x >> 8);
 }
+EXPORT_SYMBOL(bitrev16);
 
 /**
  * bitrev32 - reverse the order of bits in a u32 value
-- 
1.5.6.rc0.336.ge5422




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-06-03 18:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-03 17:55 [PATCH] bluetooth: remove private bitrev16 implementation Harvey Harrison
2008-06-03 17:59 ` Marcel Holtmann
2008-06-03 18:11   ` Harvey Harrison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox