diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2010-03-02 10:48:23 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-03-03 04:04:38 -0500 |
commit | d4612cb86ed8db8956b6b19435f8a30de6c67ffe (patch) | |
tree | 1b316277198d7fe51aa74d44bb1e7ca0265e834d /net | |
parent | 1162563f82b434e3099c9e6c1bbdba846d792f0d (diff) |
Bluetooth: Use single_open() for inquiry cache within debugfs
The inquiry cache information in debugfs should be using seq_file support
and not allocating memory on the stack for the string. Since the usage of
these information is really seldom, using single_open() for it is good
enough.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/bluetooth/hci_sysfs.c | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c index 1a79a6c7e30e..cafb55b0cea5 100644 --- a/net/bluetooth/hci_sysfs.c +++ b/net/bluetooth/hci_sysfs.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <linux/kernel.h> | 3 | #include <linux/kernel.h> |
4 | #include <linux/init.h> | 4 | #include <linux/init.h> |
5 | #include <linux/debugfs.h> | 5 | #include <linux/debugfs.h> |
6 | #include <linux/seq_file.h> | ||
6 | 7 | ||
7 | #include <net/bluetooth/bluetooth.h> | 8 | #include <net/bluetooth/bluetooth.h> |
8 | #include <net/bluetooth/hci_core.h> | 9 | #include <net/bluetooth/hci_core.h> |
@@ -405,20 +406,11 @@ static struct device_type bt_host = { | |||
405 | .release = bt_host_release, | 406 | .release = bt_host_release, |
406 | }; | 407 | }; |
407 | 408 | ||
408 | static int inquiry_cache_open(struct inode *inode, struct file *file) | 409 | static int inquiry_cache_show(struct seq_file *f, void *p) |
409 | { | ||
410 | file->private_data = inode->i_private; | ||
411 | return 0; | ||
412 | } | ||
413 | |||
414 | static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf, | ||
415 | size_t count, loff_t *ppos) | ||
416 | { | 410 | { |
417 | struct hci_dev *hdev = file->private_data; | 411 | struct hci_dev *hdev = f->private; |
418 | struct inquiry_cache *cache = &hdev->inq_cache; | 412 | struct inquiry_cache *cache = &hdev->inq_cache; |
419 | struct inquiry_entry *e; | 413 | struct inquiry_entry *e; |
420 | char buf[4096]; | ||
421 | int n = 0; | ||
422 | 414 | ||
423 | hci_dev_lock_bh(hdev); | 415 | hci_dev_lock_bh(hdev); |
424 | 416 | ||
@@ -426,23 +418,30 @@ static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf, | |||
426 | struct inquiry_data *data = &e->data; | 418 | struct inquiry_data *data = &e->data; |
427 | bdaddr_t bdaddr; | 419 | bdaddr_t bdaddr; |
428 | baswap(&bdaddr, &data->bdaddr); | 420 | baswap(&bdaddr, &data->bdaddr); |
429 | n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n", | 421 | seq_printf(f, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n", |
430 | batostr(&bdaddr), | 422 | batostr(&bdaddr), |
431 | data->pscan_rep_mode, data->pscan_period_mode, | 423 | data->pscan_rep_mode, data->pscan_period_mode, |
432 | data->pscan_mode, data->dev_class[2], | 424 | data->pscan_mode, data->dev_class[2], |
433 | data->dev_class[1], data->dev_class[0], | 425 | data->dev_class[1], data->dev_class[0], |
434 | __le16_to_cpu(data->clock_offset), | 426 | __le16_to_cpu(data->clock_offset), |
435 | data->rssi, data->ssp_mode, e->timestamp); | 427 | data->rssi, data->ssp_mode, e->timestamp); |
436 | } | 428 | } |
437 | 429 | ||
438 | hci_dev_unlock_bh(hdev); | 430 | hci_dev_unlock_bh(hdev); |
439 | 431 | ||
440 | return simple_read_from_buffer(userbuf, count, ppos, buf, n); | 432 | return 0; |
433 | } | ||
434 | |||
435 | static int inquiry_cache_open(struct inode *inode, struct file *file) | ||
436 | { | ||
437 | return single_open(file, inquiry_cache_show, inode->i_private); | ||
441 | } | 438 | } |
442 | 439 | ||
443 | static const struct file_operations inquiry_cache_fops = { | 440 | static const struct file_operations inquiry_cache_fops = { |
444 | .open = inquiry_cache_open, | 441 | .open = inquiry_cache_open, |
445 | .read = inquiry_cache_read, | 442 | .read = seq_read, |
443 | .llseek = seq_lseek, | ||
444 | .release = single_release, | ||
446 | }; | 445 | }; |
447 | 446 | ||
448 | int hci_register_sysfs(struct hci_dev *hdev) | 447 | int hci_register_sysfs(struct hci_dev *hdev) |