aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-01-03 09:03:00 -0500
committerJohan Hedberg <johan.hedberg@intel.com>2012-02-13 10:01:19 -0500
commitb57c1a5646739bfc273245dc738f2f12a2d4d3ec (patch)
tree1311c1e412bceb3dc53487c3a71365a976c2ce39
parent12325280dfeba18164f9c47e226a40ab34e23ee7 (diff)
Bluetooth: Convert inquiry cache to use standard list types
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>
-rw-r--r--include/net/bluetooth/hci_core.h10
-rw-r--r--net/bluetooth/hci_core.c31
-rw-r--r--net/bluetooth/hci_sysfs.c2
3 files changed, 22 insertions, 21 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index ea9231f4935f..91d1baf05077 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -44,14 +44,14 @@ struct inquiry_data {
44}; 44};
45 45
46struct inquiry_entry { 46struct inquiry_entry {
47 struct inquiry_entry *next; 47 struct list_head list;
48 __u32 timestamp; 48 __u32 timestamp;
49 struct inquiry_data data; 49 struct inquiry_data data;
50}; 50};
51 51
52struct inquiry_cache { 52struct inquiry_cache {
53 struct list_head list;
53 __u32 timestamp; 54 __u32 timestamp;
54 struct inquiry_entry *list;
55}; 55};
56 56
57struct hci_conn_hash { 57struct hci_conn_hash {
@@ -350,14 +350,12 @@ extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
350 350
351static inline void inquiry_cache_init(struct hci_dev *hdev) 351static inline void inquiry_cache_init(struct hci_dev *hdev)
352{ 352{
353 struct inquiry_cache *c = &hdev->inq_cache; 353 INIT_LIST_HEAD(&hdev->inq_cache.list);
354 c->list = NULL;
355} 354}
356 355
357static inline int inquiry_cache_empty(struct hci_dev *hdev) 356static inline int inquiry_cache_empty(struct hci_dev *hdev)
358{ 357{
359 struct inquiry_cache *c = &hdev->inq_cache; 358 return list_empty(&hdev->inq_cache.list);
360 return c->list == NULL;
361} 359}
362 360
363static inline long inquiry_cache_age(struct hci_dev *hdev) 361static inline long inquiry_cache_age(struct hci_dev *hdev)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 845da3ee56a0..feeea4df2529 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -357,15 +357,11 @@ struct hci_dev *hci_dev_get(int index)
357/* ---- Inquiry support ---- */ 357/* ---- Inquiry support ---- */
358static void inquiry_cache_flush(struct hci_dev *hdev) 358static void inquiry_cache_flush(struct hci_dev *hdev)
359{ 359{
360 struct inquiry_cache *cache = &hdev->inq_cache; 360 struct inquiry_entry *p, *n;
361 struct inquiry_entry *next = cache->list, *e;
362
363 BT_DBG("cache %p", cache);
364 361
365 cache->list = NULL; 362 list_for_each_entry_safe(p, n, &hdev->inq_cache.list, list) {
366 while ((e = next)) { 363 list_del(&p->list);
367 next = e->next; 364 kfree(p);
368 kfree(e);
369 } 365 }
370} 366}
371 367
@@ -376,10 +372,12 @@ struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, bdaddr_t *b
376 372
377 BT_DBG("cache %p, %s", cache, batostr(bdaddr)); 373 BT_DBG("cache %p, %s", cache, batostr(bdaddr));
378 374
379 for (e = cache->list; e; e = e->next) 375 list_for_each_entry(e, &cache->list, list) {
380 if (!bacmp(&e->data.bdaddr, bdaddr)) 376 if (!bacmp(&e->data.bdaddr, bdaddr))
381 break; 377 return e;
382 return e; 378 }
379
380 return NULL;
383} 381}
384 382
385void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data) 383void 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)
396 if (!ie) 394 if (!ie)
397 return; 395 return;
398 396
399 ie->next = cache->list; 397 list_add(&ie->list, &cache->list);
400 cache->list = ie;
401 } 398 }
402 399
403 memcpy(&ie->data, data, sizeof(*data)); 400 memcpy(&ie->data, data, sizeof(*data));
@@ -412,15 +409,21 @@ static int inquiry_cache_dump(struct hci_dev *hdev, int num, __u8 *buf)
412 struct inquiry_entry *e; 409 struct inquiry_entry *e;
413 int copied = 0; 410 int copied = 0;
414 411
415 for (e = cache->list; e && copied < num; e = e->next, copied++) { 412 list_for_each_entry(e, &cache->list, list) {
416 struct inquiry_data *data = &e->data; 413 struct inquiry_data *data = &e->data;
414
415 if (copied >= num)
416 break;
417
417 bacpy(&info->bdaddr, &data->bdaddr); 418 bacpy(&info->bdaddr, &data->bdaddr);
418 info->pscan_rep_mode = data->pscan_rep_mode; 419 info->pscan_rep_mode = data->pscan_rep_mode;
419 info->pscan_period_mode = data->pscan_period_mode; 420 info->pscan_period_mode = data->pscan_period_mode;
420 info->pscan_mode = data->pscan_mode; 421 info->pscan_mode = data->pscan_mode;
421 memcpy(info->dev_class, data->dev_class, 3); 422 memcpy(info->dev_class, data->dev_class, 3);
422 info->clock_offset = data->clock_offset; 423 info->clock_offset = data->clock_offset;
424
423 info++; 425 info++;
426 copied++;
424 } 427 }
425 428
426 BT_DBG("cache %p, copied %d", cache, copied); 429 BT_DBG("cache %p, copied %d", cache, copied);
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 521095614235..ed9cceeec7be 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -388,7 +388,7 @@ static int inquiry_cache_show(struct seq_file *f, void *p)
388 388
389 hci_dev_lock(hdev); 389 hci_dev_lock(hdev);
390 390
391 for (e = cache->list; e; e = e->next) { 391 list_for_each_entry(e, &cache->list, list) {
392 struct inquiry_data *data = &e->data; 392 struct inquiry_data *data = &e->data;
393 seq_printf(f, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n", 393 seq_printf(f, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
394 batostr(&data->bdaddr), 394 batostr(&data->bdaddr),