Skip to contentSkip to conversation

Bluetooth: Use kzalloc instead of kmalloc for pending mgmt commands

PATCH In review [email protected] 2 participants 6 messages Jun 28, 2014

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

PATCH 1/3 Bluetooth: Use kzalloc instead of kmalloc for pending mgmt commands

From: Johan Hedberg <[email protected]>

By using kzalloc we ensure that there are no struct members, such as the user_data pointer, left uninitialized.

---
 net/bluetooth/mgmt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/mgmt.c +1 -1
index d542f8af6a5d..03fa50d1ff05 100644
@@ -984,7 +984,7 @@ static struct pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode,
 {
 	struct pending_cmd *cmd;
 
-	cmd = kmalloc(sizeof(*cmd), GFP_KERNEL);
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
 	if (!cmd)
 		return NULL;
 
Signature · 1 line
1.9.3
#1 lore raw

PATCH 2/3 Bluetooth: Add tracking of local and piconet clock values

From: Johan Hedberg <[email protected]>

This patch adds support for storing the local and piconet clock values from the HCI_Read_Clock command response to the hci_dev and hci_conn structs. This will be later used in another patch to implement support for the Get Clock Info mgmt command.

---
 include/net/bluetooth/hci.h      | 12 ++++++++++++
 include/net/bluetooth/hci_core.h |  4 ++++
 net/bluetooth/hci_event.c        | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
include/net/bluetooth/hci.h +12 -0
index 6933766e7215..58c5930dea60 100644
@@ -1087,6 +1087,18 @@ struct hci_rp_read_rssi {
 	__s8     rssi;
 } __packed;
 
+#define HCI_OP_READ_CLOCK		0x1407
+struct hci_cp_read_clock {
+	__le16   handle;
+	__u8     which;
+} __packed;
+struct hci_rp_read_clock {
+	__u8     status;
+	__le16   handle;
+	__le32   clock;
+	__le16   accuracy;
+} __packed;
+
 #define HCI_OP_READ_LOCAL_AMP_INFO	0x1409
 struct hci_rp_read_local_amp_info {
 	__u8     status;
include/net/bluetooth/hci_core.h +4 -0
index ca2a99807615..0906990dedd8 100644
@@ -207,6 +207,7 @@ struct hci_dev {
 	__u16		conn_info_min_age;
 	__u16		conn_info_max_age;
 	__u8		ssp_debug_mode;
+	__u32		clock;
 
 	__u16		devid_source;
 	__u16		devid_vendor;
@@ -388,6 +389,9 @@ struct hci_conn {
 	__s8		max_tx_power;
 	unsigned long	flags;
 
+	__u32		clock;
+	__u16		clock_accuracy;
+
 	unsigned long	conn_info_timestamp;
 
 	__u8		remote_cap;
net/bluetooth/hci_event.c +39 -0
index 7a23324eac39..315d615ca3f9 100644
@@ -721,6 +721,41 @@ static void hci_cc_read_data_block_size(struct hci_dev *hdev,
 	       hdev->block_cnt, hdev->block_len);
 }
 
+static void hci_cc_read_clock(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct hci_rp_read_clock *rp = (void *) skb->data;
+	struct hci_cp_read_clock *cp;
+	struct hci_conn *conn;
+
+	BT_DBG("%s", hdev->name);
+
+	if (skb->len < sizeof(*rp))
+		return;
+
+	if (rp->status)
+		return;
+
+	hci_dev_lock(hdev);
+
+	cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK);
+	if (!cp)
+		goto unlock;
+
+	if (cp->which == 0x00) {
+		hdev->clock = le32_to_cpu(rp->clock);
+		goto unlock;
+	}
+
+	conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
+	if (conn) {
+		conn->clock = le32_to_cpu(rp->clock);
+		conn->clock_accuracy = le16_to_cpu(rp->accuracy);
+	}
+
+unlock:
+	hci_dev_unlock(hdev);
+}
+
 static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
 				       struct sk_buff *skb)
 {
@@ -2597,6 +2632,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_cc_read_local_amp_info(hdev, skb);
 		break;
 
+	case HCI_OP_READ_CLOCK:
+		hci_cc_read_clock(hdev, skb);
+		break;
+
 	case HCI_OP_READ_LOCAL_AMP_ASSOC:
 		hci_cc_read_local_amp_assoc(hdev, skb);
 		break;
Signature · 1 line
1.9.3
maintainer
#2 lore raw

Re: [PATCH 2/3] Bluetooth: Add tracking of local and piconet clock values

Hi Johan,

Quoted 11 lines

This patch adds support for storing the local and piconet clock values from the HCI_Read_Clock command response to the hci_dev and hci_conn structs. This will be later used in another patch to implement support for the Get Clock Info mgmt command.

---

include/net/bluetooth/hci.h      | 12 ++++++++++++
include/net/bluetooth/hci_core.h |  4 ++++
net/bluetooth/hci_event.c        | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel

#3 lore raw

PATCH 3/3 Bluetooth: Add support for Get Clock Info mgmt command

In reply to [email protected]

From: Johan Hedberg <[email protected]>

This patch implements support for the Get Clock Information mgmt command. This is done by performing one or two HCI_Read_Clock commands and creating the response from the stored values in the hci_dev and hci_conn structs.

---
 include/net/bluetooth/mgmt.h |  12 ++++
 net/bluetooth/mgmt.c         | 145 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+)
include/net/bluetooth/mgmt.h +12 -0
index bcffc9ae0c89..d3f27bb46f89 100644
@@ -424,6 +424,18 @@ struct mgmt_rp_get_conn_info {
 	__s8	max_tx_power;
 } __packed;
 
+#define MGMT_OP_GET_CLOCK_INFO		0x0033
+struct mgmt_cp_get_clock_info {
+	struct mgmt_addr_info addr;
+} __packed;
+#define MGMT_GET_CLOCK_INFO_SIZE	MGMT_ADDR_INFO_SIZE
+struct mgmt_rp_get_clock_info {
+	struct mgmt_addr_info addr;
+	__le32  local_clock;
+	__le32  piconet_clock;
+	__le16  accuracy;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16	opcode;
net/bluetooth/mgmt.c +145 -0

169 lines not on this page · raw message

Signature · 1 line
1.9.3
maintainer
#4 lore raw

Re: [PATCH 3/3] Bluetooth: Add support for Get Clock Info mgmt command

Hi Johan,

Quoted 10 lines

This patch implements support for the Get Clock Information mgmt command. This is done by performing one or two HCI_Read_Clock commands and creating the response from the stored values in the hci_dev and hci_conn structs.

---
include/net/bluetooth/mgmt.h | 12 ++++
net/bluetooth/mgmt.c | 145 +++++++++++++++++++++++++++++++++++++++++++

2 files changed, 157 insertions(+)

patch has been applied to bluetooth-next tree.

However I replaced hci_conn_put with hci_conn_drop to get the reference counting right. Otherwise your kernel will actually oops eventually.

Regards

Marcel