Skip to content

Commit

Permalink
style: tests: comply with MISRA C:2012 Rule 15.6
Browse files Browse the repository at this point in the history
Add missing braces to comply with MISRA C:2012 Rule 15.6 and
also following Zephyr's style guideline.

Signed-off-by: Pisit Sawangvonganan <[email protected]>
  • Loading branch information
ndrs-pst authored and nashif committed Sep 11, 2024
1 parent ead0dfc commit 442a068
Show file tree
Hide file tree
Showing 26 changed files with 287 additions and 144 deletions.
3 changes: 2 additions & 1 deletion tests/arch/common/timing/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ ZTEST(arch_timing, test_arch_timing_smp)
k_thread_start(&threads[i]);
}

for (i = 0; i < num_threads; i++)
for (i = 0; i < num_threads; i++) {
k_thread_join(&threads[i], K_FOREVER);
}
}
#else
ZTEST(arch_timing, test_arch_timing_smp)
Expand Down
18 changes: 12 additions & 6 deletions tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ static ssize_t write_value_v2(struct bt_conn *conn,
{
char *value = attr->user_data;

if (offset >= sizeof(value_v2_value))
if (offset >= sizeof(value_v2_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v2_value))
}
if (offset + len > sizeof(value_v2_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand All @@ -182,10 +184,12 @@ static ssize_t write_value_v2_1(struct bt_conn *conn,
{
char *value = attr->user_data;

if (offset >= sizeof(value_v2_1_value))
if (offset >= sizeof(value_v2_1_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v2_1_value))
}
if (offset + len > sizeof(value_v2_1_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand All @@ -211,10 +215,12 @@ static ssize_t write_value_v3(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v3_value))
if (offset >= sizeof(value_v3_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v3_value))
}
if (offset + len > sizeof(value_v3_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ static ssize_t write_value_v2(struct bt_conn *conn,
{
char *value = attr->user_data;

if (offset >= sizeof(value_v2_value))
if (offset >= sizeof(value_v2_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v2_value))
}
if (offset + len > sizeof(value_v2_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand All @@ -140,10 +142,12 @@ static ssize_t write_value_v3(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v3_value))
if (offset >= sizeof(value_v3_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v3_value))
}
if (offset + len > sizeof(value_v3_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ static ssize_t write_value_v2(struct bt_conn *conn,
{
char *value = attr->user_data;

if (offset >= sizeof(value_v2_value))
if (offset >= sizeof(value_v2_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v2_value))
}
if (offset + len > sizeof(value_v2_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand All @@ -140,10 +142,12 @@ static ssize_t write_value_v3(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v3_value))
if (offset >= sizeof(value_v3_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v3_value))
}
if (offset + len > sizeof(value_v3_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ static ssize_t write_value_v4(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v4_value))
if (offset >= sizeof(value_v4_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v4_value))
}
if (offset + len > sizeof(value_v4_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down Expand Up @@ -147,10 +149,12 @@ static ssize_t write_value_v4_1(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v4_1_value))
if (offset >= sizeof(value_v4_1_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v4_1_value))
}
if (offset + len > sizeof(value_v4_1_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down Expand Up @@ -204,10 +208,12 @@ static ssize_t write_server_cha_con(struct bt_conn *conn,
uint16_t *value = attr->user_data;
uint16_t server_cha_con_conv = sys_cpu_to_le16(*value);

if (offset >= sizeof(server_cha_con_value))
if (offset >= sizeof(server_cha_con_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(server_cha_con_value))
}
if (offset + len > sizeof(server_cha_con_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy((uint8_t *)&server_cha_con_conv + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ static ssize_t write_value_v4(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v4_value))
if (offset >= sizeof(value_v4_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v4_value))
}
if (offset + len > sizeof(value_v4_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ static ssize_t write_value_v4(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v4_value))
if (offset >= sizeof(value_v4_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v4_value))
}
if (offset + len > sizeof(value_v4_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ static ssize_t write_value_v5(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v5_value))
if (offset >= sizeof(value_v5_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v5_value))
}
if (offset + len > sizeof(value_v5_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
if (!bAuthorized)
}
if (!bAuthorized) {
return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ static ssize_t write_value_v5(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v5_value))
if (offset >= sizeof(value_v5_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v5_value))
}
if (offset + len > sizeof(value_v5_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ static ssize_t write_value_v5(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v5_value))
if (offset >= sizeof(value_v5_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v5_value))
}
if (offset + len > sizeof(value_v5_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ static ssize_t write_value_v6(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v6_value))
if (offset >= sizeof(value_v6_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v6_value))
}
if (offset + len > sizeof(value_v6_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ static ssize_t write_value_v6(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v6_value))
if (offset >= sizeof(value_v6_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v6_value))
}
if (offset + len > sizeof(value_v6_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ static ssize_t write_value_v7(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v7_value))
if (offset >= sizeof(value_v7_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v7_value))
}
if (offset + len > sizeof(value_v7_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ static ssize_t write_value_v7(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v7_value))
if (offset >= sizeof(value_v7_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v7_value))
}
if (offset + len > sizeof(value_v7_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ static ssize_t write_value_v7(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v7_value))
if (offset >= sizeof(value_v7_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v7_value))
}
if (offset + len > sizeof(value_v7_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
30 changes: 20 additions & 10 deletions tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ static ssize_t write_value_v8(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(value_v8_value))
if (offset >= sizeof(value_v8_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(value_v8_value))
}
if (offset + len > sizeof(value_v8_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down Expand Up @@ -139,10 +141,12 @@ static ssize_t write_des_v8d1(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(des_v8d1_value))
if (offset >= sizeof(des_v8d1_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(des_v8d1_value))
}
if (offset + len > sizeof(des_v8d1_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand All @@ -167,8 +171,9 @@ static ssize_t read_des_v8d2(struct bt_conn *conn,
{
const uint8_t *value = attr->user_data;

if (!bAuthorized)
if (!bAuthorized) {
return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION);
}

return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
sizeof(des_v8d2_value));
Expand All @@ -193,12 +198,15 @@ static ssize_t write_des_v8d2(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(des_v8d2_value))
if (offset >= sizeof(des_v8d2_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(des_v8d2_value))
}
if (offset + len > sizeof(des_v8d2_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
if (!bAuthorized)
}
if (!bAuthorized) {
return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION);
}

memcpy(value + offset, buf, len);

Expand Down Expand Up @@ -246,10 +254,12 @@ static ssize_t write_des_v8d3(struct bt_conn *conn,
{
uint8_t *value = attr->user_data;

if (offset >= sizeof(des_v8d3_value))
if (offset >= sizeof(des_v8d3_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
if (offset + len > sizeof(des_v8d3_value))
}
if (offset + len > sizeof(des_v8d3_value)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value + offset, buf, len);

Expand Down
Loading

0 comments on commit 442a068

Please sign in to comment.