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

Bluetooth: clean up hci code

Do not use assignment in IF condition, remove extra spaces,
fixing typos, simplify code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@nokia.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>

authored by

Andrei Emeltchenko and committed by
Gustavo F. Padovan
70f23020 894718a6

+82 -50
+2 -2
include/net/bluetooth/hci.h
··· 489 489 490 490 #define HCI_OP_WRITE_PG_TIMEOUT 0x0c18 491 491 492 - #define HCI_OP_WRITE_SCAN_ENABLE 0x0c1a 492 + #define HCI_OP_WRITE_SCAN_ENABLE 0x0c1a 493 493 #define SCAN_DISABLED 0x00 494 494 #define SCAN_INQUIRY 0x01 495 495 #define SCAN_PAGE 0x02 ··· 874 874 875 875 struct hci_command_hdr { 876 876 __le16 opcode; /* OCF & OGF */ 877 - __u8 plen; 877 + __u8 plen; 878 878 } __packed; 879 879 880 880 struct hci_event_hdr {
+7 -7
include/net/bluetooth/hci_core.h
··· 44 44 }; 45 45 46 46 struct inquiry_entry { 47 - struct inquiry_entry *next; 47 + struct inquiry_entry *next; 48 48 __u32 timestamp; 49 49 struct inquiry_data data; 50 50 }; 51 51 52 52 struct inquiry_cache { 53 - spinlock_t lock; 53 + spinlock_t lock; 54 54 __u32 timestamp; 55 - struct inquiry_entry *list; 55 + struct inquiry_entry *list; 56 56 }; 57 57 58 58 struct hci_conn_hash { ··· 141 141 void *driver_data; 142 142 void *core_data; 143 143 144 - atomic_t promisc; 144 + atomic_t promisc; 145 145 146 146 struct dentry *debugfs; 147 147 ··· 150 150 151 151 struct rfkill *rfkill; 152 152 153 - struct module *owner; 153 + struct module *owner; 154 154 155 155 int (*open)(struct hci_dev *hdev); 156 156 int (*close)(struct hci_dev *hdev); ··· 215 215 extern rwlock_t hci_cb_list_lock; 216 216 217 217 /* ----- Inquiry cache ----- */ 218 - #define INQUIRY_CACHE_AGE_MAX (HZ*30) // 30 seconds 219 - #define INQUIRY_ENTRY_AGE_MAX (HZ*60) // 60 seconds 218 + #define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */ 219 + #define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */ 220 220 221 221 #define inquiry_cache_lock(c) spin_lock(&c->lock) 222 222 #define inquiry_cache_unlock(c) spin_unlock(&c->lock)
+15 -8
net/bluetooth/hci_conn.c
··· 39 39 #include <net/sock.h> 40 40 41 41 #include <asm/system.h> 42 - #include <asm/uaccess.h> 42 + #include <linux/uaccess.h> 43 43 #include <asm/unaligned.h> 44 44 45 45 #include <net/bluetooth/bluetooth.h> ··· 66 66 bacpy(&cp.bdaddr, &conn->dst); 67 67 cp.pscan_rep_mode = 0x02; 68 68 69 - if ((ie = hci_inquiry_cache_lookup(hdev, &conn->dst))) { 69 + ie = hci_inquiry_cache_lookup(hdev, &conn->dst); 70 + if (ie) { 70 71 if (inquiry_entry_age(ie) <= INQUIRY_ENTRY_AGE_MAX) { 71 72 cp.pscan_rep_mode = ie->data.pscan_rep_mode; 72 73 cp.pscan_mode = ie->data.pscan_mode; ··· 369 368 370 369 BT_DBG("%s dst %s", hdev->name, batostr(dst)); 371 370 372 - if (!(acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst))) { 373 - if (!(acl = hci_conn_add(hdev, ACL_LINK, dst))) 371 + acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst); 372 + if (!acl) { 373 + acl = hci_conn_add(hdev, ACL_LINK, dst); 374 + if (!acl) 374 375 return NULL; 375 376 } 376 377 ··· 392 389 if (type == ACL_LINK) 393 390 return acl; 394 391 395 - if (!(sco = hci_conn_hash_lookup_ba(hdev, type, dst))) { 396 - if (!(sco = hci_conn_add(hdev, type, dst))) { 392 + sco = hci_conn_hash_lookup_ba(hdev, type, dst); 393 + if (!sco) { 394 + sco = hci_conn_add(hdev, type, dst); 395 + if (!sco) { 397 396 hci_conn_put(acl); 398 397 return NULL; 399 398 } ··· 652 647 653 648 size = sizeof(req) + req.conn_num * sizeof(*ci); 654 649 655 - if (!(cl = kmalloc(size, GFP_KERNEL))) 650 + cl = kmalloc(size, GFP_KERNEL); 651 + if (!cl) 656 652 return -ENOMEM; 657 653 658 - if (!(hdev = hci_dev_get(req.dev_id))) { 654 + hdev = hci_dev_get(req.dev_id); 655 + if (!hdev) { 659 656 kfree(cl); 660 657 return -ENODEV; 661 658 }
+42 -24
net/bluetooth/hci_core.c
··· 44 44 #include <net/sock.h> 45 45 46 46 #include <asm/system.h> 47 - #include <asm/uaccess.h> 47 + #include <linux/uaccess.h> 48 48 #include <asm/unaligned.h> 49 49 50 50 #include <net/bluetooth/bluetooth.h> ··· 349 349 void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data) 350 350 { 351 351 struct inquiry_cache *cache = &hdev->inq_cache; 352 - struct inquiry_entry *e; 352 + struct inquiry_entry *ie; 353 353 354 354 BT_DBG("cache %p, %s", cache, batostr(&data->bdaddr)); 355 355 356 - if (!(e = hci_inquiry_cache_lookup(hdev, &data->bdaddr))) { 356 + ie = hci_inquiry_cache_lookup(hdev, &data->bdaddr); 357 + if (!ie) { 357 358 /* Entry not in the cache. Add new one. */ 358 - if (!(e = kzalloc(sizeof(struct inquiry_entry), GFP_ATOMIC))) 359 + ie = kzalloc(sizeof(struct inquiry_entry), GFP_ATOMIC); 360 + if (!ie) 359 361 return; 360 - e->next = cache->list; 361 - cache->list = e; 362 + 363 + ie->next = cache->list; 364 + cache->list = ie; 362 365 } 363 366 364 - memcpy(&e->data, data, sizeof(*data)); 365 - e->timestamp = jiffies; 367 + memcpy(&ie->data, data, sizeof(*data)); 368 + ie->timestamp = jiffies; 366 369 cache->timestamp = jiffies; 367 370 } 368 371 ··· 425 422 426 423 hci_dev_lock_bh(hdev); 427 424 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || 428 - inquiry_cache_empty(hdev) || 429 - ir.flags & IREQ_CACHE_FLUSH) { 425 + inquiry_cache_empty(hdev) || 426 + ir.flags & IREQ_CACHE_FLUSH) { 430 427 inquiry_cache_flush(hdev); 431 428 do_inquiry = 1; 432 429 } 433 430 hci_dev_unlock_bh(hdev); 434 431 435 432 timeo = ir.length * msecs_to_jiffies(2000); 436 - if (do_inquiry && (err = hci_request(hdev, hci_inq_req, (unsigned long)&ir, timeo)) < 0) 437 - goto done; 433 + 434 + if (do_inquiry) { 435 + err = hci_request(hdev, hci_inq_req, (unsigned long)&ir, timeo); 436 + if (err < 0) 437 + goto done; 438 + } 438 439 439 440 /* for unlimited number of responses we will use buffer with 255 entries */ 440 441 max_rsp = (ir.num_rsp == 0) ? 255 : ir.num_rsp; ··· 446 439 /* cache_dump can't sleep. Therefore we allocate temp buffer and then 447 440 * copy it to the user space. 448 441 */ 449 - if (!(buf = kmalloc(sizeof(struct inquiry_info) * max_rsp, GFP_KERNEL))) { 442 + buf = kmalloc(sizeof(struct inquiry_info) *max_rsp, GFP_KERNEL); 443 + if (!buf) { 450 444 err = -ENOMEM; 451 445 goto done; 452 446 } ··· 619 611 struct hci_dev *hdev; 620 612 int err; 621 613 622 - if (!(hdev = hci_dev_get(dev))) 614 + hdev = hci_dev_get(dev); 615 + if (!hdev) 623 616 return -ENODEV; 624 617 err = hci_dev_do_close(hdev); 625 618 hci_dev_put(hdev); ··· 632 623 struct hci_dev *hdev; 633 624 int ret = 0; 634 625 635 - if (!(hdev = hci_dev_get(dev))) 626 + hdev = hci_dev_get(dev); 627 + if (!hdev) 636 628 return -ENODEV; 637 629 638 630 hci_req_lock(hdev); ··· 673 663 struct hci_dev *hdev; 674 664 int ret = 0; 675 665 676 - if (!(hdev = hci_dev_get(dev))) 666 + hdev = hci_dev_get(dev); 667 + if (!hdev) 677 668 return -ENODEV; 678 669 679 670 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats)); ··· 693 682 if (copy_from_user(&dr, arg, sizeof(dr))) 694 683 return -EFAULT; 695 684 696 - if (!(hdev = hci_dev_get(dr.dev_id))) 685 + hdev = hci_dev_get(dr.dev_id); 686 + if (!hdev) 697 687 return -ENODEV; 698 688 699 689 switch (cmd) { ··· 775 763 776 764 size = sizeof(*dl) + dev_num * sizeof(*dr); 777 765 778 - if (!(dl = kzalloc(size, GFP_KERNEL))) 766 + dl = kzalloc(size, GFP_KERNEL); 767 + if (!dl) 779 768 return -ENOMEM; 780 769 781 770 dr = dl->dev_req; ··· 810 797 if (copy_from_user(&di, arg, sizeof(di))) 811 798 return -EFAULT; 812 799 813 - if (!(hdev = hci_dev_get(di.dev_id))) 800 + hdev = hci_dev_get(di.dev_id); 801 + if (!hdev) 814 802 return -ENODEV; 815 803 816 804 strcpy(di.name, hdev->name); ··· 919 905 hdev->sniff_max_interval = 800; 920 906 hdev->sniff_min_interval = 80; 921 907 922 - tasklet_init(&hdev->cmd_task, hci_cmd_task,(unsigned long) hdev); 908 + tasklet_init(&hdev->cmd_task, hci_cmd_task, (unsigned long) hdev); 923 909 tasklet_init(&hdev->rx_task, hci_rx_task, (unsigned long) hdev); 924 910 tasklet_init(&hdev->tx_task, hci_tx_task, (unsigned long) hdev); 925 911 ··· 1382 1368 bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT; 1383 1369 hci_add_acl_hdr(skb, conn->handle, flags | ACL_START); 1384 1370 1385 - if (!(list = skb_shinfo(skb)->frag_list)) { 1371 + list = skb_shinfo(skb)->frag_list; 1372 + if (!list) { 1386 1373 /* Non fragmented */ 1387 1374 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); 1388 1375 ··· 1624 1609 hci_conn_enter_active_mode(conn); 1625 1610 1626 1611 /* Send to upper protocol */ 1627 - if ((hp = hci_proto[HCI_PROTO_L2CAP]) && hp->recv_acldata) { 1612 + hp = hci_proto[HCI_PROTO_L2CAP]; 1613 + if (hp && hp->recv_acldata) { 1628 1614 hp->recv_acldata(conn, skb, flags); 1629 1615 return; 1630 1616 } ··· 1660 1644 register struct hci_proto *hp; 1661 1645 1662 1646 /* Send to upper protocol */ 1663 - if ((hp = hci_proto[HCI_PROTO_SCO]) && hp->recv_scodata) { 1647 + hp = hci_proto[HCI_PROTO_SCO]; 1648 + if (hp && hp->recv_scodata) { 1664 1649 hp->recv_scodata(conn, skb); 1665 1650 return; 1666 1651 } ··· 1744 1727 if (atomic_read(&hdev->cmd_cnt) && (skb = skb_dequeue(&hdev->cmd_q))) { 1745 1728 kfree_skb(hdev->sent_cmd); 1746 1729 1747 - if ((hdev->sent_cmd = skb_clone(skb, GFP_ATOMIC))) { 1730 + hdev->sent_cmd = skb_clone(skb, GFP_ATOMIC); 1731 + if (hdev->sent_cmd) { 1748 1732 atomic_dec(&hdev->cmd_cnt); 1749 1733 hci_send_frame(skb); 1750 1734 hdev->cmd_last_tx = jiffies;
+5 -3
net/bluetooth/hci_event.c
··· 39 39 #include <net/sock.h> 40 40 41 41 #include <asm/system.h> 42 - #include <asm/uaccess.h> 42 + #include <linux/uaccess.h> 43 43 #include <asm/unaligned.h> 44 44 45 45 #include <net/bluetooth/bluetooth.h> ··· 1512 1512 conn->sent -= count; 1513 1513 1514 1514 if (conn->type == ACL_LINK) { 1515 - if ((hdev->acl_cnt += count) > hdev->acl_pkts) 1515 + hdev->acl_cnt += count; 1516 + if (hdev->acl_cnt > hdev->acl_pkts) 1516 1517 hdev->acl_cnt = hdev->acl_pkts; 1517 1518 } else { 1518 - if ((hdev->sco_cnt += count) > hdev->sco_pkts) 1519 + hdev->sco_cnt += count; 1520 + if (hdev->sco_cnt > hdev->sco_pkts) 1519 1521 hdev->sco_cnt = hdev->sco_pkts; 1520 1522 } 1521 1523 }
+11 -6
net/bluetooth/hci_sock.c
··· 43 43 #include <net/sock.h> 44 44 45 45 #include <asm/system.h> 46 - #include <asm/uaccess.h> 46 + #include <linux/uaccess.h> 47 47 #include <asm/unaligned.h> 48 48 49 49 #include <net/bluetooth/bluetooth.h> ··· 125 125 continue; 126 126 } 127 127 128 - if (!(nskb = skb_clone(skb, GFP_ATOMIC))) 128 + nskb = skb_clone(skb, GFP_ATOMIC); 129 + if (!nskb) 129 130 continue; 130 131 131 132 /* Put type byte before the data */ ··· 371 370 } 372 371 373 372 if (haddr->hci_dev != HCI_DEV_NONE) { 374 - if (!(hdev = hci_dev_get(haddr->hci_dev))) { 373 + hdev = hci_dev_get(haddr->hci_dev); 374 + if (!hdev) { 375 375 err = -ENODEV; 376 376 goto done; 377 377 } ··· 459 457 if (sk->sk_state == BT_CLOSED) 460 458 return 0; 461 459 462 - if (!(skb = skb_recv_datagram(sk, flags, noblock, &err))) 460 + skb = skb_recv_datagram(sk, flags, noblock, &err); 461 + if (!skb) 463 462 return err; 464 463 465 464 msg->msg_namelen = 0; ··· 502 499 503 500 lock_sock(sk); 504 501 505 - if (!(hdev = hci_pi(sk)->hdev)) { 502 + hdev = hci_pi(sk)->hdev; 503 + if (!hdev) { 506 504 err = -EBADFD; 507 505 goto done; 508 506 } ··· 513 509 goto done; 514 510 } 515 511 516 - if (!(skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err))) 512 + skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err); 513 + if (!skb) 517 514 goto done; 518 515 519 516 if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) {