From: Takashi Iwai Subject: Re: Alsa timer: ioctl problem/bug Date: Tue, 14 Jun 2005 10:37:09 +0200 Message-ID: References: <20050613174846.6CE911224B@sc8-sf-spam2.sourceforge.net> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: <200506140120.j5E1K51n010124@auster.physics.adelaide.edu.au> Sender: alsa-devel-admin@lists.sourceforge.net Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Jonathan Woithe Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org At Tue, 14 Jun 2005 10:50:05 +0930 (CST), Jonathan Woithe wrote: > > Hi all > > I think I have discovered a problem with the alsa timer - in particular, the > alsalib snd_timer_stop() call. In short, it doesn't work - a running timer > isn't stopped and the call often (but not always) returns an error of -14 > (-EFAULT). > > The reason for this turns out to be the definition of the > SNDRV_TIMER_IOCTL_STOP ioctl request in asound.h from alsa-driver. This > is currently defined as > > #define SNDRV_TIMER_IOCTL_STOP _IO('T',0x21) > > which resolves to 0x5421. The problem is that this is exactly the same as > the FIONBIO request used by the vfs kernel layer to control non-blocking > behaviour. When a program calls alsalib's snd_timer_stop(), the > SNDRV_TIMER_IOCTL_STOP ioctl is invoked. However, the alsa-driver never > sees this because the vfs layer sees it as a FIONBIO request first and tries > to set the file's non-blocking behaviour according to the parameter FIONBIO > expects. Of course in the case of a SNDRV_TIMER_IOCTL_STOP request we don't > pass any parameter, so the vfs FIONBIO handler accesses whatever happens to > be on the stack at the time. Sometimes it's a valid address and sometimes > it's not. When it is, the non-blocking behaviour of the alsa timer handler > is set to whatever the random stack data happens to indicate; when it's not > we get the EFAULT return from snd_timer_stop(). In both cases the alsa > timer is not stopped. > > The fix is conceptually simple: just change the magic 'T' in the > SNDRV_TIMER_IOCTL_STOP define in alsa-driver's asound.h to something else to > avoid the clash (and note that the SNDRV_TIMER_IOCTL_STOP_OLD define in > alsa-lib's timer/timer_hw.c also needs to be updated to match). As a proof > concept I tried 'U' and I was then able to stop the timer successfully. > > However, I don't know what the ALSA developers want to do here. Do we just > change the SNDRV_TIMER_IOCTL_STOP define, or should all SNDRV_TIMER_IOCTL_* > defines be changed to keep them consistent? My own thought is to change all > SNDRV_TIMER_IOCTL_* defines to avoid clashes with the "standard" ioctl > requests defined in asm/ioctls.h to remove the chances of this kind of > thing cropping up again in future. It's already fixed in ALSA 1.0.9 release. The releveant ioctl numbers were changed. Takashi ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20