summaryrefslogtreecommitdiffstats
path: root/hcid/device.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2006-08-18 22:32:10 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2006-08-18 22:32:10 +0000
commit49852c0b4fe1ef1dae5d11e7ff01b70c12464e40 (patch)
tree629e3bb0864ad6362eea38a594729fb7a8946be2 /hcid/device.c
parent14c1a4ad4c1fd5b86d3664707d76801013caa741 (diff)
Fix accessing free'd memory
Diffstat (limited to 'hcid/device.c')
-rw-r--r--hcid/device.c49
1 files changed, 20 insertions, 29 deletions
diff --git a/hcid/device.c b/hcid/device.c
index 7beb4fe8..5c3518dd 100644
--- a/hcid/device.c
+++ b/hcid/device.c
@@ -99,28 +99,6 @@ void init_devices(void)
memset(devices + i, 0, sizeof(struct hci_dev));
}
-static int device_read_bdaddr(uint16_t dev_id, bdaddr_t *bdaddr)
-{
- int dd;
-
- dd = hci_open_dev(dev_id);
- if (dd < 0) {
- error("Can't open device hci%d",
- dev_id, strerror(errno), errno);
- return -errno;
- }
-
- if (hci_read_bd_addr(dd, bdaddr, 2000) < 0) {
- error("Can't read address for hci%d: %s (%d)",
- dev_id, strerror(errno), errno);
- return -errno;
- }
-
- hci_close_dev(dd);
-
- return 0;
-}
-
int add_device(uint16_t dev_id)
{
struct hci_dev *dev;
@@ -140,13 +118,7 @@ int add_device(uint16_t dev_id)
dev->ignore = 1;
}
- if (bacmp(&di.bdaddr, BDADDR_ANY))
- bacpy(&dev->bdaddr, &di.bdaddr);
- else {
- int ret = device_read_bdaddr(dev_id, &dev->bdaddr);
- if (ret < 0)
- return ret;
- }
+ bacpy(&dev->bdaddr, &di.bdaddr);
memcpy(dev->features, di.features, 8);
info("Device hci%d has been added", dev_id);
@@ -266,6 +238,7 @@ int stop_device(uint16_t dev_id)
int get_device_address(uint16_t dev_id, char *address, size_t size)
{
struct hci_dev *dev;
+ int dd;
ASSERT_DEV_ID;
@@ -274,6 +247,24 @@ int get_device_address(uint16_t dev_id, char *address, size_t size)
dev = &devices[dev_id];
+ if (bacmp(&dev->bdaddr, BDADDR_ANY))
+ return ba2str(&dev->bdaddr, address);
+
+ dd = hci_open_dev(dev_id);
+ if (dd < 0) {
+ error("Can't open device hci%d",
+ dev_id, strerror(errno), errno);
+ return -errno;
+ }
+
+ if (hci_read_bd_addr(dd, &dev->bdaddr, 2000) < 0) {
+ error("Can't read address for hci%d: %s (%d)",
+ dev_id, strerror(errno), errno);
+ return -errno;
+ }
+
+ hci_close_dev(dd);
+
return ba2str(&dev->bdaddr, address);
}