Skip to content

Commit

Permalink
iio: Handle errors during accept
Browse files Browse the repository at this point in the history
Handle the errors that might occur during the accept_network_clients()
function.

Signed-off-by: Ciprian Regus <ciprian.regus@analog.com>
  • Loading branch information
CiprianRegus authored and buha committed Jan 9, 2024
1 parent e887939 commit 04d4526
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions iio/iio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,8 +1444,9 @@ static int32_t accept_network_clients(struct iio_desc *desc)
struct tcp_socket_desc *sock;
struct iiod_conn_data data;
int32_t ret;
uint32_t id;

do {
uint32_t id;
ret = socket_accept(desc->server, &sock);
if (NO_OS_IS_ERR_VALUE(ret))
return ret;
Expand All @@ -1454,16 +1455,30 @@ static int32_t accept_network_clients(struct iio_desc *desc)
data.buf = no_os_calloc(1, IIOD_CONN_BUFFER_SIZE);
data.len = IIOD_CONN_BUFFER_SIZE;

if (!data.buf) {
ret = -ENOMEM;
goto close_socket;
}

ret = iiod_conn_add(desc->iiod, &data, &id);
if (NO_OS_IS_ERR_VALUE(ret))
return ret;
goto free_buf;

ret = _push_conn(desc, id);
if (NO_OS_IS_ERR_VALUE(ret))
return ret;
goto remove_conn;
} while (true);

return 0;

remove_conn:
iiod_conn_remove(desc->iiod, id, &data);
free_buf:
no_os_free(data.buf);
close_socket:
socket_remove(sock);

return ret;
}
#endif

Expand Down

0 comments on commit 04d4526

Please sign in to comment.