diff options
author | Clément Bénier <clement.benier@iot.bzh> | 2018-10-09 11:52:39 +0200 |
---|---|---|
committer | Clément Bénier <clement.benier@iot.bzh> | 2018-10-12 18:27:24 +0200 |
commit | 731d7a904db900b7dc36ed9f5f3771653e67f41b (patch) | |
tree | c93ff19de293685b42d669b8806b05751b398f0a /binding | |
parent | e240ef90ac31d1be85c528ab26646a1f6a7543be (diff) |
set_channel: no next channel when it doesn't exist
in set_channel, when channel does not exist,
next_channel has to be set to NULL
Change-Id: I512691126200b2a1cc5041b1d2855087b8da1895
Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'binding')
-rw-r--r-- | binding/iiodevices-binding.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/binding/iiodevices-binding.c b/binding/iiodevices-binding.c index affd4b9..9b4b60d 100644 --- a/binding/iiodevices-binding.c +++ b/binding/iiodevices-binding.c @@ -162,7 +162,7 @@ static void init_dev(struct client_sub *client) static int read_infos(struct client_sub* client) { if(!client || !client->channels || !client->channels->chn) { - AFB_ERROR("client=%p or client->channels=%p or client->channels->chn=%p is null", client, client->channels, client->channels->chn); + AFB_ERROR("client or client->channels or client->channels->chn is null"); return -1; } json_object *jobject = NULL; @@ -369,6 +369,10 @@ static void init_event_io(struct client_sub *client) AFB_ERROR("client is null"); return; } + if(!client->channels) { + AFB_ERROR("channel is null"); + return; + } read_infos(client); //get unchanged infos sd_event_source *source = NULL; if(client->u_period <= 0) { //no given frequency @@ -409,7 +413,9 @@ static struct channels* set_channel( if(!(chn->chn = iio_device_find_channel(client->dev, chn->name, false))) { AFB_ERROR("cannot find %s channel", chn->name); - return NULL; + free(chn); + prev_chn->next = NULL; + return prev_chn; } iio_channel_enable(chn->chn); return chn; @@ -530,13 +536,26 @@ static void subscribe(struct afb_req request) uint64_t u_period = get_period(freq); enum iio_elements iioelts = (int)treat_iio_elts(s_iioelts); + if(iioelts == 0){ + afb_req_fail(request, "failed", "wrong args"); + return; + } struct client_sub* client = is_new_client_sub_needed(&iio_infos[i], u_period, &iioelts); if(!client || iioelts > 0) { //no client found or new channels if(!client) client = add_new_client(&iio_infos[i], iioelts, u_period); init_dev(client); + if(!client->dev) { + deinit_client_sub(client); + afb_req_fail_f(request, "failed", "No %s device found", client->infos->dev_name); + return; + } init_channel(client, iioelts); + if(!client->channels) { + afb_req_fail(request, "failed", "No channels found"); + return; + } init_event_io(client); } //stored client in order to be get in unsubscription |