Bluetooth: coding-style: fix one-line branch braces usage

The coding guidelines make an exception to the Linux kernel style
where all branches, even one-liners, should use braces.

Change-Id: I368930af3033eac15f0152a6671909e401d332e6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-05-05 10:50:14 +03:00 committed by Anas Nashif
parent 607819ec5e
commit a0bb20f4d1
6 changed files with 126 additions and 67 deletions

View file

@ -68,8 +68,9 @@ static int bt_uart_read(int uart, uint8_t *buf, size_t len, size_t min)
rx = uart_fifo_read(uart, buf, len);
if (rx == 0) {
BT_DBG("Got zero bytes from UART\n");
if (total < min)
if (total < min) {
continue;
}
break;
}
@ -86,8 +87,9 @@ static size_t bt_uart_discard(int uart, size_t len)
{
uint8_t buf[33];
if (len > sizeof(buf))
if (len > sizeof(buf)) {
len = sizeof(buf);
}
return uart_fifo_read(uart, buf, len);
}
@ -103,10 +105,11 @@ static struct bt_buf *bt_uart_evt_recv(int *remaining)
*remaining = hdr.len;
buf = bt_buf_get(BT_EVT, 0);
if (buf)
if (buf) {
memcpy(bt_buf_add(buf, sizeof(hdr)), &hdr, sizeof(hdr));
else
} else {
BT_ERR("No available event buffers!\n");
}
BT_DBG("len %u\n", hdr.len);
@ -122,10 +125,11 @@ static struct bt_buf *bt_uart_acl_recv(int *remaining)
bt_uart_read(UART, (void *)&hdr, sizeof(hdr), sizeof(hdr));
buf = bt_buf_get(BT_ACL_IN, 0);
if (buf)
if (buf) {
memcpy(bt_buf_add(buf, sizeof(hdr)), &hdr, sizeof(hdr));
else
} else {
BT_ERR("No available ACL buffers!\n");
}
*remaining = sys_le16_to_cpu(hdr.len);
@ -145,10 +149,11 @@ void bt_uart_isr(void *unused)
int read;
if (!uart_irq_rx_ready(UART)) {
if (uart_irq_tx_ready(UART))
if (uart_irq_tx_ready(UART)) {
BT_DBG("transmit ready\n");
else
} else {
BT_DBG("spurious interrupt\n");
}
continue;
}

View file

@ -53,8 +53,9 @@ static void send_err_rsp(struct bt_conn *conn, uint8_t req, uint16_t handle,
buf = bt_l2cap_create_pdu(conn, BT_L2CAP_CID_ATT,
sizeof(*hdr) + sizeof(*rsp));
if (!buf)
if (!buf) {
return;
}
hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
hdr->code = BT_ATT_ERROR_RSP;

View file

@ -105,14 +105,16 @@ void bt_buf_put(struct bt_buf *buf)
BT_DBG("buf %p ref %u type %d\n", buf, buf->ref, buf->type);
if (--buf->ref)
if (--buf->ref) {
return;
}
handle = buf->acl.handle;
nano_fifo_put(avail, buf);
if (avail != &avail_acl_in)
if (avail != &avail_acl_in) {
return;
}
BT_DBG("Reporting completed packet for handle %u\n", handle);
@ -184,16 +186,19 @@ int bt_buf_init(int acl_in, int acl_out)
acl_in, acl_out, NUM_BUFS - (acl_in + acl_out));
nano_fifo_init(&avail_acl_in);
for (i = 0; acl_in > 0; i++, acl_in--)
for (i = 0; acl_in > 0; i++, acl_in--) {
nano_fifo_put(&avail_acl_in, &buffers[i]);
}
nano_fifo_init(&avail_acl_out);
for (; acl_out > 0; i++, acl_out--)
for (; acl_out > 0; i++, acl_out--) {
nano_fifo_put(&avail_acl_out, &buffers[i]);
}
nano_fifo_init(&avail_hci);
for (; i < NUM_BUFS; i++)
for (; i < NUM_BUFS; i++) {
nano_fifo_put(&avail_hci, &buffers[i]);
}
return 0;
}

View file

@ -48,8 +48,9 @@ static struct bt_conn conns[MAX_CONN_COUNT];
static void bt_conn_reset_rx_state(struct bt_conn *conn)
{
if (!conn->rx_len)
if (!conn->rx_len) {
return;
}
bt_buf_put(conn->rx);
conn->rx = NULL;
@ -114,8 +115,9 @@ void bt_conn_recv(struct bt_conn *conn, struct bt_buf *buf, uint8_t flags)
conn->rx_len -= buf->len;
bt_buf_put(buf);
if (conn->rx_len)
if (conn->rx_len) {
return;
}
buf = conn->rx;
conn->rx = NULL;
@ -172,8 +174,9 @@ static void conn_rx_fiber(int arg1, int arg2)
BT_DBG("handle %u disconnected - cleaning up\n", conn->handle);
/* Give back any allocated buffers */
while ((buf = nano_fifo_get(&conn->rx_queue)))
while ((buf = nano_fifo_get(&conn->rx_queue))) {
bt_buf_put(buf);
}
bt_conn_reset_rx_state(conn);
@ -204,8 +207,9 @@ static void conn_tx_fiber(int arg1, int arg2)
BT_DBG("handle %u disconnected - cleaning up\n", conn->handle);
/* Give back any allocated buffers */
while ((buf = nano_fifo_get(&conn->tx_queue)))
while ((buf = nano_fifo_get(&conn->tx_queue))) {
bt_buf_put(buf);
}
BT_DBG("handle %u exiting\n", conn->handle);
bt_conn_put(conn);
@ -223,8 +227,9 @@ struct bt_conn *bt_conn_add(struct bt_dev *dev, uint16_t handle)
}
}
if (!conn)
if (!conn) {
return NULL;
}
memset(conn, 0, sizeof(*conn));
@ -251,8 +256,9 @@ void bt_conn_del(struct bt_conn *conn)
{
BT_DBG("handle %u\n", conn->handle);
if (conn->state != BT_CONN_CONNECTED)
if (conn->state != BT_CONN_CONNECTED) {
return;
}
conn->state = BT_CONN_DISCONNECTED;
@ -268,10 +274,13 @@ struct bt_conn *bt_conn_lookup(uint16_t handle)
int i;
for (i = 0; i < MAX_CONN_COUNT; i++) {
if (conns[i].state != BT_CONN_CONNECTED)
if (conns[i].state != BT_CONN_CONNECTED) {
continue;
if (conns[i].handle == handle)
}
if (conns[i].handle == handle) {
return &conns[i];
}
}
return NULL;
@ -292,8 +301,9 @@ void bt_conn_put(struct bt_conn *conn)
BT_DBG("handle %u ref %u\n", conn->handle, conn->ref);
if (conn->ref)
if (conn->ref) {
return;
}
conn->handle = 0;
}
@ -305,8 +315,9 @@ struct bt_buf *bt_conn_create_pdu(struct bt_conn *conn, size_t len)
struct bt_buf *buf;
buf = bt_buf_get(BT_ACL_OUT, dev->drv->head_reserve);
if (!buf)
if (!buf) {
return NULL;
}
hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
hdr->handle = sys_cpu_to_le16(conn->handle);

View file

@ -88,8 +88,9 @@ int bt_hci_cmd_send(uint16_t opcode, struct bt_buf *buf)
{
if (!buf) {
buf = bt_hci_cmd_create(opcode, 0);
if (!buf)
if (!buf) {
return -ENOBUFS;
}
}
BT_DBG("opcode %x len %u\n", opcode, buf->len);
@ -116,8 +117,9 @@ static int bt_hci_cmd_send_sync(uint16_t opcode, struct bt_buf *buf,
if (!buf) {
buf = bt_hci_cmd_create(opcode, 0);
if (!buf)
if (!buf) {
return -ENOBUFS;
}
}
BT_DBG("opcode %x len %u\n", opcode, buf->len);
@ -130,15 +132,17 @@ static int bt_hci_cmd_send_sync(uint16_t opcode, struct bt_buf *buf,
nano_sem_take_wait(&sync_sem);
/* Indicate failure if we failed to get the return parameters */
if (!buf->hci.sync)
if (!buf->hci.sync) {
err = -EIO;
else
} else {
err = 0;
}
if (rsp)
if (rsp) {
*rsp = buf->hci.sync;
else if (buf->hci.sync)
} else if (buf->hci.sync) {
bt_buf_put(buf->hci.sync);
}
bt_buf_put(buf);
@ -212,16 +216,18 @@ static void hci_reset_complete(struct bt_buf *buf)
BT_DBG("status %u\n", status);
if (status)
if (status) {
return;
}
}
static void hci_cmd_done(uint16_t opcode, uint8_t status, struct bt_buf *buf)
{
struct bt_buf *sent = dev.sent_cmd;
if (!sent)
if (!sent) {
return;
}
if (dev.sent_cmd->hci.opcode != opcode) {
BT_ERR("Unexpected completion of opcode %x\n", opcode);
@ -234,10 +240,11 @@ static void hci_cmd_done(uint16_t opcode, uint8_t status, struct bt_buf *buf)
if (sent->hci.sync) {
struct nano_sem *sem = sent->hci.sync;
if (status)
if (status) {
sent->hci.sync = NULL;
else
} else {
sent->hci.sync = bt_buf_hold(buf);
}
nano_fiber_sem_give(sem);
} else {
@ -499,8 +506,9 @@ static void host_buffer_size_complete(struct bt_buf *buf)
BT_DBG("status %u\n", rp->status);
/* If LE-side has buffers we can ignore the BR/EDR values */
if (dev.le_mtu)
if (dev.le_mtu) {
return;
}
dev.le_mtu = sys_le16_to_cpu(rp->acl_max_len);
dev.le_pkts = sys_le16_to_cpu(rp->acl_max_num);
@ -529,23 +537,26 @@ static int hci_init(void)
/* Read Local Supported Features */
err = bt_hci_cmd_send_sync(BT_HCI_OP_READ_LOCAL_FEATURES, NULL, &rsp);
if (err)
if (err) {
return err;
}
read_local_features_complete(rsp);
bt_buf_put(rsp);
/* Read Local Version Information */
err = bt_hci_cmd_send_sync(BT_HCI_OP_READ_LOCAL_VERSION_INFO, NULL,
&rsp);
if (err)
if (err) {
return err;
}
read_local_ver_complete(rsp);
bt_buf_put(rsp);
/* Read Bluetooth Address */
err = bt_hci_cmd_send_sync(BT_HCI_OP_READ_BD_ADDR, NULL, &rsp);
if (err)
if (err) {
return err;
}
read_bdaddr_complete(rsp);
bt_buf_put(rsp);
@ -558,21 +569,24 @@ static int hci_init(void)
/* Read Low Energy Supported Features */
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_READ_LOCAL_FEATURES, NULL,
&rsp);
if (err)
if (err) {
return err;
}
read_le_features_complete(rsp);
bt_buf_put(rsp);
/* Read LE Buffer Size */
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_READ_BUFFER_SIZE, NULL, &rsp);
if (err)
if (err) {
return err;
}
le_read_buffer_size_complete(rsp);
bt_buf_put(rsp);
buf = bt_hci_cmd_create(BT_HCI_OP_SET_EVENT_MASK, 8);
if (!buf)
if (!buf) {
return -ENOBUFS;
}
ev = (void *)bt_buf_add(buf, sizeof(*ev));
memset(ev, 0, sizeof(*ev));
@ -593,8 +607,9 @@ static int hci_init(void)
bt_hci_cmd_send_sync(BT_HCI_OP_SET_EVENT_MASK, buf, NULL);
buf = bt_hci_cmd_create(BT_HCI_OP_HOST_BUFFER_SIZE, sizeof(*hbs));
if (!buf)
if (!buf) {
return -ENOBUFS;
}
hbs = (void *)bt_buf_add(buf, sizeof(*hbs));
memset(hbs, 0, sizeof(*hbs));
@ -603,14 +618,16 @@ static int hci_init(void)
hbs->acl_pkts = sys_cpu_to_le16(ACL_IN_MAX);
err = bt_hci_cmd_send_sync(BT_HCI_OP_HOST_BUFFER_SIZE, buf, &rsp);
if (err)
if (err) {
return err;
}
host_buffer_size_complete(rsp);
bt_buf_put(rsp);
buf = bt_hci_cmd_create(BT_HCI_OP_SET_CTL_TO_HOST_FLOW, 1);
if (!buf)
if (!buf) {
return -ENOBUFS;
}
enable = (void *)bt_buf_add(buf, sizeof(*enable));
*enable = 0x01;
@ -620,14 +637,15 @@ static int hci_init(void)
struct bt_hci_cp_write_le_host_supp *cp;
/* Use BR/EDR buffer size if LE reports zero buffers */
if (!dev.le_mtu)
if (!dev.le_mtu) {
bt_hci_cmd_send(BT_HCI_OP_READ_BUFFER_SIZE, NULL);
}
buf = bt_hci_cmd_create(BT_HCI_OP_LE_WRITE_LE_HOST_SUPP,
sizeof(*cp));
if (!buf)
if (!buf) {
return -ENOBUFS;
}
cp = (void *)bt_buf_add(buf, sizeof*cp);
@ -659,11 +677,13 @@ void bt_recv(struct bt_buf *buf)
int bt_driver_register(struct bt_driver *drv)
{
if (dev.drv)
if (dev.drv) {
return -EALREADY;
}
if (!drv->open || !drv->send)
if (!drv->open || !drv->send) {
return -EINVAL;
}
dev.drv = drv;
@ -704,8 +724,9 @@ int bt_init(void)
int acl_out;
int err;
if (!drv)
if (!drv) {
return -ENODEV;
}
/* Initialize buffers with zero ACL for starters */
bt_buf_init(0, 0);
@ -714,21 +735,24 @@ int bt_init(void)
rx_queue_init();
err = drv->open();
if (err)
if (err) {
return err;
}
err = hci_init();
if (err)
if (err) {
return err;
}
/* Initialize pending ACL packets FIFO */
nano_fifo_init(&dev.acl_pend);
/* Re-initialize buffers now that we know the ACL counts */
if (dev.le_pkts > ACL_OUT_MAX)
if (dev.le_pkts > ACL_OUT_MAX) {
acl_out = ACL_OUT_MAX;
else
} else {
acl_out = dev.le_pkts;
}
return bt_buf_init(ACL_IN_MAX, acl_out);
}
@ -742,12 +766,14 @@ int bt_start_advertising(uint8_t type, const struct bt_eir *ad,
struct bt_hci_cp_le_set_adv_parameters *set_param;
int i;
if (!ad)
if (!ad) {
goto send_scan_rsp;
}
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_DATA, sizeof(*set_data));
if (!buf)
if (!buf) {
return -ENOBUFS;
}
set_data = (void *)bt_buf_add(buf, sizeof(*set_data));
@ -755,8 +781,9 @@ int bt_start_advertising(uint8_t type, const struct bt_eir *ad,
for (i = 0; ad[i].len; i++) {
/* Check if ad fit in the remaining buffer */
if (set_data->len + ad[i].len + 1 > 29)
if (set_data->len + ad[i].len + 1 > 29) {
break;
}
memcpy(&set_data->data[set_data->len], &ad[i], ad[i].len + 1);
set_data->len += ad[i].len + 1;
@ -765,13 +792,15 @@ int bt_start_advertising(uint8_t type, const struct bt_eir *ad,
bt_hci_cmd_send(BT_HCI_OP_LE_SET_ADV_DATA, buf);
send_scan_rsp:
if (!sd)
if (!sd) {
goto send_set_param;
}
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_SCAN_RSP_DATA,
sizeof(*scan_rsp));
if (!buf)
if (!buf) {
return -ENOBUFS;
}
scan_rsp = (void *)bt_buf_add(buf, sizeof(*scan_rsp));
@ -779,8 +808,9 @@ send_scan_rsp:
for (i = 0; sd[i].len; i++) {
/* Check if ad fit in the remaining buffer */
if (scan_rsp->len + sd[i].len + 1 > 29)
if (scan_rsp->len + sd[i].len + 1 > 29) {
break;
}
memcpy(&scan_rsp->data[scan_rsp->len], &sd[i], sd[i].len + 1);
scan_rsp->len += sd[i].len + 1;
@ -791,8 +821,9 @@ send_scan_rsp:
send_set_param:
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_PARAMETERS,
sizeof(*set_param));
if (!buf)
if (!buf) {
return -ENOBUFS;
}
set_param = (void *)bt_buf_add(buf, sizeof(*set_param));
@ -805,8 +836,9 @@ send_set_param:
bt_hci_cmd_send(BT_HCI_OP_LE_SET_ADV_PARAMETERS, buf);
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
if (!buf)
if (!buf) {
return -ENOBUFS;
}
dev.adv_enable = 0x01;
memcpy(bt_buf_add(buf, 1), &dev.adv_enable, 1);

View file

@ -22,8 +22,9 @@ static uint8_t get_ident(struct bt_conn *conn)
conn->l2_ident++;
/* handle integer overflow (0 is not valid) */
if (!conn->l2_ident)
if (!conn->l2_ident) {
conn->l2_ident++;
}
return conn->l2_ident;
}
@ -35,8 +36,9 @@ struct bt_buf *bt_l2cap_create_pdu(struct bt_conn *conn, uint16_t cid,
struct bt_buf *buf;
buf = bt_conn_create_pdu(conn, sizeof(*hdr) + len);
if (!buf)
if (!buf) {
return NULL;
}
hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
hdr->len = sys_cpu_to_le16(len);
@ -53,8 +55,9 @@ static void rej_not_understood(struct bt_conn *conn, uint8_t ident)
buf = bt_l2cap_create_pdu(conn, BT_L2CAP_CID_LE_SIG,
sizeof(*hdr) + sizeof(*rej));
if (!buf)
if (!buf) {
return;
}
hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
hdr->code = BT_L2CAP_CMD_REJECT;
@ -157,13 +160,15 @@ void bt_l2cap_update_conn_param(struct bt_conn *conn)
/* Check if we need to update anything */
if (conn->le_conn_interval >= LE_CONN_MIN_INTERVAL &&
conn->le_conn_interval <= LE_CONN_MAX_INTERVAL)
conn->le_conn_interval <= LE_CONN_MAX_INTERVAL) {
return;
}
buf = bt_l2cap_create_pdu(conn, BT_L2CAP_CID_LE_SIG,
sizeof(*hdr) + sizeof(*req));
if (!buf)
if (!buf) {
return;
}
hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
hdr->code = BT_L2CAP_CONN_PARAM_REQ;