Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: Use static const, consolidate code

Using static const generally increases object text and decreases data size.
It also generally decreases overall object size.

Consolidate duplicated code into new fix_crc_bug function
and declare data in that function static const.

Signed-off-by: Joe Perches <joe@perches.com>

+16 -23
+16 -23
drivers/net/usb/hso.c
··· 997 997 } 998 998 } 999 999 1000 + static void fix_crc_bug(struct urb *urb, __le16 max_packet_size) 1001 + { 1002 + static const u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF }; 1003 + u32 rest = urb->actual_length % le16_to_cpu(max_packet_size); 1004 + 1005 + if (((rest == 5) || (rest == 6)) && 1006 + !memcmp(((u8 *)urb->transfer_buffer) + urb->actual_length - 4, 1007 + crc_check, 4)) { 1008 + urb->actual_length -= 4; 1009 + } 1010 + } 1011 + 1000 1012 /* Moving data from usb to kernel (in interrupt state) */ 1001 1013 static void read_bulk_callback(struct urb *urb) 1002 1014 { ··· 1037 1025 return; 1038 1026 } 1039 1027 1040 - if (odev->parent->port_spec & HSO_INFO_CRC_BUG) { 1041 - u32 rest; 1042 - u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF }; 1043 - rest = urb->actual_length % 1044 - le16_to_cpu(odev->in_endp->wMaxPacketSize); 1045 - if (((rest == 5) || (rest == 6)) && 1046 - !memcmp(((u8 *) urb->transfer_buffer) + 1047 - urb->actual_length - 4, crc_check, 4)) { 1048 - urb->actual_length -= 4; 1049 - } 1050 - } 1028 + if (odev->parent->port_spec & HSO_INFO_CRC_BUG) 1029 + fix_crc_bug(urb, odev->in_endp->wMaxPacketSize); 1051 1030 1052 1031 /* do we even have a packet? */ 1053 1032 if (urb->actual_length) { ··· 1230 1227 return; 1231 1228 1232 1229 if (status == 0) { 1233 - if (serial->parent->port_spec & HSO_INFO_CRC_BUG) { 1234 - u32 rest; 1235 - u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF }; 1236 - rest = 1237 - urb->actual_length % 1238 - le16_to_cpu(serial->in_endp->wMaxPacketSize); 1239 - if (((rest == 5) || (rest == 6)) && 1240 - !memcmp(((u8 *) urb->transfer_buffer) + 1241 - urb->actual_length - 4, crc_check, 4)) { 1242 - urb->actual_length -= 4; 1243 - } 1244 - } 1230 + if (serial->parent->port_spec & HSO_INFO_CRC_BUG) 1231 + fix_crc_bug(urb, serial->in_endp->wMaxPacketSize); 1245 1232 /* Valid data, handle RX data */ 1246 1233 spin_lock(&serial->serial_lock); 1247 1234 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 1;