diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2012-01-03 09:03:00 -0500 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2012-02-13 10:01:19 -0500 |
commit | b57c1a5646739bfc273245dc738f2f12a2d4d3ec (patch) | |
tree | 1311c1e412bceb3dc53487c3a71365a976c2ce39 /net/bluetooth | |
parent | 12325280dfeba18164f9c47e226a40ab34e23ee7 (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>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/hci_core.c | 31 | ||||
-rw-r--r-- | net/bluetooth/hci_sysfs.c | 2 |
2 files changed, 18 insertions, 15 deletions
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 ---- */ |
358 | static void inquiry_cache_flush(struct hci_dev *hdev) | 358 | static 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 | ||
385 | void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data) | 383 | 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) | |||
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), |