All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Julio Cruz <jcsistemas2001@gmail.com>, linux-iio@vger.kernel.org
Subject: Re: read /dev/iio:device0 return -1 (Invalid argument)
Date: Sat, 12 Dec 2015 11:51:14 +0000	[thread overview]
Message-ID: <566C0A32.3030104@kernel.org> (raw)
In-Reply-To: <CAAn_ec90t=N1e1m8aUcBZRb5wsRwiz56WUzFCWqTrVHHhcAuBA@mail.gmail.com>

On 12/12/15 08:36, Julio Cruz wrote:
> Hi,
> 
> I get an error trying to read /dev/iio:device0 in a custom application
> (C/C++), however in a terminal the command "cat /dev/iio_device0"
> return data.
> 
> Below the procedure:
> 
> - enable channels
> - setup trigger
> - setup buffer lenght
> - enable buffer (the SPI interrupt is setup properly and all the
> trigger handler are done)
> - read /dev/iio_device0
> 
> It's a SPI device acquiring 27 bytes @ 1KHz.
Reading this again after point 4 below this makes me ask the question
what are you pushing into the buffer? 27 bytes seems unlikely given
the alignment requirements.

> 
> Results:
> 
> 1. Custom application (based on generic_buffer.c): function 'read'
> return -1 and strerror(errno) return "Invalid argument"
> 2. iio_readdev (libiio): show the message "Unable to refill buffer:
> Input/output error"
> 3. In terminal, the command "cat /dev/iio_device0" show values (no
> readable) while the buffer is enable.
> 
> Any suggestion?
> 
> Thanks for your help!
Sounds like you are ultimately getting that error from a call to
 iio_buffer_read_first_n_outer
so what can return -EINVAL (which is -1)?

1) Buffer not being allocated (seems unlikely - that's really just to
pick up on bugs in side the driver)
2) read_first_n from the buffer not supplied - again not likely.
3) wait_event_interruptible returns it - unlikely.
4) read_first_n which comes from the buffer implementation is returning -EINVAL
This last one seems most likely.

So I am guessing you are using the kfifo buffer (most common option).
Reasons this can return -EINVAL are
1) kfifo not initialized (unlikely)
2) Read length is less than the buffer element size (which is the full scan storage
size)
3) an error from kfifo_to_user (unlikely)

So I'm guessing you are reading too small an amount of data. (tricky to chase
down without adding further printk's etc to the relevant bits of kernel code)
If I've 'guessed' right, interesting question is how this came about.
How many bytes is it trying to read?

Note that IIO has strict alignment requirements - any element must be aligned
to it's own size and this will in some case add lots of padding.  The full buffer
element will be a multiple of the largest element in the scan.  If you have a timestamp
for example at 64bits the whole buffer element will be a multiple of 8bytes.

Jonathan
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


  reply	other threads:[~2015-12-12 11:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-12  8:36 read /dev/iio:device0 return -1 (Invalid argument) Julio Cruz
2015-12-12 11:51 ` Jonathan Cameron [this message]
     [not found]   ` <CAAn_ec_=9syP4j+g5GRMCB-+7vCWE1XqryE6KWUm=auUBZE=uQ@mail.gmail.com>
2015-12-12 12:35     ` Jonathan Cameron
2015-12-12 12:41       ` Julio Cruz
2015-12-13 10:44         ` Julio Cruz
2015-12-13 12:14           ` Jonathan Cameron
2015-12-13 14:42             ` Julio Cruz
2015-12-13 15:21               ` Jonathan Cameron
2016-01-04  4:59                 ` Julio Cruz
2016-01-04 11:34                   ` Jonathan Cameron
2016-01-04 12:29                     ` Daniel Baluta
2016-01-04 12:46                     ` Lars-Peter Clausen
2016-01-04 18:22                       ` Jonathan Cameron
2016-01-05 11:57                         ` Julio Cruz
2016-01-06 18:27                           ` Jonathan Cameron
2016-01-06 18:59                             ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=566C0A32.3030104@kernel.org \
    --to=jic23@kernel.org \
    --cc=jcsistemas2001@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.