From bb34c219ce6e73f6408918b2a47e727021234200 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Thu, 4 Feb 2016 12:02:51 +0200 Subject: [PATCH] drivers/nble: gatt: Fix loosing errcode and wrong comparision Fix assigning negative error code to unsigned int and then compare it against zero. Change-Id: Idedaf91dda20a38806ee81d5c488ae8b46c8feff Signed-off-by: Andrei Emeltchenko --- drivers/nble/gatt.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/nble/gatt.c b/drivers/nble/gatt.c index cd54f8c8d3b..7a24c9c1d99 100644 --- a/drivers/nble/gatt.c +++ b/drivers/nble/gatt.c @@ -127,6 +127,7 @@ int bt_gatt_register(struct bt_gatt_attr *attrs, size_t count) for (i = 0; i < count; i++) { struct bt_gatt_attr *attr = &attrs[i]; struct ble_gatt_attr *att; + int err; if (attr_table_size + sizeof(*att) > sizeof(attr_table)) { return -ENOMEM; @@ -138,14 +139,15 @@ int bt_gatt_register(struct bt_gatt_attr *attrs, size_t count) attr_table_size += sizeof(*att); /* Read attribute data */ - att->data_size = attr_read(attr, att->data, - sizeof(attr_table) - - attr_table_size); - if (att->data_size < 0) { - BT_ERR("Failed to read attr: %d", att->data_size); - return att->data_size; + err = attr_read(attr, att->data, + sizeof(attr_table) - attr_table_size); + if (err < 0) { + BT_ERR("Failed to read attr: %d", err); + return err; } + att->data_size = err; + /* Compute the new element size and align it on upper 4 bytes * boundary. */