Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong IIO device attribute (and a iio_rwdev fix) #1237

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct iio_channel_pdata {
static const char * const device_attrs_denylist[] = {
"dev",
"uevent",
"waiting_for_supplier",
};

static const char * const buffer_attrs_reserved[] = {
Expand Down Expand Up @@ -133,6 +134,7 @@ static void local_shutdown(struct iio_context *ctx)
static void strcut(char *str, int nb)
{
char *ptr = str + nb;

while (*ptr)
*str++ = *ptr++;
*str = 0;
Expand Down Expand Up @@ -633,8 +635,8 @@ static int local_set_trigger(const struct iio_device *dev,
strlen(value) + 1, IIO_ATTR_TYPE_DEVICE);
if (nb < 0)
return (int) nb;
else
return 0;

return 0;
}

static bool is_channel(const struct iio_device *dev, const char *attr, bool strict)
Expand Down Expand Up @@ -995,6 +997,7 @@ static unsigned int is_global_attr(struct iio_channel *chn, const char *attr)
unsigned int len1 = dashptr - attr;
unsigned int len2 = ptr - dashptr - 1;
const char* iddashptr = strchr(chn->id, '-');

if (iddashptr && strlen(iddashptr + 1) > len2 &&
(unsigned int)(iddashptr - chn->id) > len1 &&
chn->id[len1] >= '0' && chn->id[len1] <= '9' &&
Expand All @@ -1016,10 +1019,11 @@ static unsigned int is_global_attr(struct iio_channel *chn, const char *attr)
return 2;
}
return 1;
} else if (chn->id[len] != '_') {
return 0;
}

if (chn->id[len] != '_')
return 0;

if (find_channel_modifier(chn->id + len + 1, NULL) != IIO_NO_MOD)
return 1;

Expand All @@ -1034,6 +1038,7 @@ static int detect_global_attr(struct iio_device *dev, const char *attr,
*match = false;
for (i = 0; i < dev->nb_channels; i++) {
struct iio_channel *chn = dev->channels[i];

if (is_global_attr(chn, attr) == level) {
int ret;
*match = true;
Expand Down Expand Up @@ -1929,7 +1934,6 @@ static char * cat_file(const char *path)
{
char buf[BUF_SIZE];
ssize_t ret;

FILE *f;

f = fopen(path, "re");
Expand All @@ -1938,11 +1942,11 @@ static char * cat_file(const char *path)

ret = fread(buf, 1, sizeof(buf)-1, f);
fclose(f);
if (ret > 0)
buf[ret - 1] = '\0';
else
if (ret <= 0)
return NULL;

buf[ret - 1] = '\0';

return strndup(buf, sizeof(buf) - 1);
}

Expand Down
5 changes: 3 additions & 2 deletions utils/iio_rwdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,9 @@ int main(int argc, char **argv)

block = iio_stream_get_next_block(stream);
ret = iio_err(block);
if (ret && app_running) {
dev_perror(dev, ret, "Unable to get next block");
if (ret) {
if (app_running)
dev_perror(dev, ret, "Unable to get next block");
break;
}

Expand Down