]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
Bluetooth: Convert inquiry cache to use standard list types
authorJohan Hedberg <johan.hedberg@intel.com>
Tue, 3 Jan 2012 14:03:00 +0000 (16:03 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Mon, 13 Feb 2012 15:01:19 +0000 (17:01 +0200)
This makes it possible to use the convenience functions provided for
standard kernel list types and it also makes it easier to extend the use
of the cache for the management interface where e.g. name resolving
control will be needed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_core.c
net/bluetooth/hci_sysfs.c

index ea9231f4935feba9ebd791e4d12287cc24284fd6..91d1baf050772f5620e82a7b3dac6056eeecbb99 100644 (file)
@@ -44,14 +44,14 @@ struct inquiry_data {
 };
 
 struct inquiry_entry {
-       struct inquiry_entry    *next;
+       struct list_head        list;
        __u32                   timestamp;
        struct inquiry_data     data;
 };
 
 struct inquiry_cache {
+       struct list_head        list;
        __u32                   timestamp;
-       struct inquiry_entry    *list;
 };
 
 struct hci_conn_hash {
@@ -350,14 +350,12 @@ extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
 
 static inline void inquiry_cache_init(struct hci_dev *hdev)
 {
-       struct inquiry_cache *c = &hdev->inq_cache;
-       c->list = NULL;
+       INIT_LIST_HEAD(&hdev->inq_cache.list);
 }
 
 static inline int inquiry_cache_empty(struct hci_dev *hdev)
 {
-       struct inquiry_cache *c = &hdev->inq_cache;
-       return c->list == NULL;
+       return list_empty(&hdev->inq_cache.list);
 }
 
 static inline long inquiry_cache_age(struct hci_dev *hdev)
index 845da3ee56a0d3966bdeb5ab627ef3dc49c8dead..feeea4df25296ba7f0d7acbeb0e1c31dd3ac3de8 100644 (file)
@@ -357,15 +357,11 @@ struct hci_dev *hci_dev_get(int index)
 /* ---- Inquiry support ---- */
 static void inquiry_cache_flush(struct hci_dev *hdev)
 {
-       struct inquiry_cache *cache = &hdev->inq_cache;
-       struct inquiry_entry *next  = cache->list, *e;
-
-       BT_DBG("cache %p", cache);
+       struct inquiry_entry *p, *n;
 
-       cache->list = NULL;
-       while ((e = next)) {
-               next = e->next;
-               kfree(e);
+       list_for_each_entry_safe(p, n, &hdev->inq_cache.list, list) {
+               list_del(&p->list);
+               kfree(p);
        }
 }
 
@@ -376,10 +372,12 @@ struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, bdaddr_t *b
 
        BT_DBG("cache %p, %s", cache, batostr(bdaddr));
 
-       for (e = cache->list; e; e = e->next)
+       list_for_each_entry(e, &cache->list, list) {
                if (!bacmp(&e->data.bdaddr, bdaddr))
-                       break;
-       return e;
+                       return e;
+       }
+
+       return NULL;
 }
 
 void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data)
@@ -396,8 +394,7 @@ void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data)
                if (!ie)
                        return;
 
-               ie->next = cache->list;
-               cache->list = ie;
+               list_add(&ie->list, &cache->list);
        }
 
        memcpy(&ie->data, data, sizeof(*data));
@@ -412,15 +409,21 @@ static int inquiry_cache_dump(struct hci_dev *hdev, int num, __u8 *buf)
        struct inquiry_entry *e;
        int copied = 0;
 
-       for (e = cache->list; e && copied < num; e = e->next, copied++) {
+       list_for_each_entry(e, &cache->list, list) {
                struct inquiry_data *data = &e->data;
+
+               if (copied >= num)
+                       break;
+
                bacpy(&info->bdaddr, &data->bdaddr);
                info->pscan_rep_mode    = data->pscan_rep_mode;
                info->pscan_period_mode = data->pscan_period_mode;
                info->pscan_mode        = data->pscan_mode;
                memcpy(info->dev_class, data->dev_class, 3);
                info->clock_offset      = data->clock_offset;
+
                info++;
+               copied++;
        }
 
        BT_DBG("cache %p, copied %d", cache, copied);
index 52109561423514fcbd16e1c1895d2e9f7ee7a490..ed9cceeec7bea13cef19044eb35224f860e90041 100644 (file)
@@ -388,7 +388,7 @@ static int inquiry_cache_show(struct seq_file *f, void *p)
 
        hci_dev_lock(hdev);
 
-       for (e = cache->list; e; e = e->next) {
+       list_for_each_entry(e, &cache->list, list) {
                struct inquiry_data *data = &e->data;
                seq_printf(f, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
                           batostr(&data->bdaddr),