From: Jonathan Cameron <jic23@kernel.org>
To: "Sa, Nuno" <Nuno.Sa@analog.com>
Cc: Jonathan Cameron <Jonathan.Cameron@Huawei.com>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Subject: Re: [PATCH] iio: buffer: Fix demux update
Date: Sat, 14 Nov 2020 16:26:38 +0000 [thread overview]
Message-ID: <20201114162638.6fbf55a8@archlinux> (raw)
In-Reply-To: <CY4PR03MB263146ADC49222DE28BB028999E60@CY4PR03MB2631.namprd03.prod.outlook.com>
On Fri, 13 Nov 2020 07:55:21 +0000
"Sa, Nuno" <Nuno.Sa@analog.com> wrote:
> > -----Original Message-----
> > From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
> > Sent: Thursday, November 12, 2020 6:28 PM
> > To: Sa, Nuno <Nuno.Sa@analog.com>
> > Cc: linux-iio@vger.kernel.org; Jonathan Cameron <jic23@kernel.org>;
> > Lars-Peter Clausen <lars@metafoo.de>; Peter Meerwald-Stadler
> > <pmeerw@pmeerw.net>
> > Subject: Re: [PATCH] iio: buffer: Fix demux update
> >
> >
> > On Thu, 12 Nov 2020 15:43:22 +0100
> > Nuno Sá <nuno.sa@analog.com> wrote:
> >
> > > When updating the buffer demux, we will skip a scan element from
> > the
> > > device in the case `in_ind != out_ind` and we enter the while loop.
> > > in_ind should only be refreshed with `find_next_bit()` in the end of
> > the
> > > loop.
> > >
> > > Fixes: 5ada4ea9be16 ("staging:iio: add demux optionally to path from
> > device to buffer")
> > > Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> >
> > Yikes that's been there a long time.
> >
> > Could you provide an example of a particular layout and the result of
> > this being wrong?
> >
>
> Hi Jonathan,
>
> Let's say:
>
> iio_dev_mask: 0x0111
> buffer_mask: 0x0100
>
> We would get out_ind = 2 and in_ind = 0 and enter the loop. In the first
> iteration we call find_next_bit() before doing the in_ind=0 computation which means we
> will skip it and go directly to bit 1... And if we continue the path flow, we see that bit 2 will
> be computed two times, so if we are lucky and scan_index0_len == scan_index2_len this
> will go unnoticed...
>
> Honestly, I didn't test this but it looks one of those things more or less clear by reading
> the code or am I missing something here?
Mostly I was wondering why it hadn't bitten us before. I think you've identified
why with your "if we are lucky and scan_index0_len == scan_index2_len" then this will
go unnoticed.
It's very rare (though not unheard of) for a device to have it's main channels
of different widths (timestamp doesn't matter for this as it is always at the
end). The demux also only kicks in if we have a restricted channel
mask (or are using a kfifo and a buffer_cb which is rather rare). I suspect
we have few if any devices that actually run into this problem.
I guess I originally tested this code with devices I had at the time and none of
them would have tripped this.
Anyhow, whilst I agree with your analysis I'd like to leave this on list for
perhaps another week before applying it on the basis I'm paranoid and would
ideally like a few more eyes on this.
Good spot!
Jonathan
>
> - Nuno Sá
>
> > Thanks,
> >
> > Jonathan
> >
next prev parent reply other threads:[~2020-11-14 16:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-12 14:43 [PATCH] iio: buffer: Fix demux update Nuno Sá
2020-11-12 17:28 ` Jonathan Cameron
2020-11-13 7:55 ` Sa, Nuno
2020-11-14 16:26 ` Jonathan Cameron [this message]
2020-11-28 15:50 ` Jonathan Cameron
-- strict thread matches above, loose matches on Subject: below --
2023-10-03 1:18 Yeah Yeah
2023-10-04 21:50 Yeah Yeah
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=20201114162638.6fbf55a8@archlinux \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@Huawei.com \
--cc=Nuno.Sa@analog.com \
--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).