From: Jeff Garzik <jeff@garzik.org>
To: Dmitry Torokhov <dtor@insightbb.com>
Cc: linux-input@atrey.karlin.mff.cuni.cz, linux-kernel@vger.kernel.org
Subject: Re: [RFC/RFT 1/5] Input: implement proper locking in input core
Date: Tue, 24 Jul 2007 01:35:54 -0400 [thread overview]
Message-ID: <46A58FBA.5010505@garzik.org> (raw)
In-Reply-To: <20070724044858.192608314.dtor@insightbb.com>
Dmitry Torokhov wrote:
> +static void input_repeat_key(unsigned long data)
> +{
> + struct input_dev *dev = (void *) data;
>
> - change_bit(code, dev->key);
> + spin_lock_irq(&dev->event_lock);
[...]
> +void input_inject_event(struct input_handle *handle,
> + unsigned int type, unsigned int code, int value)
> {
> - struct input_dev *dev = (void *) data;
> + struct input_dev *dev = handle->dev;
> + struct input_handle *grab;
>
> - if (!test_bit(dev->repeat_key, dev->key))
> - return;
> + if (is_event_supported(type, dev->evbit, EV_MAX)) {
> + spin_lock_irq(&dev->event_lock);
>
> - input_event(dev, EV_KEY, dev->repeat_key, 2);
> - input_sync(dev);
> + grab = rcu_dereference(dev->grab);
> + if (!grab || grab == handle)
> + input_handle_event(dev, type, code, value);
>
> - if (dev->rep[REP_PERIOD])
> - mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_PERIOD]));
> + spin_unlock_irq(&dev->event_lock);
> + }
> }
> +EXPORT_SYMBOL(input_inject_event);
[...]
> + spin_lock_irq(&dev->event_lock);
> +
> + /*
> + * Simulate keyup events for all pressed keys so that handlers
> + * are not left with "stuck" keys. The driver may continue
> + * generate events even after we done here but they will not
> + * reach any handlers.
> + */
> + if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
> + for (code = 0; code <= KEY_MAX; code++) {
> + if (is_event_supported(code, dev->keybit, KEY_MAX) &&
> + test_bit(code, dev->key)) {
> + input_pass_event(dev, EV_KEY, code, 0);
> + }
> + }
> + input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
> + }
> +
> + list_for_each_entry(handle, &dev->h_list, d_node)
> + handle->open = 0;
> +
> + spin_unlock_irq(&dev->event_lock);
spin_lock_irq() should generally be avoided.
In cases like the first case -- input_repeat_key() -- you are making
incorrect assumptions about the state of interrupts. The other cases
are probably ok, but in general spin_lock_irq() has a long history of
being very fragile and quite often wrong.
Use spin_lock_irqsave() to be safe. Definitely in input_repeat_key(),
but I strongly recommend removing spin_lock_irq() from all your patches
here.
Jeff
next prev parent reply other threads:[~2007-07-24 5:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-24 4:45 [RFC/RFT 0/5] Input locking patches Dmitry Torokhov
2007-07-24 4:45 ` [RFC/RFT 1/5] Input: implement proper locking in input core Dmitry Torokhov
2007-07-24 5:35 ` Jeff Garzik [this message]
2007-07-24 5:52 ` Dmitry Torokhov
2007-07-27 23:28 ` Indan Zupancic
2007-07-29 3:50 ` Dmitry Torokhov
2007-07-29 12:50 ` Indan Zupancic
2007-07-24 4:45 ` [RFC/RFT 2/5] evdev - implement proper locking Dmitry Torokhov
2007-07-24 4:45 ` [RFC/RFT 3/5] Input: tsdev " Dmitry Torokhov
2007-07-24 4:45 ` [RFC/RFT 4/5] Input: mousedev " Dmitry Torokhov
2007-07-24 4:45 ` [RFC/RFT 5/5] Input: joydev " Dmitry Torokhov
2007-07-27 22:25 ` [RFC/RFT 0/5] Input locking patches Indan Zupancic
2007-07-29 3:38 ` Dmitry Torokhov
2007-07-29 12:15 ` Indan Zupancic
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=46A58FBA.5010505@garzik.org \
--to=jeff@garzik.org \
--cc=dtor@insightbb.com \
--cc=linux-input@atrey.karlin.mff.cuni.cz \
--cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.