From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org,
device-drivers-devel@blackfin.uclinux.org, greg@kroah.com,
dmitry.torokhov@gmail.com, broonie@opensource.wolfsonmicro.com,
alan@lxorguk.ukuu.org.uk, arnd@arndb.de,
linus.walleij@linaro.org, maxime.ripard@free-electrons.com,
thomas.petazzoni@free-electrons.com, zdevai@gmail.com,
w.sang@pengutronix.de, marek.vasut@gmail.com,
Jonathan Cameron <jic23@cam.ac.uk>
Subject: Re: [PATCH 1/4] staging:iio: make all buffer access pass through the buffer_list
Date: Mon, 16 Apr 2012 17:59:49 +0200 [thread overview]
Message-ID: <4F8C41F5.2010807@metafoo.de> (raw)
In-Reply-To: <1334090294-23407-2-git-send-email-jic23@kernel.org>
On 04/10/2012 10:38 PM, Jonathan Cameron wrote:
> From: Jonathan Cameron <jic23@cam.ac.uk>
>
> Crucial step in allowing multiple interfaces.
>
> Main stages:
>
> 1) Ensure no trigger_handler touches the buffers directly.
> They should only care about active_scan_mask and scan_timestamp
> in indio_dev.
> 2) Ensure all setup ops for the buffers act on the general mode
> and the individual buffers in a consistent fashion.
> 3) Make use of iio_sw_buffer_preenable where possibe. It's never
> in a particular fast path so even if overcomplex it is worth
> using to cut down on code duplication.
In my opinion it would have been better to split 1, 2 and 3 into different
patches.
The driver specific bits look good, but I can't really say I do understand
all that's changed in the core right now.
> [...]
>
> int iio_update_demux(struct iio_dev *indio_dev)
> {
> const struct iio_chan_spec *ch;
> - struct iio_buffer *buffer = indio_dev->buffer;
> - int ret, in_ind = -1, out_ind, length;
> - unsigned in_loc = 0, out_loc = 0;
> + struct iio_buffer *buffer;
> struct iio_demux_table *p, *q;
> + int ret;
>
> - /* Clear out any old demux */
> - list_for_each_entry_safe(p, q, &buffer->demux_list, l) {
> - list_del(&p->l);
> - kfree(p);
> - }
> - kfree(buffer->demux_bounce);
> - buffer->demux_bounce = NULL;
> -
> - /* First work out which scan mode we will actually have */
> - if (bitmap_equal(indio_dev->active_scan_mask,
> - buffer->scan_mask,
> - indio_dev->masklength))
> - return 0;
> + list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
> + unsigned in_loc = 0, out_loc = 0;
> + int in_ind = -1, out_ind, length;
How about using a outer function here which loops over the buffers and a
inner function, which handles a single buffer? This keeps the indention
level low and also makes the diffstat a lot more readable.
>
> - /* Now we have the two masks, work from least sig and build up sizes */
> - for_each_set_bit(out_ind,
> - indio_dev->active_scan_mask,
> - indio_dev->masklength) {
> - in_ind = find_next_bit(indio_dev->active_scan_mask,
> - indio_dev->masklength,
> - in_ind + 1);
> - while (in_ind != out_ind) {
> + /* Clear out any old demux */
> + list_for_each_entry_safe(p, q, &buffer->demux_list, l) {
> + list_del(&p->l);
> + kfree(p);
> + }
> + kfree(buffer->demux_bounce);
> + buffer->demux_bounce = NULL;
> +
> + /* First work out which scan mode we will actually have */
> + if (bitmap_equal(indio_dev->active_scan_mask,
> + buffer->scan_mask,
> + indio_dev->masklength))
> + return 0;
> +
> + /*
> + * Now we have the two masks, work from least sig
> + * and build up sizes.
> + */
> + for_each_set_bit(out_ind,
> + indio_dev->active_scan_mask,
> + indio_dev->masklength) {
> in_ind = find_next_bit(indio_dev->active_scan_mask,
> indio_dev->masklength,
> in_ind + 1);
> + while (in_ind != out_ind) {
> + 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);
> + length = ch->scan_type.storagebits/8;
> + /* Make sure we are aligned */
> + in_loc += length;
> + if (in_loc % length)
> + in_loc += length - in_loc % length;
> + }
> + p = kmalloc(sizeof(*p), GFP_KERNEL);
> + if (p == NULL) {
> + ret = -ENOMEM;
> + goto error_clear_mux_table;
> + }
> ch = iio_find_channel_from_si(indio_dev, in_ind);
> length = ch->scan_type.storagebits/8;
> - /* Make sure we are aligned */
> - in_loc += length;
> + if (out_loc % length)
> + out_loc += length - out_loc % length;
> if (in_loc % length)
> in_loc += length - in_loc % length;
> + p->from = in_loc;
> + p->to = out_loc;
> + p->length = length;
> + list_add_tail(&p->l, &buffer->demux_list);
> + out_loc += length;
> + in_loc += length;
> }
> - p = kmalloc(sizeof(*p), GFP_KERNEL);
> - if (p == NULL) {
> - ret = -ENOMEM;
> - goto error_clear_mux_table;
> + /* Relies on scan_timestamp being last */
> + if (buffer->scan_timestamp) {
> + p = kmalloc(sizeof(*p), GFP_KERNEL);
> + if (p == NULL) {
> + ret = -ENOMEM;
> + goto error_clear_mux_table;
> + }
> + ch = iio_find_channel_from_si(indio_dev,
> + indio_dev->
> + scan_index_timestamp);
> + length = ch->scan_type.storagebits/8;
> + if (out_loc % length)
> + out_loc += length - out_loc % length;
> + if (in_loc % length)
> + in_loc += length - in_loc % length;
> + p->from = in_loc;
> + p->to = out_loc;
> + p->length = length;
> + list_add_tail(&p->l, &buffer->demux_list);
> + out_loc += length;
> + in_loc += length;
> }
> - ch = iio_find_channel_from_si(indio_dev, in_ind);
> - length = ch->scan_type.storagebits/8;
> - if (out_loc % length)
> - out_loc += length - out_loc % length;
> - if (in_loc % length)
> - in_loc += length - in_loc % length;
> - p->from = in_loc;
> - p->to = out_loc;
> - p->length = length;
> - list_add_tail(&p->l, &buffer->demux_list);
> - out_loc += length;
> - in_loc += length;
> - }
> - /* Relies on scan_timestamp being last */
> - if (buffer->scan_timestamp) {
> - p = kmalloc(sizeof(*p), GFP_KERNEL);
> - if (p == NULL) {
> + buffer->demux_bounce = kzalloc(out_loc, GFP_KERNEL);
> + if (buffer->demux_bounce == NULL) {
> ret = -ENOMEM;
> goto error_clear_mux_table;
> }
> - ch = iio_find_channel_from_si(indio_dev,
> - buffer->scan_index_timestamp);
> - length = ch->scan_type.storagebits/8;
> - if (out_loc % length)
> - out_loc += length - out_loc % length;
> - if (in_loc % length)
> - in_loc += length - in_loc % length;
> - p->from = in_loc;
> - p->to = out_loc;
> - p->length = length;
> - list_add_tail(&p->l, &buffer->demux_list);
> - out_loc += length;
> - in_loc += length;
> - }
> - buffer->demux_bounce = kzalloc(out_loc, GFP_KERNEL);
> - if (buffer->demux_bounce == NULL) {
> - ret = -ENOMEM;
> - goto error_clear_mux_table;
> }
> return 0;
>
> error_clear_mux_table:
> - list_for_each_entry_safe(p, q, &buffer->demux_list, l) {
> - list_del(&p->l);
> - kfree(p);
> + list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
> + list_for_each_entry_safe(p, q, &buffer->demux_list, l) {
> + list_del(&p->l);
> + kfree(p);
> + }
> }
> return ret;
> }
next prev parent reply other threads:[~2012-04-16 15:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-10 20:38 [RFC PATCH 0/4 V2] Add push based interface for non userspace iio users Jonathan Cameron
2012-04-10 20:38 ` [PATCH 1/4] staging:iio: make all buffer access pass through the buffer_list Jonathan Cameron
2012-04-16 15:59 ` Lars-Peter Clausen [this message]
2012-04-16 20:40 ` Jonathan Cameron
2012-04-10 20:38 ` [PATCH 3/4] staging:iio:in kernel users: Add a data field for channel specific info Jonathan Cameron
2012-04-10 20:38 ` [PATCH 4/4] staging:iio: Proof of concept input driver 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=4F8C41F5.2010807@metafoo.de \
--to=lars@metafoo.de \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arnd@arndb.de \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=device-drivers-devel@blackfin.uclinux.org \
--cc=dmitry.torokhov@gmail.com \
--cc=greg@kroah.com \
--cc=jic23@cam.ac.uk \
--cc=jic23@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-iio@vger.kernel.org \
--cc=marek.vasut@gmail.com \
--cc=maxime.ripard@free-electrons.com \
--cc=thomas.petazzoni@free-electrons.com \
--cc=w.sang@pengutronix.de \
--cc=zdevai@gmail.com \
/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).