public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vojtech Pavlik <vojtech@suse.cz>
To: Dmitry Torokhov <dtor_core@ameritech.net>
Cc: InputML <linux-input@atrey.karlin.mff.cuni.cz>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RCF/RFT] Fix race timer race in gameport-based joystick drivers
Date: Tue, 15 Feb 2005 15:05:01 +0100	[thread overview]
Message-ID: <20050215140501.GF7250@ucw.cz> (raw)
In-Reply-To: <200502150042.32564.dtor_core@ameritech.net>

On Tue, Feb 15, 2005 at 12:42:31AM -0500, Dmitry Torokhov wrote:
> Hi,
> 
> There seems to be a race WRT to timer handling in all gameport-based
> joystick drivers. open() and close() methods are used to start and
> stop polling timers on demand but counter and the timer itself is not
> protected in any way so if several clients will try to open/close
> corresponding input device node they could up with timer not running
> at all or running while nobody has the node open. Plus it is possible
> that disconnect will run and free driver structure while timer is running
> on other CPU.
> 
> I have moved timer and counter down into gameport structure (I think it
> is ok because on the one hand joysticks are the only users of gameport
> and on the other hand polling timer can be useful to other clients if
> ever writen), and added helper functions to manipulate it:
> 
> 	- gameport_start_polling(gameport)
> 	- gameport_stop_polling(gameport)
> 	- gameport_set_poll_handler(gameoirt, handler)
> 	- gameport_set_poll_interval(gameport, msecs)
> 
> gameport_{start|stop}_poll handler are using spinlock to guarantee that
> timer updated properly. Also, gameport_close deletes (synchronously) timer
> to make sure there is no surprises since gameport_stop_poling does del_timer
> and thus may leave timer scheduled. Timer routine also checks the counter
> and does not restart it if there are no users.
> 
> Please let me know what you think.

I'm not really sure if I really want to move the polling into the
gameport layer. It's useful, but without it, gameport is considered
strictly a passive device which can't generate callbacks (other than
open/close/connect/disconnect).

The new polling interface isn't much simpler than what Linux timers
offer, only it provides additional locking.

Probably protecting open/close calls in gameport.c with a spinlock would
allow to work without explicit locking in the drivers.

Other than that, the implementation looks OK.

-- 
Vojtech Pavlik
SuSE Labs, SuSE CR

  reply	other threads:[~2005-02-15 14:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-15  5:42 [RCF/RFT] Fix race timer race in gameport-based joystick drivers Dmitry Torokhov
2005-02-15 14:05 ` Vojtech Pavlik [this message]
2005-02-15 14:51   ` Dmitry Torokhov
2005-02-15 15:06     ` Vojtech Pavlik
2005-02-16  5:45       ` Dmitry Torokhov
2005-02-16  8:35         ` Vojtech Pavlik

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=20050215140501.GF7250@ucw.cz \
    --to=vojtech@suse.cz \
    --cc=dtor_core@ameritech.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox