summaryrefslogtreecommitdiff
path: root/osi
diff options
context:
space:
mode:
authorPavlin Radoslavov <pavlin@google.com>2016-02-06 08:36:06 -0800
committerAndre Eisenbach <eisenbach@google.com>2016-02-18 10:39:26 -0800
commit5fe6f0cf6b223e3ed6be4912d55b3ed5b41ce0cd (patch)
tree0b02fa7ad9daca004d2e14afff56f097c32abff8 /osi
parent75be8ac2970284b8dbd7cdb2323bd3cf80f9c6ff (diff)
downloadandroid-system-bt-5fe6f0cf6b223e3ed6be4912d55b3ed5b41ce0cd.tar.gz
android-system-bt-5fe6f0cf6b223e3ed6be4912d55b3ed5b41ce0cd.tar.xz
Removed checks for NULL returns after osi_calloc() / osi_malloc()
Removed explicit checks for NULL pointer returns after calls to osi_calloc() and osi_malloc(), because those are not needed. If the memory allocation fails, osi_calloc() and osi_malloc() will trigger an assert. Bug: 27048759 Change-Id: I2791eb2f69c08f991f8fcdef10e101a41568cd95
Diffstat (limited to 'osi')
-rw-r--r--osi/src/alarm.c4
-rw-r--r--osi/src/array.c4
-rw-r--r--osi/src/buffer.c8
-rw-r--r--osi/src/config.c12
-rw-r--r--osi/src/data_dispatcher.c4
-rw-r--r--osi/src/eager_reader.c4
-rw-r--r--osi/src/fixed_queue.c2
-rw-r--r--osi/src/future.c13
-rw-r--r--osi/src/reactor.c9
-rw-r--r--osi/src/ringbuffer.c7
-rw-r--r--osi/src/semaphore.c12
-rw-r--r--osi/src/socket.c13
-rw-r--r--osi/src/thread.c6
13 files changed, 8 insertions, 90 deletions
diff --git a/osi/src/alarm.c b/osi/src/alarm.c
index 2ccdd4f..fa4f856 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -165,10 +165,6 @@ static alarm_t *alarm_new_internal(const char *name, bool is_periodic) {
pthread_mutexattr_init(&attr);
alarm_t *ret = osi_calloc(sizeof(alarm_t));
- if (!ret) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for alarm.", __func__);
- goto error;
- }
// Make this a recursive mutex to make it safe to call |alarm_cancel| from
// within the callback function of the alarm.
diff --git a/osi/src/array.c b/osi/src/array.c
index 8291dbb..0baa9bb 100644
--- a/osi/src/array.c
+++ b/osi/src/array.c
@@ -43,10 +43,6 @@ array_t *array_new(size_t element_size) {
assert(element_size > 0);
array_t *array = osi_calloc(sizeof(array_t) + element_size * INTERNAL_ELEMENTS);
- if (!array) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for array with elements of size %zu.", __func__, element_size);
- return NULL;
- }
array->element_size = element_size;
array->capacity = INTERNAL_ELEMENTS;
diff --git a/osi/src/buffer.c b/osi/src/buffer.c
index cbd1e23..54129fb 100644
--- a/osi/src/buffer.c
+++ b/osi/src/buffer.c
@@ -37,10 +37,6 @@ buffer_t *buffer_new(size_t size) {
assert(size > 0);
buffer_t *buffer = osi_calloc(sizeof(buffer_t) + size);
- if (!buffer) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate buffer of %zu bytes.", __func__, size);
- return NULL;
- }
buffer->root = buffer;
buffer->refcount = 1;
@@ -60,10 +56,6 @@ buffer_t *buffer_new_slice(const buffer_t *buf, size_t slice_size) {
assert(slice_size <= buf->length);
buffer_t *ret = osi_calloc(sizeof(buffer_t));
- if (!ret) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate new buffer for slice of length %zu.", __func__, slice_size);
- return NULL;
- }
ret->root = buf->root;
ret->refcount = SIZE_MAX;
diff --git a/osi/src/config.c b/osi/src/config.c
index bf753e7..740677a 100644
--- a/osi/src/config.c
+++ b/osi/src/config.c
@@ -62,10 +62,6 @@ static entry_t *entry_find(const config_t *config, const char *section, const ch
config_t *config_new_empty(void) {
config_t *config = osi_calloc(sizeof(config_t));
- if (!config) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for config_t.", __func__);
- goto error;
- }
config->sections = list_new(section_free);
if (!config->sections) {
@@ -254,10 +250,6 @@ bool config_save(const config_t *config, const char *filename) {
assert(*filename != '\0');
char *temp_filename = osi_calloc(strlen(filename) + 5);
- if (!temp_filename) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for filename.", __func__);
- return false;
- }
strcpy(temp_filename, filename);
strcat(temp_filename, ".new");
@@ -376,8 +368,6 @@ static void config_parse(FILE *fp, config_t *config) {
static section_t *section_new(const char *name) {
section_t *section = osi_calloc(sizeof(section_t));
- if (!section)
- return NULL;
section->name = osi_strdup(name);
section->entries = list_new(entry_free);
@@ -406,8 +396,6 @@ static section_t *section_find(const config_t *config, const char *section) {
static entry_t *entry_new(const char *key, const char *value) {
entry_t *entry = osi_calloc(sizeof(entry_t));
- if (!entry)
- return NULL;
entry->key = osi_strdup(key);
entry->value = osi_strdup(value);
diff --git a/osi/src/data_dispatcher.c b/osi/src/data_dispatcher.c
index ebbd674..1537f3a 100644
--- a/osi/src/data_dispatcher.c
+++ b/osi/src/data_dispatcher.c
@@ -40,10 +40,6 @@ data_dispatcher_t *data_dispatcher_new(const char *name) {
assert(name != NULL);
data_dispatcher_t *ret = osi_calloc(sizeof(data_dispatcher_t));
- if (!ret) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for new data dispatcher.", __func__);
- goto error;
- }
ret->dispatch_table = hash_map_new(DEFAULT_TABLE_BUCKETS, hash_function_naive, NULL, NULL, NULL);
if (!ret->dispatch_table) {
diff --git a/osi/src/eager_reader.c b/osi/src/eager_reader.c
index 29a7cec..044ee81 100644
--- a/osi/src/eager_reader.c
+++ b/osi/src/eager_reader.c
@@ -76,10 +76,6 @@ eager_reader_t *eager_reader_new(
assert(thread_name != NULL && *thread_name != '\0');
eager_reader_t *ret = osi_calloc(sizeof(eager_reader_t));
- if (!ret) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for new eager_reader.", __func__);
- goto error;
- }
ret->allocator = allocator;
ret->inbound_fd = fd_to_read;
diff --git a/osi/src/fixed_queue.c b/osi/src/fixed_queue.c
index 76291a0..be4f292 100644
--- a/osi/src/fixed_queue.c
+++ b/osi/src/fixed_queue.c
@@ -43,8 +43,6 @@ static void internal_dequeue_ready(void *context);
fixed_queue_t *fixed_queue_new(size_t capacity) {
fixed_queue_t *ret = osi_calloc(sizeof(fixed_queue_t));
- if (!ret)
- goto error;
pthread_mutex_init(&ret->lock, NULL);
ret->capacity = capacity;
diff --git a/osi/src/future.c b/osi/src/future.c
index e91cdb3..cf720c5 100644
--- a/osi/src/future.c
+++ b/osi/src/future.c
@@ -37,10 +37,6 @@ static void future_free(future_t *future);
future_t *future_new(void) {
future_t *ret = osi_calloc(sizeof(future_t));
- if (!ret) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for return value.", __func__);
- goto error;
- }
ret->semaphore = semaphore_new(0);
if (!ret->semaphore) {
@@ -57,17 +53,10 @@ error:;
future_t *future_new_immediate(void *value) {
future_t *ret = osi_calloc(sizeof(future_t));
- if (!ret) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for return value.", __func__);
- goto error;
- }
ret->result = value;
ret->ready_can_be_called = false;
- return ret;
-error:;
- future_free(ret);
- return NULL;
+ return ret;
}
void future_ready(future_t *future, void *value) {
diff --git a/osi/src/reactor.c b/osi/src/reactor.c
index b216fec..7bab5e4 100644
--- a/osi/src/reactor.c
+++ b/osi/src/reactor.c
@@ -64,8 +64,6 @@ static const eventfd_t EVENT_REACTOR_STOP = 1;
reactor_t *reactor_new(void) {
reactor_t *ret = (reactor_t *)osi_calloc(sizeof(reactor_t));
- if (!ret)
- return NULL;
ret->epoll_fd = INVALID_FD;
ret->event_fd = INVALID_FD;
@@ -138,11 +136,8 @@ reactor_object_t *reactor_register(reactor_t *reactor,
assert(reactor != NULL);
assert(fd != INVALID_FD);
- reactor_object_t *object = (reactor_object_t *)osi_calloc(sizeof(reactor_object_t));
- if (!object) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate reactor object: %s", __func__, strerror(errno));
- return NULL;
- }
+ reactor_object_t *object =
+ (reactor_object_t *)osi_calloc(sizeof(reactor_object_t));
object->reactor = reactor;
object->fd = fd;
diff --git a/osi/src/ringbuffer.c b/osi/src/ringbuffer.c
index 131f5b1..aeb413c 100644
--- a/osi/src/ringbuffer.c
+++ b/osi/src/ringbuffer.c
@@ -32,15 +32,8 @@ struct ringbuffer_t {
ringbuffer_t* ringbuffer_init(const size_t size) {
ringbuffer_t* p = osi_calloc(sizeof(ringbuffer_t));
- if (p == 0)
- return NULL;
p->base = osi_calloc(size);
- if (p->base == 0) {
- osi_free(p);
- return NULL;
- }
-
p->head = p->tail = p->base;
p->total = p->available = size;
diff --git a/osi/src/semaphore.c b/osi/src/semaphore.c
index 59b250a..0318401 100644
--- a/osi/src/semaphore.c
+++ b/osi/src/semaphore.c
@@ -42,13 +42,11 @@ struct semaphore_t {
semaphore_t *semaphore_new(unsigned int value) {
semaphore_t *ret = osi_malloc(sizeof(semaphore_t));
- if (ret) {
- ret->fd = eventfd(value, EFD_SEMAPHORE);
- if (ret->fd == INVALID_FD) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate semaphore: %s", __func__, strerror(errno));
- osi_free(ret);
- ret = NULL;
- }
+ ret->fd = eventfd(value, EFD_SEMAPHORE);
+ if (ret->fd == INVALID_FD) {
+ LOG_ERROR(LOG_TAG, "%s unable to allocate semaphore: %s", __func__, strerror(errno));
+ osi_free(ret);
+ ret = NULL;
}
return ret;
}
diff --git a/osi/src/socket.c b/osi/src/socket.c
index 90fbb97..80813f5 100644
--- a/osi/src/socket.c
+++ b/osi/src/socket.c
@@ -50,10 +50,6 @@ static void internal_write_ready(void *context);
socket_t *socket_new(void) {
socket_t *ret = (socket_t *)osi_calloc(sizeof(socket_t));
- if (!ret) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for socket.", __func__);
- goto error;
- }
ret->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (ret->fd == INVALID_FD) {
@@ -80,10 +76,6 @@ socket_t *socket_new_from_fd(int fd) {
assert(fd != INVALID_FD);
socket_t *ret = (socket_t *)osi_calloc(sizeof(socket_t));
- if (!ret) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for socket.", __func__);
- return NULL;
- }
ret->fd = fd;
return ret;
@@ -128,11 +120,6 @@ socket_t *socket_accept(const socket_t *socket) {
}
socket_t *ret = (socket_t *)osi_calloc(sizeof(socket_t));
- if (!ret) {
- close(fd);
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory for socket.", __func__);
- return NULL;
- }
ret->fd = fd;
return ret;
diff --git a/osi/src/thread.c b/osi/src/thread.c
index 4386e45..6120039 100644
--- a/osi/src/thread.c
+++ b/osi/src/thread.c
@@ -66,8 +66,6 @@ thread_t *thread_new_sized(const char *name, size_t work_queue_capacity) {
assert(work_queue_capacity != 0);
thread_t *ret = osi_calloc(sizeof(thread_t));
- if (!ret)
- goto error;
ret->reactor = reactor_new();
if (!ret->reactor)
@@ -141,10 +139,6 @@ bool thread_post(thread_t *thread, thread_fn func, void *context) {
// Queue item is freed either when the queue itself is destroyed
// or when the item is removed from the queue for dispatch.
work_item_t *item = (work_item_t *)osi_malloc(sizeof(work_item_t));
- if (!item) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate memory: %s", __func__, strerror(errno));
- return false;
- }
item->func = func;
item->context = context;
fixed_queue_enqueue(thread->work_queue, item);