diff options
author | Szymon Janc <szymon.janc@codecoup.pl> | 2015-10-16 12:24:09 +0200 |
---|---|---|
committer | Szymon Janc <szymon.janc@codecoup.pl> | 2015-10-30 11:44:19 +0100 |
commit | 97075679fe12d96fb433a1cac860e5dd90538e72 (patch) | |
tree | ce21f4b709249050f4153b7acf057bdb66c2ca52 /android/gatt.c | |
parent | 962285c7cf3719e59db1a351ae615e87d3f242ad (diff) | |
download | bluez-97075679fe12d96fb433a1cac860e5dd90538e72.tar.gz |
android: Remove dead code
This removes dead code due to memory allocation with new0 not being
able to fail.
Diffstat (limited to 'android/gatt.c')
-rw-r--r-- | android/gatt.c | 336 |
1 files changed, 34 insertions, 302 deletions
diff --git a/android/gatt.c b/android/gatt.c index 65f314228..28635edf4 100644 --- a/android/gatt.c +++ b/android/gatt.c @@ -744,37 +744,14 @@ static struct gatt_device *create_device(const bdaddr_t *addr) struct gatt_device *dev; dev = new0(struct gatt_device, 1); - if (!dev) - return NULL; bacpy(&dev->bdaddr, addr); dev->services = queue_new(); - if (!dev->services) { - error("gatt: Failed to allocate memory for client"); - destroy_device(dev); - return NULL; - } - dev->autoconnect_apps = queue_new(); - if (!dev->autoconnect_apps) { - error("gatt: Failed to allocate memory for client"); - destroy_device(dev); - return NULL; - } - dev->pending_requests = queue_new(); - if (!dev->pending_requests) { - error("gatt: Failed to allocate memory for client"); - destroy_device(dev); - return NULL; - } - if (!queue_push_head(gatt_devices, dev)) { - error("gatt: Cannot push device to queue"); - destroy_device(dev); - return NULL; - } + queue_push_head(gatt_devices, dev); return device_ref(dev); } @@ -1116,25 +1093,13 @@ static struct app_connection *create_connection(struct gatt_device *device, /* Check if already connected */ new_conn = new0(struct app_connection, 1); - if (!new_conn) - return NULL; /* Make connection id unique to connection record (app, device) pair */ new_conn->app = app; new_conn->id = last_conn_id++; - new_conn->transactions = queue_new(); - if (!new_conn->transactions) { - free(new_conn); - return NULL; - } - if (!queue_push_head(app_connections, new_conn)) { - error("gatt: Cannot push client on the client queue!?"); - queue_destroy(new_conn->transactions, free); - free(new_conn); - return NULL; - } + queue_push_head(app_connections, new_conn); new_conn->device = device_ref(device); @@ -1147,33 +1112,15 @@ static struct service *create_service(uint8_t id, bool primary, char *uuid, struct service *s; s = new0(struct service, 1); - if (!s) { - error("gatt: Cannot allocate memory for gatt_primary"); - return NULL; - } - - s->chars = queue_new(); - if (!s->chars) { - error("gatt: Cannot allocate memory for char cache"); - free(s); - return NULL; - } - - s->included = queue_new(); - if (!s->included) { - error("gatt: Cannot allocate memory for included queue"); - queue_destroy(s->chars, NULL); - free(s); - return NULL; - } if (bt_string_to_uuid(&s->id.uuid, uuid) < 0) { error("gatt: Cannot convert string to uuid"); - queue_destroy(s->chars, NULL); free(s); return NULL; } + s->chars = queue_new(); + s->included = queue_new(); s->id.instance = id; /* Put primary service to our local list */ @@ -1256,12 +1203,7 @@ static void discover_srvc_by_uuid_cb(uint8_t status, GSList *ranges, goto reply; } - if (!queue_push_tail(dev->services, s)) { - error("gatt: Cannot push primary service to the list"); - destroy_service(s); - gatt_status = GATT_FAILURE; - goto reply; - } + queue_push_tail(dev->services, s); send_client_primary_notify(s, INT_TO_PTR(cb_data->conn->id)); @@ -1318,11 +1260,7 @@ static void discover_srvc_all_cb(uint8_t status, GSList *services, if (!p) continue; - if (!queue_push_tail(dev->services, p)) { - error("gatt: Cannot push primary service to the list"); - free(p); - continue; - } + queue_push_tail(dev->services, p); DBG("attr handle = 0x%04x, end grp handle = 0x%04x uuid: %s", prim->range.start, prim->range.end, prim->uuid); @@ -1412,11 +1350,6 @@ static guint search_dev_for_srvc(struct app_connection *conn, bt_uuid_t *uuid) struct discover_srvc_data *cb_data; cb_data = new0(struct discover_srvc_data, 1); - if (!cb_data) { - error("gatt: Cannot allocate cb data"); - return 0; - } - cb_data->conn = conn; if (uuid) { @@ -1779,7 +1712,7 @@ done: dev = create_device(addr); } - if (!dev || dev->state != DEVICE_CONNECT_INIT) + if (dev->state != DEVICE_CONNECT_INIT) return; device_set_state(dev, DEVICE_CONNECT_READY); @@ -1802,38 +1735,20 @@ static struct gatt_app *register_app(const uint8_t *uuid, gatt_type_t type) } app = new0(struct gatt_app, 1); - if (!app) { - error("gatt: Cannot allocate memory for registering app"); - return NULL; - } app->type = type; - if (app->type == GATT_CLIENT) { + if (app->type == GATT_CLIENT) app->notifications = queue_new(); - if (!app->notifications) { - error("gatt: couldn't allocate notifications queue"); - destroy_gatt_app(app); - return NULL; - } - } memcpy(app->uuid, uuid, sizeof(app->uuid)); app->id = application_id++; - if (!queue_push_head(gatt_apps, app)) { - error("gatt: Cannot push app on the list"); - destroy_gatt_app(app); - return NULL; - } + queue_push_head(gatt_apps, app); - if ((app->type == GATT_SERVER) && - !queue_push_tail(listen_apps, INT_TO_PTR(app->id))) { - error("gatt: Cannot push server on the list"); - destroy_gatt_app(app); - return NULL; - } + if (app->type == GATT_SERVER) + queue_push_tail(listen_apps, INT_TO_PTR(app->id)); return app; } @@ -2056,9 +1971,6 @@ static struct listen_data *create_listen_data(int32_t client_id, bool start) struct listen_data *d; d = new0(struct listen_data, 1); - if (!d) - return NULL; - d->client_id = client_id; d->start = start; @@ -2108,11 +2020,6 @@ static void handle_client_unregister(const void *buf, uint16_t len) if (!advertising_cnt) { data = create_listen_data(cmd->client_if, false); - if (!data) { - error("gatt: Could not allocate listen data"); - status = HAL_STATUS_NOMEM; - goto reply; - } if (!bt_le_set_advertising(data->start, set_advertising_cb, data)) { @@ -2144,11 +2051,8 @@ static uint8_t handle_connect(int32_t app_id, const bdaddr_t *addr, bool direct) return HAL_STATUS_FAILED; device = find_device_by_addr(addr); - if (!device) { + if (!device) device = create_device(addr); - if (!device) - return HAL_STATUS_FAILED; - } conn_match.device = device; conn_match.app = app; @@ -2229,12 +2133,7 @@ static void handle_client_listen(const void *buf, uint16_t len) goto reply; } - if (!queue_push_tail(listen_apps, - INT_TO_PTR(cmd->client_if))) { - error("gatt: Could not put client on listen queue"); - status = HAL_STATUS_FAILED; - goto reply; - } + queue_push_tail(listen_apps, INT_TO_PTR(cmd->client_if)); /* If listen is already on just return success*/ if (advertising_cnt > 0) { @@ -2264,11 +2163,6 @@ static void handle_client_listen(const void *buf, uint16_t len) } data = create_listen_data(cmd->client_if, cmd->start); - if (!data) { - error("gatt: Could not allocate listen data"); - status = HAL_STATUS_NOMEM; - goto reply; - } if (!bt_le_set_advertising(cmd->start, set_advertising_cb, data)) { error("gatt: Could not set advertising"); @@ -2507,12 +2401,8 @@ static void get_included_cb(uint8_t status, GSList *included, void *user_data) * 1. on services queue together with primary service * 2. on special queue inside primary service */ - if (!queue_push_tail(service->included, incl) || - !queue_push_tail(conn->device->services, incl)) { - error("gatt: Cannot push incl service to the list"); - destroy_service(incl); - continue; - } + queue_push_tail(service->included, incl); + queue_push_tail(conn->device->services, incl); } /* @@ -2525,18 +2415,13 @@ failed: send_client_incl_service_notify(&service->id, incl, conn->id); } -static bool search_included_services(struct app_connection *conn, +static void search_included_services(struct app_connection *conn, struct service *service) { struct get_included_data *data; uint16_t start, end; data = new0(struct get_included_data, 1); - if (!data) { - error("gatt: failed to allocate memory for included_data"); - return false; - } - data->prim = service; data->conn = conn; @@ -2550,8 +2435,6 @@ static bool search_included_services(struct app_connection *conn, gatt_find_included(conn->device->attrib, start, end, get_included_cb, data); - - return true; } static bool find_service(int32_t conn_id, struct element_id *service_id, @@ -2610,13 +2493,9 @@ static void handle_client_get_included_service(const void *buf, uint16_t len) } if (!prim_service->incl_search_done) { - if (search_included_services(conn, prim_service)) { - status = HAL_STATUS_SUCCESS; - goto reply; - } - - status = HAL_STATUS_FAILED; - goto notify; + search_included_services(conn, prim_service); + status = HAL_STATUS_SUCCESS; + goto reply; } /* Try to use cache here */ @@ -2696,17 +2575,7 @@ static void cache_all_srvc_chars(struct service *srvc, GSList *characteristics) struct characteristic *ch; ch = new0(struct characteristic, 1); - if (!ch) { - error("gatt: Error while caching characteristic"); - continue; - } - ch->descriptors = queue_new(); - if (!ch->descriptors) { - error("gatt: Error while caching characteristic"); - free(ch); - continue; - } memcpy(&ch->ch, characteristics->data, sizeof(ch->ch)); @@ -2732,10 +2601,7 @@ static void cache_all_srvc_chars(struct service *srvc, GSList *characteristics) DBG("attr handle = 0x%04x, end handle = 0x%04x uuid: %s", ch->ch.handle, ch->end_handle, ch->ch.uuid); - if (!queue_push_tail(srvc->chars, ch)) { - error("gatt: Error while caching characteristic"); - destroy_characteristic(ch); - } + queue_push_tail(srvc->chars, ch); } } @@ -2797,12 +2663,6 @@ static void handle_client_get_characteristic(const void *buf, uint16_t len) struct att_range range; cb_data = new0(struct discover_char_data, 1); - if (!cb_data) { - error("gatt: Cannot allocate cb data"); - status = HAL_STATUS_FAILED; - goto done; - } - cb_data->service = srvc; cb_data->conn_id = conn->id; @@ -2889,8 +2749,6 @@ static void gatt_discover_desc_cb(guint8 status, GSList *descs, bt_uuid_t uuid; descr = new0(struct descriptor, 1); - if (!descr) - continue; bt_string_to_uuid(&uuid, desc->uuid); bt_uuid_to_uuid128(&uuid, &descr->id.uuid); @@ -2900,8 +2758,7 @@ static void gatt_discover_desc_cb(guint8 status, GSList *descs, DBG("attr handle = 0x%04x, uuid: %s", desc->handle, desc->uuid); - if (!queue_push_tail(ch->descriptors, descr)) - free(descr); + queue_push_tail(ch->descriptors, descr); } reply: @@ -2929,9 +2786,6 @@ static bool build_descr_cache(struct app_connection *conn, struct service *srvc, return false; cb_data = new0(struct discover_desc_data, 1); - if (!cb_data) - return false; - cb_data->conn = conn; cb_data->srvc = srvc; cb_data->ch = ch; @@ -3033,9 +2887,6 @@ static struct char_op_data *create_char_op_data(int32_t conn_id, struct char_op_data *d; d = new0(struct char_op_data, 1); - if (!d) - return NULL; - d->conn_id = conn_id; d->srvc_id = s_id; d->char_id = ch_id; @@ -3216,11 +3067,6 @@ static void handle_client_read_characteristic(const void *buf, uint16_t len) cb_data = create_char_op_data(cmd->conn_id, &srvc->id, &ch->id, cmd->srvc_id.is_primary); - if (!cb_data) { - error("gatt: Cannot allocate cb data"); - status = HAL_STATUS_NOMEM; - goto failed; - } if (!set_auth_type(conn->device, cmd->auth_req)) { error("gatt: Failed to set security %d", cmd->auth_req); @@ -3354,11 +3200,6 @@ static void handle_client_write_characteristic(const void *buf, uint16_t len) cmd->write_type == GATT_WRITE_TYPE_DEFAULT) { cb_data = create_char_op_data(cmd->conn_id, &srvc->id, &ch->id, cmd->srvc_id.is_primary); - if (!cb_data) { - error("gatt: Cannot allocate call data"); - status = HAL_STATUS_NOMEM; - goto failed; - } } if (!set_auth_type(conn->device, cmd->auth_req)) { @@ -3507,9 +3348,6 @@ static struct desc_data *create_desc_data(int32_t conn_id, struct desc_data *d; d = new0(struct desc_data, 1); - if (!d) - return NULL; - d->conn_id = conn_id; d->srvc_id = s_id; d->char_id = ch_id; @@ -3569,12 +3407,6 @@ static void handle_client_read_descriptor(const void *buf, uint16_t len) cb_data = create_desc_data(conn_id, &srvc->id, &ch->id, &descr->id, primary); - if (!cb_data) { - error("gatt: Read descr. could not allocate callback data"); - - status = HAL_STATUS_NOMEM; - goto failed; - } if (!set_auth_type(conn->device, cmd->auth_req)) { error("gatt: Failed to set security %d", cmd->auth_req); @@ -3698,16 +3530,9 @@ static void handle_client_write_descriptor(const void *buf, uint16_t len) goto failed; } - if (cmd->write_type != GATT_WRITE_TYPE_NO_RESPONSE) { + if (cmd->write_type != GATT_WRITE_TYPE_NO_RESPONSE) cb_data = create_desc_data(conn_id, &srvc->id, &ch->id, &descr->id, primary); - if (!cb_data) { - error("gatt: Write descr. could not allocate cb_data"); - - status = HAL_STATUS_NOMEM; - goto failed; - } - } if (!set_auth_type(conn->device, cmd->auth_req)) { error("gatt: Failed to set security %d", cmd->auth_req); @@ -3897,10 +3722,6 @@ static void handle_client_register_for_notification(const void *buf, } notification = new0(struct notification_data, 1); - if (!notification) { - status = HAL_STATUS_NOMEM; - goto failed; - } memcpy(¬ification->ch, &cmd->char_id, sizeof(notification->ch)); memcpy(¬ification->service, &cmd->srvc_id, @@ -3947,11 +3768,7 @@ static void handle_client_register_for_notification(const void *buf, */ notification->ref = 2; - if (!queue_push_tail(conn->app->notifications, notification)) { - unregister_notification(notification); - status = HAL_STATUS_FAILED; - goto failed; - } + queue_push_tail(conn->app->notifications, notification); status = HAL_STATUS_SUCCESS; @@ -4503,8 +4320,6 @@ static void send_dev_complete_response(struct gatt_device *device, struct queue *temp; temp = queue_new(); - if (!temp) - goto done; val = queue_pop_head(device->pending_requests); if (!val) { @@ -4567,8 +4382,6 @@ static void send_dev_complete_response(struct gatt_device *device, struct queue *temp; temp = queue_new(); - if (!temp) - goto done; val = queue_pop_head(device->pending_requests); if (!val) { @@ -4630,12 +4443,6 @@ static void send_dev_complete_response(struct gatt_device *device, } range = new0(struct att_range, 1); - if (!range) { - destroy_pending_request(val); - error = ATT_ECODE_INSUFF_RESOURCES; - break; - } - range->start = gatt_db_attribute_get_handle( val->attrib); @@ -4878,19 +4685,13 @@ static struct pending_trans_data *conn_add_transact(struct app_connection *conn, static int32_t trans_id = 1; transaction = new0(struct pending_trans_data, 1); - if (!transaction) - return NULL; - - if (!queue_push_tail(conn->transactions, transaction)) { - free(transaction); - return NULL; - } - transaction->id = trans_id++; transaction->opcode = opcode; transaction->attrib = attrib; transaction->serial_id = serial_id; + queue_push_tail(conn->transactions, transaction); + return transaction; } @@ -4949,8 +4750,6 @@ static void read_cb(struct gatt_db_attribute *attrib, unsigned int id, /* Store the request data, complete callback and transaction id */ transaction = conn_add_transact(conn, opcode, attrib, id); - if (!transaction) - goto failed; bdaddr2android(&bdaddr, ev.bdaddr); ev.conn_id = conn->id; @@ -5009,8 +4808,6 @@ static void write_cb(struct gatt_db_attribute *attrib, unsigned int id, /* Store the request data, complete callback and transaction id */ transaction = conn_add_transact(conn, opcode, attrib, id); - if (!transaction) - goto failed; memset(ev, 0, sizeof(*ev)); @@ -5313,9 +5110,6 @@ static struct service_sdp *new_service_sdp_record(int32_t service_handle) return NULL; s = new0(struct service_sdp, 1); - if (!s) - return NULL; - s->service_handle = service_handle; s->sdp_handle = add_sdp_record(&uuid, service_handle, end_handle, NULL); if (!s->sdp_handle) { @@ -5350,10 +5144,7 @@ static bool add_service_sdp_record(int32_t service_handle) if (!s) return false; - if (!queue_push_tail(services_sdp, s)) { - free_service_sdp_record(s); - return false; - } + queue_push_tail(services_sdp, s); return true; } @@ -6080,8 +5871,6 @@ static uint8_t read_by_type(const uint8_t *cmd, uint16_t cmd_len, return ATT_ECODE_INVALID_HANDLE; q = queue_new(); - if (!q) - return ATT_ECODE_INSUFF_RESOURCES; switch (cmd[0]) { case ATT_OP_READ_BY_TYPE_REQ: @@ -6104,17 +5893,8 @@ static uint8_t read_by_type(const uint8_t *cmd, uint16_t cmd_len, struct gatt_db_attribute *attrib = queue_pop_head(q); data = new0(struct pending_request, 1); - if (!data) { - queue_destroy(q, NULL); - return ATT_ECODE_INSUFF_RESOURCES; - } - data->attrib = attrib; - if (!queue_push_tail(device->pending_requests, data)) { - free(data); - queue_destroy(q, NULL); - return ATT_ECODE_INSUFF_RESOURCES; - } + queue_push_tail(device->pending_requests, data); } queue_destroy(q, NULL); @@ -6156,15 +5936,9 @@ static uint8_t read_request(const uint8_t *cmd, uint16_t cmd_len, return ATT_ECODE_INVALID_HANDLE; data = new0(struct pending_request, 1); - if (!data) - return ATT_ECODE_INSUFF_RESOURCES; - data->offset = offset; data->attrib = attrib; - if (!queue_push_tail(dev->pending_requests, data)) { - free(data); - return ATT_ECODE_INSUFF_RESOURCES; - } + queue_push_tail(dev->pending_requests, data); process_dev_pending_requests(dev, cmd[0]); @@ -6226,8 +6000,6 @@ static uint8_t find_info_handle(const uint8_t *cmd, uint16_t cmd_len, return ATT_ECODE_INVALID_HANDLE; q = queue_new(); - if (!q) - return ATT_ECODE_UNLIKELY; gatt_db_find_information(gatt_db, start, end, q); @@ -6237,10 +6009,6 @@ static uint8_t find_info_handle(const uint8_t *cmd, uint16_t cmd_len, } temp = queue_new(); - if (!temp) { - queue_destroy(q, NULL); - return ATT_ECODE_UNLIKELY; - } attrib = queue_peek_head(q); /* UUIDS can be only 128 bit and 16 bit */ @@ -6321,11 +6089,6 @@ static void find_by_type_request_cb(struct gatt_db_attribute *attrib, return; request_data = new0(struct pending_request, 1); - if (!request_data) { - find_data->error = ATT_ECODE_INSUFF_RESOURCES; - return; - } - request_data->filter_value = malloc0(find_data->search_vlen); if (!request_data->filter_value) { destroy_pending_request(request_data); @@ -6338,11 +6101,7 @@ static void find_by_type_request_cb(struct gatt_db_attribute *attrib, memcpy(request_data->filter_value, find_data->search_value, find_data->search_vlen); - if (!queue_push_tail(find_data->device->pending_requests, - request_data)) { - destroy_pending_request(request_data); - find_data->error = ATT_ECODE_INSUFF_RESOURCES; - } + queue_push_tail(find_data->device->pending_requests, request_data); } static uint8_t find_by_type_request(const uint8_t *cmd, uint16_t cmd_len, @@ -6511,7 +6270,6 @@ static void attribute_write_cb(struct gatt_db_attribute *attrib, int err, data->attrib = attrib; data->error = error; - data->completed = true; } @@ -6545,15 +6303,9 @@ static uint8_t write_req_request(const uint8_t *cmd, uint16_t cmd_len, return error; data = new0(struct pending_request, 1); - if (!data) - return ATT_ECODE_INSUFF_RESOURCES; - data->attrib = attrib; - if (!queue_push_tail(dev->pending_requests, data)) { - free(data); - return ATT_ECODE_INSUFF_RESOURCES; - } + queue_push_tail(dev->pending_requests, data); if (!gatt_db_attribute_write(attrib, 0, value, vlen, cmd[0], g_attrib_get_att(dev->attrib), @@ -6600,16 +6352,10 @@ static uint8_t write_prep_request(const uint8_t *cmd, uint16_t cmd_len, return error; data = new0(struct pending_request, 1); - if (!data) - return ATT_ECODE_INSUFF_RESOURCES; - data->attrib = attrib; data->offset = offset; - if (!queue_push_tail(dev->pending_requests, data)) { - free(data); - return ATT_ECODE_INSUFF_RESOURCES; - } + queue_push_tail(dev->pending_requests, data); data->value = g_memdup(value, vlen); data->length = vlen; @@ -6641,10 +6387,6 @@ static void send_server_write_execute_notify(void *data, void *user_data) ev->conn_id = conn->id; transaction = conn_add_transact(conn, ATT_OP_EXEC_WRITE_REQ, NULL, 0); - if (!transaction) { - conn->wait_execute_write = false; - return; - } ev->trans_id = transaction->id; @@ -6674,13 +6416,8 @@ static uint8_t write_execute_request(const uint8_t *cmd, uint16_t cmd_len, ev.exec_write = value; data = new0(struct pending_request, 1); - if (!data) - return ATT_ECODE_INSUFF_RESOURCES; - if (!queue_push_tail(dev->pending_requests, data)) { - free(data); - return ATT_ECODE_INSUFF_RESOURCES; - } + queue_push_tail(dev->pending_requests, data); queue_foreach(app_connections, send_server_write_execute_notify, &ev); send_dev_complete_response(dev, cmd[0]); @@ -6774,10 +6511,6 @@ static void connect_confirm(GIOChannel *io, void *user_data) dev = find_device_by_addr(&dst); if (!dev) { dev = create_device(&dst); - if (!dev) { - error("gatt: Could not create device"); - goto drop; - } } else { if ((dev->state != DEVICE_DISCONNECTED) && !(dev->state == DEVICE_CONNECT_INIT && @@ -7227,9 +6960,8 @@ bool bt_gatt_register(struct ipc *ipc, const bdaddr_t *addr) services_sdp = queue_new(); gatt_db = gatt_db_new(); - if (!gatt_devices || !gatt_apps || !listen_apps || !app_connections || - !services_sdp || !gatt_db) { - error("gatt: Failed to allocate memory for queues"); + if (!gatt_db) { + error("gatt: Failed to allocate memory for database"); goto failed; } |