bluetooth: remove private bitrev16 implementation
Subsystems (3)
PATCH 1/1 bluetooth: remove private bitrev16 implementation
Expose bitrev16 from lib/bitrev.c and use it.
Signed-off-by Harvey Harrison <[email protected]>
--- drivers/bluetooth/hci_bcsp.c | 28 ++++------------------------ include/linux/bitrev.h | 1 + lib/bitrev.c | 3 ++- 3 files changed, 7 insertions(+), 25 deletions(-)
drivers/bluetooth/hci_bcsp.c +4 -24
@@ -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 ]);
include/linux/bitrev.h +1 -0
@@ -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 */
lib/bitrev.c +2 -1
@@ -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
Signature · 1 line
1.5.6.rc0.336.ge5422
Marcel Holtmann
maintainerHi Harvey,
Quoted 1 line
Expose bitrev16 from
lib/bitrev.cand use it.
can you please split these into two patches. One that exports bitrev16 properly and the other one that fixes the Bluetooth driver.
Regards
Marcel
Quoted 7 lines · Marcel Holtmann
Hi Harvey,
Quoted 1 line
Expose bitrev16 from
lib/bitrev.cand use it.can you please split these into two patches. One that exports bitrev16 properly and the other one that fixes the Bluetooth driver.
I just sent you a second cleanup patch, I'll split this one and send a revised 3-patch series including the second cleanup patch.
Harvey