From: Job Noorman <job@noorman.info>
To: linux-input@vger.kernel.org
Subject: Question: input_ff_create_memless synchronization
Date: Fri, 29 Jul 2022 12:00:18 +0000 [thread overview]
Message-ID: <CLS4GBA6ROU5.3CJMX42BWA8B5@ancom> (raw)
Hi all,
While creating a driver for a haptics device, I started looking at
existing consumers of `input_ff_create_memless` to learn how this API is
typically used. All drivers in drivers/input/misc that use this API
follow the same structure (code heavily simplified):
```
probe() {
input_ff_create_memless(play);
INIT_WORK(work);
}
play(data, effect) {
data->strength = calc_strength(effect);
schedule_work(work);
}
work(data) {
do_device_io(data->strength);
}
```
My question is about the lack of synchronization on `data` between
`play` and `work` (none of the drivers I found use any kind of
synchronization).
As far as I understand, `play` is called in the context of a timer
softirq and `work` on a workqueue. So it seems possible that `play` is
executed while a previously scheduled `work` is still running or hasn't
even started yet. I see two potential problems when this would happen:
1. A race on `data->strength`;
2. Missed effect updates: if `work` hasn't finished yet when `play` is
called again, `schedule_work` will not schedule it. In the worst
case, we could miss the disabling of an effect.
Is this analysis correct? If not, what am I missing? If so, what would
be the correct way to synchronize? (1. seems easy enough but 2. might
need to involve `flush_work` to implement properly and I'm not sure if
it's ok to call that from a softirq context.)
Best,
Job
reply other threads:[~2022-07-29 12:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=CLS4GBA6ROU5.3CJMX42BWA8B5@ancom \
--to=job@noorman.info \
--cc=linux-input@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 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).