{
GList *i2c_list = *list;
GList *link;
- pb_i2c_data_h i2c_data;
+ pb_i2c_data_h i2c_handle;
if (i2c_list == NULL)
return NULL;
link = i2c_list;
while (link) {
- i2c_data = (pb_i2c_data_h)link->data;
- if (i2c_data->bus == bus && i2c_data->address == address)
- return i2c_data;
+ i2c_handle = (pb_i2c_data_h)link->data;
+ if (i2c_handle->bus == bus && i2c_handle->address == address)
+ return i2c_handle;
link = g_list_next(link);
}
static pb_i2c_data_h peripheral_bus_i2c_data_new(GList **list)
{
GList *i2c_list = *list;
- pb_i2c_data_h i2c_data;
+ pb_i2c_data_h i2c_handle;
- i2c_data = (pb_i2c_data_h)calloc(1, sizeof(peripheral_bus_i2c_data_s));
- if (i2c_data == NULL) {
+ i2c_handle = (pb_i2c_data_h)calloc(1, sizeof(peripheral_bus_i2c_data_s));
+ if (i2c_handle == NULL) {
_E("failed to allocate peripheral_bus_i2c_data_s");
return NULL;
}
- *list = g_list_append(i2c_list, i2c_data);
+ *list = g_list_append(i2c_list, i2c_handle);
- return i2c_data;
+ return i2c_handle;
}
-static int peripheral_bus_i2c_data_free(pb_i2c_data_h i2c_handle, GList **list)
+static int peripheral_bus_i2c_data_free(pb_i2c_data_h i2c_handle, GList **i2c_list)
{
- GList *i2c_list = *list;
GList *link;
- pb_i2c_data_h i2c;
- if (i2c_handle == NULL)
- return -1;
+ RETVM_IF(i2c_handle == NULL, -1, "handle is null");
- link = i2c_list;
- while (link) {
- i2c = (pb_i2c_data_h)link->data;
-
- if (i2c == i2c_handle) {
- *list = g_list_remove_link(i2c_list, link);
- if (i2c->buffer)
- free(i2c->buffer);
- free(i2c);
- g_list_free(link);
- return 0;
- }
- link = g_list_next(link);
+ link = g_list_find(*i2c_list, i2c_handle);
+ if (!link) {
+ _E("handle does not exist in list");
+ return -1;
}
- return -1;
+ *i2c_list = g_list_remove_link(*i2c_list, link);
+ if (i2c_handle->buffer)
+ free(i2c_handle->buffer);
+ free(i2c_handle);
+ g_list_free(link);
+
+ return 0;
}
int peripheral_bus_i2c_open(int bus, int address, pb_i2c_data_h *i2c, gpointer user_data)
{
GList *pwm_list = *list;
GList *link;
- pb_pwm_data_h pwm_data;
+ pb_pwm_data_h pwm_handle;
link = pwm_list;
while (link) {
- pwm_data = (pb_pwm_data_h)link->data;
- if (pwm_data->device == device && pwm_data->channel == channel)
- return pwm_data;
+ pwm_handle = (pb_pwm_data_h)link->data;
+ if (pwm_handle->device == device && pwm_handle->channel == channel)
+ return pwm_handle;
link = g_list_next(link);
}
static pb_pwm_data_h peripheral_bus_pwm_data_new(GList **list)
{
GList *pwm_list = *list;
- pb_pwm_data_h pwm_data;
+ pb_pwm_data_h pwm_handle;
- pwm_data = (pb_pwm_data_h)calloc(1, sizeof(peripheral_bus_pwm_data_s));
- if (pwm_data == NULL) {
+ pwm_handle = (pb_pwm_data_h)calloc(1, sizeof(peripheral_bus_pwm_data_s));
+ if (pwm_handle == NULL) {
_E("failed to allocate peripheral_bus_pwm_data_s");
return NULL;
}
- *list = g_list_append(pwm_list, pwm_data);
+ *list = g_list_append(pwm_list, pwm_handle);
- return pwm_data;
+ return pwm_handle;
}
-static int peripheral_bus_pwm_data_free(pb_pwm_data_h pwm_handle, GList **list)
+static int peripheral_bus_pwm_data_free(pb_pwm_data_h pwm_handle, GList **pwm_list)
{
- GList *pwm_list = *list;
GList *link;
- pb_pwm_data_h pwm_data;
- link = pwm_list;
- while (link) {
- pwm_data = (pb_pwm_data_h)link->data;
-
- if (pwm_data == pwm_handle) {
- *list = g_list_remove_link(pwm_list, link);
- free(pwm_data);
- g_list_free(link);
- return 0;
- }
- link = g_list_next(link);
+ RETVM_IF(pwm_handle == NULL, -1, "handle is null");
+
+ link = g_list_find(*pwm_list, pwm_handle);
+ if (!link) {
+ _E("handle does not exist in list");
+ return -1;
}
- return -1;
+ *pwm_list = g_list_remove_link(*pwm_list, link);
+ free(pwm_handle);
+ g_list_free(link);
+
+ return 0;
}
int peripheral_bus_pwm_open(int device, int channel, pb_pwm_data_h *pwm, gpointer user_data)
{
GList *uart_list = *list;
GList *link;
- pb_uart_data_h uart_data;
+ pb_uart_data_h uart_handle;
link = uart_list;
while (link) {
- uart_data = (pb_uart_data_h)link->data;
- if (uart_data->port == port)
- return uart_data;
+ uart_handle = (pb_uart_data_h)link->data;
+ if (uart_handle->port == port)
+ return uart_handle;
link = g_list_next(link);
}
static pb_uart_data_h peripheral_bus_uart_data_new(GList **list)
{
GList *uart_list = *list;
- pb_uart_data_h uart_data;
+ pb_uart_data_h uart_handle;
- uart_data = (pb_uart_data_h)calloc(1, sizeof(peripheral_bus_uart_data_s));
- if (uart_data == NULL) {
+ uart_handle = (pb_uart_data_h)calloc(1, sizeof(peripheral_bus_uart_data_s));
+ if (uart_handle == NULL) {
_E("failed to allocate peripheral_bus_uart_data_s");
return NULL;
}
- *list = g_list_append(uart_list, uart_data);
+ *list = g_list_append(uart_list, uart_handle);
- return uart_data;
+ return uart_handle;
}
-static int peripheral_bus_uart_data_free(pb_uart_data_h uart_handle, GList **list)
+static int peripheral_bus_uart_data_free(pb_uart_data_h uart_handle, GList **uart_list)
{
- GList *uart_list = *list;
GList *link;
- pb_uart_data_h uart_data;
- link = uart_list;
- while (link) {
- uart_data = (pb_uart_data_h)link->data;
-
- if (uart_data == uart_handle) {
- *list = g_list_remove_link(uart_list, link);
- if (uart_data->buffer)
- free(uart_data->buffer);
- free(uart_data);
- g_list_free(link);
- return 0;
- }
- link = g_list_next(link);
+ RETVM_IF(uart_handle == NULL, -1, "handle is null");
+
+ link = g_list_find(*uart_list, uart_handle);
+ if (!link) {
+ _E("handle does not exist in list");
+ return -1;
}
- return -1;
+ *uart_list = g_list_remove_link(*uart_list, link);
+ if (uart_handle->buffer)
+ free(uart_handle->buffer);
+ free(uart_handle);
+ g_list_free(link);
+
+ return 0;
}
int peripheral_bus_uart_open(int port, pb_uart_data_h *uart, gpointer user_data)