Linux bluetooth development
 help / color / mirror / Atom feed
From: David Herrmann <dh.herrmann@googlemail.com>
To: linux-bluetooth@vger.kernel.org
Cc: marcel@holtmann.org, padovan@profusion.mobi,
	David Herrmann <dh.herrmann@googlemail.com>
Subject: [RFC 2/4] Bluetooth: Fix hci-sysfs ref-counts
Date: Fri, 28 Oct 2011 15:00:02 +0200	[thread overview]
Message-ID: <1319806804-12230-3-git-send-email-dh.herrmann@googlemail.com> (raw)
In-Reply-To: <1319806804-12230-1-git-send-email-dh.herrmann@googlemail.com>

When registering a device object we need to take a module reference so
the device-destruct function is available when the object is freed.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
---
 include/net/bluetooth/hci_core.h |    2 +-
 net/bluetooth/hci_core.c         |    6 +++++-
 net/bluetooth/hci_sysfs.c        |    8 +++++++-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 13a62ad..c8368a5 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -580,7 +580,7 @@ int hci_recv_frame(struct sk_buff *skb);
 int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
 int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count);
 
-void hci_init_sysfs(struct hci_dev *hdev);
+int hci_init_sysfs(struct hci_dev *hdev);
 int hci_add_sysfs(struct hci_dev *hdev);
 void hci_del_sysfs(struct hci_dev *hdev);
 void hci_conn_init_sysfs(struct hci_conn *conn);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index daa948f..20c3c97 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -912,7 +912,11 @@ struct hci_dev *hci_alloc_dev(void)
 	if (!hdev)
 		return NULL;
 
-	hci_init_sysfs(hdev);
+	if (hci_init_sysfs(hdev)) {
+		kfree(hdev);
+		return NULL;
+	}
+
 	skb_queue_head_init(&hdev->driver_init);
 
 	return hdev;
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 116401a..605cb2b 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -78,6 +78,7 @@ static void bt_link_release(struct device *dev)
 {
 	void *data = dev_get_drvdata(dev);
 	kfree(data);
+	module_put(THIS_MODULE);
 }
 
 static struct device_type bt_link = {
@@ -540,15 +541,20 @@ static int auto_accept_delay_get(void *data, u64 *val)
 DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
 					auto_accept_delay_set, "%llu\n");
 
-void hci_init_sysfs(struct hci_dev *hdev)
+int hci_init_sysfs(struct hci_dev *hdev)
 {
 	struct device *dev = &hdev->dev;
 
+	if (!try_module_get(THIS_MODULE))
+		return -EIO;
+
 	dev->type = &bt_host;
 	dev->class = bt_class;
 
 	dev_set_drvdata(dev, hdev);
 	device_initialize(dev);
+
+	return 0;
 }
 
 int hci_add_sysfs(struct hci_dev *hdev)
-- 
1.7.7.1

  parent reply	other threads:[~2011-10-28 13:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-28 13:00 [RFC 0/4] Fix hci_dev ref-counts David Herrmann
2011-10-28 13:00 ` [RFC 1/4] Bluetooth: Remove obsolete hci-destruct callback David Herrmann
2011-10-28 13:00 ` David Herrmann [this message]
2011-10-29 16:40   ` [RFC 2/4] Bluetooth: Fix hci-sysfs ref-counts David Herrmann
2011-10-28 13:00 ` [RFC 3/4] Bluetooth: Remove hci owner field David Herrmann
2011-10-28 13:00 ` [RFC 4/4] Bluetooth: Correctly take device refcounts David Herrmann
2011-10-31 11:58 ` [RFC 0/4] Fix hci_dev ref-counts Marcel Holtmann
2011-11-01 19:59   ` David Herrmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1319806804-12230-3-git-send-email-dh.herrmann@googlemail.com \
    --to=dh.herrmann@googlemail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=padovan@profusion.mobi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox