Skip to contentSkip to conversation

Propagata hci_register_sysfs() error

PATCH New Erik Andrén 1 participant 2 messages Mar 7, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Propagata hci_register_sysfs() error

Currently if the hci_register_sysfs() function fails, the error is not propagated. Make it so.

---
 net/bluetooth/hci_core.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
net/bluetooth/hci_core.c +6 -3
index cd06151..9c98f6e 100644
@@ -842,7 +842,7 @@ EXPORT_SYMBOL(hci_free_dev);
 int hci_register_dev(struct hci_dev *hdev)
 {
 	struct list_head *head = &hci_dev_list, *p;
-	int i, id = 0;
+	int i, err, id = 0;
 
 	BT_DBG("%p name %s type %d owner %p", hdev, hdev->name, hdev->type, hdev->owner);
 
@@ -855,7 +855,8 @@ int hci_register_dev(struct hci_dev *hdev)
 	list_for_each(p, &hci_dev_list) {
 		if (list_entry(p, struct hci_dev, list)->id != id)
 			break;
-		head = p; id++;
+		head = p;
+		id++;
 	}
 
 	sprintf(hdev->name, "hci%d", id);
@@ -898,7 +899,9 @@ int hci_register_dev(struct hci_dev *hdev)
 
 	write_unlock_bh(&hci_dev_list_lock);
 
-	hci_register_sysfs(hdev);
+	err = hci_register_sysfs(hdev);
+	if (err < 0)
+		return err;
 
 	hci_notify(hdev, HCI_DEV_REG);
 
Signature · 1 line
1.5.6.3
#1 lore raw

PATCH 2/2 Defer btaddconn and btdelconn workqueues until a device has actually connected

Many distros always load the bluetooth module, even if no actual bluetooth device exists. This causes two workqueues: btaddconn and btdelconn to be spawned at init time, clogging up the process list without performing any actual work.
This patch defers the workqueue creation until the first hci device has connected. Also, tear down the workqueues when the last device disconnects.

---
 include/net/bluetooth/hci_core.h |    4 +-
 net/bluetooth/hci_core.c         |   11 ++++++---
 net/bluetooth/hci_sysfs.c        |   44 +++++++++++++++++++++----------------
 3 files changed, 34 insertions(+), 25 deletions(-)
include/net/bluetooth/hci_core.h +2 -2
index 01f9316..b3bc9fa 100644
@@ -453,8 +453,8 @@ static inline int hci_recv_frame(struct sk_buff *skb)
 
 int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
 
-int hci_register_sysfs(struct hci_dev *hdev);
-void hci_unregister_sysfs(struct hci_dev *hdev);
+int hci_register_sysfs(struct hci_dev *hdev, bool e);
+void hci_unregister_sysfs(struct hci_dev *hdev, bool e);
 void hci_conn_add_sysfs(struct hci_conn *conn);
 void hci_conn_del_sysfs(struct hci_conn *conn);
 
net/bluetooth/hci_core.c +7 -4
index 9c98f6e..c21753f 100644
@@ -843,6 +843,7 @@ int hci_register_dev(struct hci_dev *hdev)
 {
 	struct list_head *head = &hci_dev_list, *p;
 	int i, err, id = 0;
+	bool empty;
 
 	BT_DBG("%p name %s type %d owner %p", hdev, hdev->name, hdev->type, hdev->owner);
 
@@ -859,6 +860,8 @@ int hci_register_dev(struct hci_dev *hdev)
 		id++;
 	}
 
+	empty = list_empty(&hci_dev_list);
+
 	sprintf(hdev->name, "hci%d", id);
 	hdev->id = id;
 	list_add(&hdev->list, head);
@@ -896,10 +899,9 @@ int hci_register_dev(struct hci_dev *hdev)
 	memset(&hdev->stat, 0, sizeof(struct hci_dev_stats));
 
 	atomic_set(&hdev->promisc, 0);
-
 	write_unlock_bh(&hci_dev_list_lock);
 
-	err = hci_register_sysfs(hdev);
+	err = hci_register_sysfs(hdev, empty);
 	if (err < 0)
 		return err;
 
@@ -913,13 +915,14 @@ EXPORT_SYMBOL(hci_register_dev);
 int hci_unregister_dev(struct hci_dev *hdev)
 {
 	int i;
+	bool empty;
 
 	BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
 
 	write_lock_bh(&hci_dev_list_lock);
 	list_del(&hdev->list);
+	empty = list_empty(&hci_dev_list);
 	write_unlock_bh(&hci_dev_list_lock);
-
 	hci_dev_do_close(hdev);
 
 	for (i = 0; i < 3; i++)
@@ -927,7 +930,7 @@ int hci_unregister_dev(struct hci_dev *hdev)
 
 	hci_notify(hdev, HCI_DEV_UNREG);
 
-	hci_unregister_sysfs(hdev);
+	hci_unregister_sysfs(hdev, empty);
 
 	__hci_dev_put(hdev);
 
net/bluetooth/hci_sysfs.c +25 -19

74 lines not on this page · raw message

Signature · 1 line
1.5.6.3