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@xxxxxxxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html