Correct comments and some redundant statements.
diff --git a/system/stack/gatt/gatt_api.c b/system/stack/gatt/gatt_api.c
index 6683cb6..32e5ffc 100644
--- a/system/stack/gatt/gatt_api.c
+++ b/system/stack/gatt/gatt_api.c
@@ -1323,7 +1323,7 @@
**
** Parameter gatt_if: applicaiton interface.
**
-** Returns 0 for error, otherwise the index of the client registered with GATT
+** Returns None.
**
*******************************************************************************/
void GATT_StartIf (tGATT_IF gatt_if)
@@ -1338,7 +1338,6 @@
GATT_TRACE_API ("GATT_StartIf gatt_if=%d", gatt_if);
if ((p_reg = gatt_get_regcb(gatt_if)) != NULL)
{
- p_reg = &gatt_cb.cl_rcb[gatt_if - 1];
start_idx = 0;
while (gatt_find_the_connected_bda(start_idx, bda, &found_idx, &transport))
{
diff --git a/system/stack/gatt/gatt_utils.c b/system/stack/gatt/gatt_utils.c
index f0658ea..11d8dff 100644
--- a/system/stack/gatt/gatt_utils.c
+++ b/system/stack/gatt/gatt_utils.c
@@ -1562,15 +1562,20 @@
UINT8 ii = (UINT8)gatt_if;
tGATT_REG *p_reg = NULL;
- if (ii)
- {
- ii--; /* convert from one based to zero based */
- p_reg = &gatt_cb.cl_rcb[ii];
- if ( (ii < GATT_MAX_APPS) && (p_reg->in_use) )
- return(p_reg);
+ if (ii < 1 || ii > GATT_MAX_APPS) {
+ GATT_TRACE_WARNING("gatt_if out of range [ = %d]", ii);
+ return NULL;
}
- return NULL;
+ // Index for cl_rcb is always 1 less than gatt_if.
+ p_reg = &gatt_cb.cl_rcb[ii - 1];
+
+ if (!p_reg->in_use) {
+ GATT_TRACE_WARNING("gatt_if found but not in use.");
+ return NULL;
+ }
+
+ return p_reg;
}