From: Takashi Iwai Subject: Re: How to report error in _pointer function? Date: Mon, 11 Aug 2008 09:19:20 +0200 Message-ID: References: <489A1D9E.7040709@freescale.com> <489CC803.9030408@freescale.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id DF0A510380A for ; Mon, 11 Aug 2008 09:19:20 +0200 (CEST) In-Reply-To: <489CC803.9030408@freescale.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Timur Tabi Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Fri, 08 Aug 2008 17:26:11 -0500, Timur Tabi wrote: > > Takashi Iwai wrote: > > > So, the PCM status is properly changed to XRUN as expected. From the > > driver perspective, everything must be fine. > > I've been debugging aplay. The main loop is function pcm_write(). It calls > writei_func() which returns -EPIPE. This causes aplay to jump to xrun(), which > attempts to recover. > > This is not what I want. I don't want to return overrun/underrun. I want to > return failure. Returning XRUN is wrong. > > Instead, I need to take a look at this code I have: > > snd_pcm_stream_lock_irqsave(substream, flags); > > if (snd_pcm_running(substream)) > snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); > > snd_pcm_stream_unlock_irqrestore(substream, flags); > > It's the call to snd_pcm_stop() that I don't like. There doesn't appear to be a > SNDRV_PCM_STATE_xxx state that makes sense. This function should eventually > bring me to snd_pcm_pre_stop(). But this function returns -EBADFD because the > current state is RUNNING and not OPEN. Because it returns an error, > snd_pcm_do_stop() is never called. Hm? snd_pcm_pre_stop() returns -EBADFD if the stream *IS* OPEN. If it's RUNNING, it will stop the stream and change the state. > This doesn't make any sense to me. Why should I be able to stop a stream only > if it's open but not running? If it's open, but not running, then there's > nothing to stop! Can you explain the restriction in snd_pcm_pre_stop()? If the state is OPEN, it means that the stream is already stopped. Not sure which version you are referring, but I see no problem in the current code, at least... Takashi