linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] Bluetooth: hci_core: return cmd status in __hci_cmd_sync()
@ 2015-05-11 15:50 Frederic Danis
  2015-05-11 15:50 ` [PATCH v3 2/2] Bluetooth: Update calls to __hci_cmd_sync() Frederic Danis
  2015-05-11 17:35 ` [PATCH v3 1/2] Bluetooth: hci_core: return cmd status in __hci_cmd_sync() Johan Hedberg
  0 siblings, 2 replies; 3+ messages in thread
From: Frederic Danis @ 2015-05-11 15:50 UTC (permalink / raw)
  To: linux-bluetooth

Handle command complete event, extract command status from reply and
return it if it is an error.
This will allow to simplify error test in calling functions.

Signed-off-by: Frederic Danis <frederic.danis@linux.intel.com>
---
 net/bluetooth/hci_core.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 476709b..3510284 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -94,7 +94,6 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
 	char buf[32];
 	size_t buf_size = min(count, (sizeof(buf)-1));
 	bool enable;
-	int err;
 
 	if (!test_bit(HCI_UP, &hdev->flags))
 		return -ENETDOWN;
@@ -121,12 +120,6 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
 	if (IS_ERR(skb))
 		return PTR_ERR(skb);
 
-	err = -bt_to_errno(skb->data[0]);
-	kfree_skb(skb);
-
-	if (err < 0)
-		return err;
-
 	hci_dev_change_flag(hdev, HCI_DUT_MODE);
 
 	return count;
@@ -234,7 +227,18 @@ EXPORT_SYMBOL(__hci_cmd_sync_ev);
 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
 			       const void *param, u32 timeout)
 {
-	return __hci_cmd_sync_ev(hdev, opcode, plen, param, 0, timeout);
+	struct sk_buff *skb;
+	int err;
+
+	skb = __hci_cmd_sync_ev(hdev, opcode, plen, param, 0, timeout);
+	if (!IS_ERR(skb) && skb->data[0]) {
+		err = -bt_to_errno(skb->data[0]);
+		kfree_skb(skb);
+
+		return ERR_PTR(err);
+	}
+
+	return skb;
 }
 EXPORT_SYMBOL(__hci_cmd_sync);
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-05-11 17:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-11 15:50 [PATCH v3 1/2] Bluetooth: hci_core: return cmd status in __hci_cmd_sync() Frederic Danis
2015-05-11 15:50 ` [PATCH v3 2/2] Bluetooth: Update calls to __hci_cmd_sync() Frederic Danis
2015-05-11 17:35 ` [PATCH v3 1/2] Bluetooth: hci_core: return cmd status in __hci_cmd_sync() Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).