Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f8f2a47 authored by Pomai Ahlo's avatar Pomai Ahlo
Browse files

Log when find_rfc_slot_by_id returns NULL

Delete error log in find_rfc_slot_by_id and instead log an error or
warning where appropriate whenever find_rfc_slot_by_id is called.

Bug: 295023364
Test: m Bluetooth
Change-Id: I8412e26c291b6ee853fbdd56fc65a3d0fbc2189f
parent 5400d131
Loading
Loading
Loading
Loading
+53 −11
Original line number Diff line number Diff line
@@ -155,7 +155,6 @@ static rfc_slot_t* find_rfc_slot_by_id(uint32_t id) {
  for (size_t i = 0; i < ARRAY_SIZE(rfc_slots); ++i)
    if (rfc_slots[i].id == id) return &rfc_slots[i];

  LOG_ERROR("%s unable to find RFCOMM slot id: %u", __func__, id);
  return NULL;
}

@@ -487,11 +486,17 @@ static bool send_app_connect_signal(int fd, const RawAddress* addr, int channel,
static void on_cl_rfc_init(tBTA_JV_RFCOMM_CL_INIT* p_init, uint32_t id) {
  std::unique_lock<std::recursive_mutex> lock(slot_lock);
  rfc_slot_t* slot = find_rfc_slot_by_id(id);
  if (!slot) return;
  if (!slot) {
    LOG_ERROR("RFCOMM slot with id %u not found. p_init->status=%u", id,
              p_init->status);
    return;
  }

  if (p_init->status == BTA_JV_SUCCESS) {
    slot->rfc_handle = p_init->handle;
  } else {
    LOG_WARN("INIT unsuccessful, status %u. Cleaning up slot with id %u",
             p_init->status, slot->id);
    cleanup_rfc_slot(slot);
  }
}
@@ -500,7 +505,10 @@ static void on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START* p_start,
                                      uint32_t id) {
  std::unique_lock<std::recursive_mutex> lock(slot_lock);
  rfc_slot_t* slot = find_rfc_slot_by_id(id);
  if (!slot) return;
  if (!slot) {
    LOG_ERROR("RFCOMM slot with id %u not found", id);
    return;
  }

  if (p_start->status == BTA_JV_SUCCESS) {
    slot->rfc_handle = p_start->handle;
@@ -516,6 +524,8 @@ static void on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START* p_start,
        slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN
                       : android::bluetooth::SOCKET_ROLE_CONNECTION);
  } else {
    LOG_WARN("START unsuccessful, status %u. Cleaning up slot with id %u",
             p_start->status, slot->id);
    cleanup_rfc_slot(slot);
  }
}
@@ -525,7 +535,10 @@ static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open,
  std::unique_lock<std::recursive_mutex> lock(slot_lock);
  rfc_slot_t* accept_rs;
  rfc_slot_t* srv_rs = find_rfc_slot_by_id(id);
  if (!srv_rs) return 0;
  if (!srv_rs) {
    LOG_ERROR("RFCOMM slot with id %u not found.", id);
    return 0;
  }

  accept_rs = create_srv_accept_rfc_slot(
      srv_rs, &p_open->rem_bda, p_open->handle, p_open->new_listen_handle);
@@ -557,9 +570,14 @@ static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open,
static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN* p_open, uint32_t id) {
  std::unique_lock<std::recursive_mutex> lock(slot_lock);
  rfc_slot_t* slot = find_rfc_slot_by_id(id);
  if (!slot) return;
  if (!slot) {
    LOG_ERROR("RFCOMM slot with id %u not found.", id);
    return;
  }

  if (p_open->status != BTA_JV_SUCCESS) {
    LOG_WARN("CONNECT unsuccessful, status %u. Cleaning up slot with id %u",
             p_open->status, slot->id);
    cleanup_rfc_slot(slot);
    return;
  }
@@ -599,6 +617,8 @@ static void on_rfc_close(UNUSED_ATTR tBTA_JV_RFCOMM_CLOSE* p_close,
        slot->f.server ? android::bluetooth::SOCKET_ROLE_LISTEN
                       : android::bluetooth::SOCKET_ROLE_CONNECTION);
    cleanup_rfc_slot(slot);
  } else {
    LOG_WARN("RFCOMM slot with id %u not found.", id);
  }
}

@@ -620,6 +640,8 @@ static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE* p, uint32_t id) {
                           slot->id);
    }
    slot->tx_bytes += p->len;
  } else {
    LOG_ERROR("RFCOMM slot with id %u not found.", id);
  }

  uid_set_add_tx(uid_set, app_uid, p->len);
@@ -634,6 +656,8 @@ static void on_rfc_outgoing_congest(tBTA_JV_RFCOMM_CONG* p, uint32_t id) {
    if (!slot->f.outgoing_congest)
      btsock_thread_add_fd(pth, slot->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD,
                           slot->id);
  } else {
    LOG_ERROR("RFCOMM slot with id %u not found.", id);
  }
}

@@ -733,6 +757,8 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
            "jv_dm_cback: Error: allocate channel %d, slot found:%p", rs->scn,
            rs);
        cleanup_rfc_slot(rs);
      } else {
        LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event);
      }
      break;
    }
@@ -753,6 +779,8 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
        APPL_TRACE_ERROR("jv_dm_cback: cannot start server, slot found:%p",
                         slot);
        cleanup_rfc_slot(slot);
      } else {
        LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event);
      }
      break;
    }
@@ -783,6 +811,8 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id) {
        }
      } else if (slot) {
        cleanup_rfc_slot(slot);
      } else {
        LOG_ERROR("RFCOMM slot with id %u not found. event:%d", id, event);
      }

      // Find the next slot that needs to perform an SDP request and service it.
@@ -861,11 +891,14 @@ static bool flush_incoming_que_on_wr_signal(rfc_slot_t* slot) {
  return true;
}

void btsock_rfc_signaled(UNUSED_ATTR int fd, int flags, uint32_t user_id) {
void btsock_rfc_signaled(UNUSED_ATTR int fd, int flags, uint32_t id) {
  bool need_close = false;
  std::unique_lock<std::recursive_mutex> lock(slot_lock);
  rfc_slot_t* slot = find_rfc_slot_by_id(user_id);
  if (!slot) return;
  rfc_slot_t* slot = find_rfc_slot_by_id(id);
  if (!slot) {
    LOG_ERROR("RFCOMM slot with id %u not found.", id);
    return;
  }

  // Data available from app, tell stack we have outgoing data.
  if (flags & SOCK_THREAD_FD_RD && !slot->f.server) {
@@ -910,7 +943,10 @@ int bta_co_rfc_data_incoming(uint32_t id, BT_HDR* p_buf) {
  int ret = 0;
  std::unique_lock<std::recursive_mutex> lock(slot_lock);
  rfc_slot_t* slot = find_rfc_slot_by_id(id);
  if (!slot) return 0;
  if (!slot) {
    LOG_ERROR("RFCOMM slot with id %u not found.", id);
    return 0;
  }

  app_uid = slot->app_uid;
  bytes_rx = p_buf->len;
@@ -948,7 +984,10 @@ int bta_co_rfc_data_outgoing_size(uint32_t id, int* size) {
  *size = 0;
  std::unique_lock<std::recursive_mutex> lock(slot_lock);
  rfc_slot_t* slot = find_rfc_slot_by_id(id);
  if (!slot) return false;
  if (!slot) {
    LOG_ERROR("RFCOMM slot with id %u not found.", id);
    return false;
  }

  if (ioctl(slot->fd, FIONREAD, size) != 0) {
    LOG_ERROR("%s unable to determine bytes remaining to be read on fd %d: %s",
@@ -963,7 +1002,10 @@ int bta_co_rfc_data_outgoing_size(uint32_t id, int* size) {
int bta_co_rfc_data_outgoing(uint32_t id, uint8_t* buf, uint16_t size) {
  std::unique_lock<std::recursive_mutex> lock(slot_lock);
  rfc_slot_t* slot = find_rfc_slot_by_id(id);
  if (!slot) return false;
  if (!slot) {
    LOG_ERROR("RFCOMM slot with id %u not found.", id);
    return false;
  }

  ssize_t received;
  OSI_NO_INTR(received = recv(slot->fd, buf, size, 0));