Skip to content

Commit

Permalink
IIOD: Fix bug in mask bit tests (continued)
Browse files Browse the repository at this point in the history
From: #198
Previously, the index field of struct iio_channel was being used to test
against the buffer field of struct iio_device and struct iio_buffer.
This is incorrect because the index of the first channel may be non-zero
and the indexes may not be contiguous. For further evidence, look at
iio_channel_enable/disable() which use number rather than index.

Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
  • Loading branch information
mhennerich committed Oct 31, 2018
1 parent ad085a5 commit b7407af
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions iiod/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static ssize_t send_sample(const struct iio_channel *chn,
void *src, size_t length, void *d)
{
struct sample_cb_info *info = d;
if (chn->index < 0 || !TEST_BIT(info->mask, chn->index))
if (chn->index < 0 || !TEST_BIT(info->mask, chn->number))
return 0;
if (info->nb_bytes < length)
return 0;
Expand All @@ -389,7 +389,7 @@ static ssize_t receive_sample(const struct iio_channel *chn,
void *dst, size_t length, void *d)
{
struct sample_cb_info *info = d;
if (chn->index < 0 || !TEST_BIT(info->mask, chn->index))
if (chn->index < 0 || !TEST_BIT(info->mask, chn->number))
return 0;
if (info->cpt == info->nb_bytes)
return 0;
Expand Down Expand Up @@ -560,7 +560,10 @@ static void rw_thd(struct thread_pool *pool, void *d)
struct iio_channel *chn = dev->channels[i];
long index = chn->index;

if (index >= 0 && TEST_BIT(entry->mask, i))
if (index < 0)
continue;

if (TEST_BIT(entry->mask, chn->number))
iio_channel_enable(chn);
else
iio_channel_disable(chn);
Expand Down

0 comments on commit b7407af

Please sign in to comment.