Skip to content

Commit

Permalink
local: Handle errors of create_channel()
Browse files Browse the repository at this point in the history
Instead of returning -ENXIO if anything goes wrong when creating a
channel, return the actual underlying error.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Jun 25, 2021
1 parent 66a74e4 commit 018e8e3
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -1420,33 +1420,41 @@ static struct iio_channel *create_channel(struct iio_device *dev,
char *id, const char *attr, const char *path,
bool is_scan_element)
{
struct iio_channel *chn = zalloc(sizeof(*chn));
struct iio_channel *chn;
int err = -ENOMEM;

chn = zalloc(sizeof(*chn));
if (!chn)
return NULL;
return ERR_PTR(-ENOMEM);

chn->pdata = zalloc(sizeof(*chn->pdata));
if (!chn->pdata)
goto err_free_chn;

if (!strncmp(attr, "out_", 4))
if (!strncmp(attr, "out_", 4)) {
chn->is_output = true;
else if (strncmp(attr, "in_", 3))
} else if (strncmp(attr, "in_", 3)) {
err = -EINVAL;
goto err_free_chn_pdata;
}

chn->dev = dev;
chn->id = id;
chn->is_scan_element = is_scan_element;
chn->index = -ENOENT;

if (!add_attr_to_channel(chn, attr, path, is_scan_element))
return chn;
err = add_attr_to_channel(chn, attr, path, is_scan_element);
if (err)
goto err_free_chn_pdata;

return chn;

err_free_chn_pdata:
free(chn->pdata->enable_fn);
free(chn->pdata);
err_free_chn:
free(chn);
return NULL;
return ERR_PTR(err);
}

static int add_channel(struct iio_device *dev, const char *name,
Expand Down Expand Up @@ -1474,9 +1482,9 @@ static int add_channel(struct iio_device *dev, const char *name,
}

chn = create_channel(dev, channel_id, name, path, dir_is_scan_elements);
if (!chn) {
if (IS_ERR(chn)) {
free(channel_id);
return -ENXIO;
return PTR_ERR(chn);
}

iio_channel_init_finalize(chn);
Expand Down

0 comments on commit 018e8e3

Please sign in to comment.