From: Sean Young <sean@mess.org>
To: Viktor Prutyanov <viktor.prutyanov@phystech.edu>
Cc: mchehab@kernel.org, robh+dt@kernel.org, khilman@baylibre.com,
narmstrong@baylibre.com, jbrunet@baylibre.com,
martin.blumenstingl@googlemail.com, linux-media@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-amlogic@lists.infradead.org, rockosov@gmail.com
Subject: Re: [PATCH v5 2/2] media: rc: introduce Meson IR TX driver
Date: Fri, 16 Jul 2021 09:24:05 +0100 [thread overview]
Message-ID: <20210716082405.GA30719@gofer.mess.org> (raw)
In-Reply-To: <20210716013652.248bce6f@192.168.1.3>
Hi Viktor,
On Fri, Jul 16, 2021 at 01:36:52AM +0300, Viktor Prutyanov wrote:
> Hi Sean,
>
> On Thu, 15 Jul 2021 22:40:01 +0100
> Sean Young <sean@mess.org> wrote:
>
> > On Thu, Jul 15, 2021 at 12:27:06AM +0300, Viktor Prutyanov wrote:
> > + meson_irtx_fill_buf(ir, tx_buf, buf, len);
> > > + dev_dbg(ir->dev, "TX buffer filled, length = %u\n", len);
> > > +
> > > + spin_lock_irqsave(&ir->lock, flags);
> > > + meson_irtx_update_buf(ir, tx_buf, len, 0);
> > > + reinit_completion(&ir->completion);
> > > + meson_irtx_send_buffer(ir);
> > > + spin_unlock_irqrestore(&ir->lock, flags);
> > > +
> > > + ret = wait_for_completion_interruptible(&ir->completion);
> > > + dev_dbg(ir->dev, "TX %s\n", ret ? "interrupted" :
> > > "completed");
> >
> > Here two things can happen. One is, the process received a signal
> > (e.g. ^C). The other is that the hardware didn't issue any interrupts
> > due some problem somewhere. In the latter case, we only escape this
> > wait_for_completion_interruptable() when the user gets fed up and
> > presses ^C or something like that.
> >
> > > +
> > > + spin_lock_irqsave(&ir->lock, flags);
> > > + kfree(ir->buf);
> > > + meson_irtx_update_buf(ir, NULL, 0, 0);
> > > + spin_unlock_irqrestore(&ir->lock, flags);
> >
> > Now it is possible that the buffer gets cleared before that IR was
> > sent, if the signal was received early enough. This means not all the
> > Tx was completed.
> >
> > > +
> > > + return len;
> >
> > Yet, we always return success.
> >
> > In case no interrupts were generated we should return an error in a
> > timely manner, so the wait_for_completion() needs the timeout. You
> > can use the fact that the IR is never longer IR_MAX_DURATION (half a
> > second currently). Not sure what the returned error should be, maybe
> > -ETIMEDOUT?
>
> As for me, ETIMEDOUT is OK.
> >
> > The problem with the interruptable wait is that a process can receive
> > a signal at any time, and now when this happens your IR gets
> > truncated. I don't think this is what you want.
>
> Should I replace wait_for_completion_interruptible by
> wait_for_completion_timeout in order to wait in uninterruptible way?
Yes, the process can receive a signal if the terminal is resized
(SIGWINCH) or if the process is backgrounded and then foregrounded with
^Z and fg (SIGCONT). If this happens during tx then the tx might be
incomplete.
Thanks,
Sean
prev parent reply other threads:[~2021-07-16 8:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-14 21:27 [PATCH v5 0/2] media: rc: add support for Amlogic Meson IR blaster Viktor Prutyanov
2021-07-14 21:27 ` [PATCH v5 1/2] media: rc: meson-ir-tx: document device tree bindings Viktor Prutyanov
2021-07-14 21:27 ` [PATCH v5 2/2] media: rc: introduce Meson IR TX driver Viktor Prutyanov
2021-07-15 21:40 ` Sean Young
2021-07-15 22:36 ` Viktor Prutyanov
2021-07-16 8:24 ` Sean Young [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=20210716082405.GA30719@gofer.mess.org \
--to=sean@mess.org \
--cc=devicetree@vger.kernel.org \
--cc=jbrunet@baylibre.com \
--cc=khilman@baylibre.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=mchehab@kernel.org \
--cc=narmstrong@baylibre.com \
--cc=robh+dt@kernel.org \
--cc=rockosov@gmail.com \
--cc=viktor.prutyanov@phystech.edu \
/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).