diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2011-10-08 08:58:47 -0400 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-10-14 14:22:28 -0400 |
commit | 0ac7e7002c4d0841197e9ccb8cfecc5b8c58b200 (patch) | |
tree | 5050ba12aedf48b75660ab9175fcae26250cd603 /net/bluetooth/hci_sysfs.c | |
parent | 928abaa777501ddab94b1b49aae485a2c730d303 (diff) |
Bluetooth: Fix hci core device initialization
We must not call device_del() if we didn't use device_add(). See module.c
for comments on that. Therefore, we need to call device_initialize() when
allocating the hci device and later device_add() instead of
device_register().
This also fixes a bug when hci_register_dev() failed and we call
hci_free_dev() without a valid core device. hci_free_dev() segfaults while
calling put_device() on invalid memory.
We already do this with hci_conn connections (hci_conn_init_sysfs()) so
they do not need to be fixed.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net/bluetooth/hci_sysfs.c')
-rw-r--r-- | net/bluetooth/hci_sysfs.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c index 22f1a6c87035..a7d5de3a6b5a 100644 --- a/net/bluetooth/hci_sysfs.c +++ b/net/bluetooth/hci_sysfs.c | |||
@@ -542,6 +542,17 @@ static int auto_accept_delay_get(void *data, u64 *val) | |||
542 | DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get, | 542 | DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get, |
543 | auto_accept_delay_set, "%llu\n"); | 543 | auto_accept_delay_set, "%llu\n"); |
544 | 544 | ||
545 | void hci_init_sysfs(struct hci_dev *hdev) | ||
546 | { | ||
547 | struct device *dev = &hdev->dev; | ||
548 | |||
549 | dev->type = &bt_host; | ||
550 | dev->class = bt_class; | ||
551 | |||
552 | dev_set_drvdata(dev, hdev); | ||
553 | device_initialize(dev); | ||
554 | } | ||
555 | |||
545 | int hci_register_sysfs(struct hci_dev *hdev) | 556 | int hci_register_sysfs(struct hci_dev *hdev) |
546 | { | 557 | { |
547 | struct device *dev = &hdev->dev; | 558 | struct device *dev = &hdev->dev; |
@@ -549,15 +560,10 @@ int hci_register_sysfs(struct hci_dev *hdev) | |||
549 | 560 | ||
550 | BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); | 561 | BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); |
551 | 562 | ||
552 | dev->type = &bt_host; | ||
553 | dev->class = bt_class; | ||
554 | dev->parent = hdev->parent; | 563 | dev->parent = hdev->parent; |
555 | |||
556 | dev_set_name(dev, "%s", hdev->name); | 564 | dev_set_name(dev, "%s", hdev->name); |
557 | 565 | ||
558 | dev_set_drvdata(dev, hdev); | 566 | err = device_add(dev); |
559 | |||
560 | err = device_register(dev); | ||
561 | if (err < 0) | 567 | if (err < 0) |
562 | return err; | 568 | return err; |
563 | 569 | ||