linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Daniel Baluta <daniel.baluta@gmail.com>,
	Lars-Peter Clausen <lars@metafoo.de>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>
Subject: Re: [PATCH v2] iio: Add helper function for calculating scan index storage size
Date: Sat, 6 Feb 2016 18:22:24 +0000	[thread overview]
Message-ID: <56B639E0.1090702@kernel.org> (raw)
In-Reply-To: <CAEnQRZAkwRJk1SNw5tGs6EdJ34ZVkmsyVEnmwv+mEQD16doA8w@mail.gmail.com>

On 03/02/16 14:35, Daniel Baluta wrote:
> On Tue, Feb 2, 2016 at 5:27 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
>> We have the same code for computing the scan index storage size in bytes
>> all over the place. Factor this out into helper functions.
>>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> 
> Nice!
Indeed.
> 
> Acked-by: Daniel Baluta <daniel.baluta@intel.com>
Applied to the togreg branch of iio.git - initially pushed out as testing
as per normal.

Jonathan
> 
>> ---
>> Changes since v1:
>>         * Workaround checkpatch.pl --strict warnings
>> ---
>>  drivers/iio/industrialio-buffer.c | 59 +++++++++++++++++----------------------
>>  1 file changed, 25 insertions(+), 34 deletions(-)
>>
>> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
>> index 139ae91..b976332 100644
>> --- a/drivers/iio/industrialio-buffer.c
>> +++ b/drivers/iio/industrialio-buffer.c
>> @@ -512,33 +512,41 @@ static ssize_t iio_buffer_show_enable(struct device *dev,
>>         return sprintf(buf, "%d\n", iio_buffer_is_active(indio_dev->buffer));
>>  }
>>
>> +static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev,
>> +                                            unsigned int scan_index)
>> +{
>> +       const struct iio_chan_spec *ch;
>> +       unsigned int bytes;
>> +
>> +       ch = iio_find_channel_from_si(indio_dev, scan_index);
>> +       bytes = ch->scan_type.storagebits / 8;
>> +       if (ch->scan_type.repeat > 1)
>> +               bytes *= ch->scan_type.repeat;
>> +       return bytes;
>> +}
>> +
>> +static unsigned int iio_storage_bytes_for_timestamp(struct iio_dev *indio_dev)
>> +{
>> +       return iio_storage_bytes_for_si(indio_dev,
>> +                                       indio_dev->scan_index_timestamp);
>> +}
>> +
>>  static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
>>                                 const unsigned long *mask, bool timestamp)
>>  {
>> -       const struct iio_chan_spec *ch;
>>         unsigned bytes = 0;
>>         int length, i;
>>
>>         /* How much space will the demuxed element take? */
>>         for_each_set_bit(i, mask,
>>                          indio_dev->masklength) {
>> -               ch = iio_find_channel_from_si(indio_dev, i);
>> -               if (ch->scan_type.repeat > 1)
>> -                       length = ch->scan_type.storagebits / 8 *
>> -                               ch->scan_type.repeat;
>> -               else
>> -                       length = ch->scan_type.storagebits / 8;
>> +               length = iio_storage_bytes_for_si(indio_dev, i);
>>                 bytes = ALIGN(bytes, length);
>>                 bytes += length;
>>         }
>> +
>>         if (timestamp) {
>> -               ch = iio_find_channel_from_si(indio_dev,
>> -                                             indio_dev->scan_index_timestamp);
>> -               if (ch->scan_type.repeat > 1)
>> -                       length = ch->scan_type.storagebits / 8 *
>> -                               ch->scan_type.repeat;
>> -               else
>> -                       length = ch->scan_type.storagebits / 8;
>> +               length = iio_storage_bytes_for_timestamp(indio_dev);
>>                 bytes = ALIGN(bytes, length);
>>                 bytes += length;
>>         }
>> @@ -1288,7 +1296,6 @@ static int iio_buffer_add_demux(struct iio_buffer *buffer,
>>  static int iio_buffer_update_demux(struct iio_dev *indio_dev,
>>                                    struct iio_buffer *buffer)
>>  {
>> -       const struct iio_chan_spec *ch;
>>         int ret, in_ind = -1, out_ind, length;
>>         unsigned in_loc = 0, out_loc = 0;
>>         struct iio_demux_table *p = NULL;
>> @@ -1315,21 +1322,11 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
>>                         in_ind = find_next_bit(indio_dev->active_scan_mask,
>>                                                indio_dev->masklength,
>>                                                in_ind + 1);
>> -                       ch = iio_find_channel_from_si(indio_dev, in_ind);
>> -                       if (ch->scan_type.repeat > 1)
>> -                               length = ch->scan_type.storagebits / 8 *
>> -                                       ch->scan_type.repeat;
>> -                       else
>> -                               length = ch->scan_type.storagebits / 8;
>> +                       length = iio_storage_bytes_for_si(indio_dev, in_ind);
>>                         /* Make sure we are aligned */
>>                         in_loc = roundup(in_loc, length) + length;
>>                 }
>> -               ch = iio_find_channel_from_si(indio_dev, in_ind);
>> -               if (ch->scan_type.repeat > 1)
>> -                       length = ch->scan_type.storagebits / 8 *
>> -                               ch->scan_type.repeat;
>> -               else
>> -                       length = ch->scan_type.storagebits / 8;
>> +               length = iio_storage_bytes_for_si(indio_dev, in_ind);
>>                 out_loc = roundup(out_loc, length);
>>                 in_loc = roundup(in_loc, length);
>>                 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length);
>> @@ -1340,13 +1337,7 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
>>         }
>>         /* Relies on scan_timestamp being last */
>>         if (buffer->scan_timestamp) {
>> -               ch = iio_find_channel_from_si(indio_dev,
>> -                       indio_dev->scan_index_timestamp);
>> -               if (ch->scan_type.repeat > 1)
>> -                       length = ch->scan_type.storagebits / 8 *
>> -                               ch->scan_type.repeat;
>> -               else
>> -                       length = ch->scan_type.storagebits / 8;
>> +               length = iio_storage_bytes_for_timestamp(indio_dev);
>>                 out_loc = roundup(out_loc, length);
>>                 in_loc = roundup(in_loc, length);
>>                 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length);
>> --
>> 2.1.4
>>
> --
> 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:[~2016-02-06 18:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-02 15:27 [PATCH v2] iio: Add helper function for calculating scan index storage size Lars-Peter Clausen
2016-02-03 14:35 ` Daniel Baluta
2016-02-06 18:22   ` Jonathan Cameron [this message]

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=56B639E0.1090702@kernel.org \
    --to=jic23@kernel.org \
    --cc=daniel.baluta@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).