All of lore.kernel.org
 help / color / mirror / Atom feed
* ALSA: pcm: fix fifo_size frame calculation
@ 2014-09-21 20:50 Clemens Ladisch
  2014-09-22  7:02 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Clemens Ladisch @ 2014-09-21 20:50 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

The calculated frame size was wrong because snd_pcm_format_physical_width()
actually returns the number of bits, not bytes.

Use snd_pcm_format_size() instead, which not only returns bytes, but also
simplifies the calculation.

Fixes: 8bea869c5e56 ("ALSA: PCM midlevel: improve fifo_size handling")
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
---
 sound/core/pcm_lib.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index b03c7ae..dfc2854 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1784,14 +1784,16 @@ static int snd_pcm_lib_ioctl_fifo_size(struct snd_pcm_substream *substream,
 {
 	struct snd_pcm_hw_params *params = arg;
 	snd_pcm_format_t format;
-	int channels, width;
+	int channels;
+	ssize_t frame_size;

 	params->fifo_size = substream->runtime->hw.fifo_size;
 	if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_FIFO_IN_FRAMES)) {
 		format = params_format(params);
 		channels = params_channels(params);
-		width = snd_pcm_format_physical_width(format);
-		params->fifo_size /= width * channels;
+		frame_size = snd_pcm_format_size(format, channels);
+		if (frame_size > 0)
+			params->fifo_size /= (unsigned)frame_size;
 	}
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: ALSA: pcm: fix fifo_size frame calculation
  2014-09-21 20:50 ALSA: pcm: fix fifo_size frame calculation Clemens Ladisch
@ 2014-09-22  7:02 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2014-09-22  7:02 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel

At Sun, 21 Sep 2014 22:50:57 +0200,
Clemens Ladisch wrote:
> 
> The calculated frame size was wrong because snd_pcm_format_physical_width()
> actually returns the number of bits, not bytes.
> 
> Use snd_pcm_format_size() instead, which not only returns bytes, but also
> simplifies the calculation.
> 
> Fixes: 8bea869c5e56 ("ALSA: PCM midlevel: improve fifo_size handling")
> Signed-off-by: Clemens Ladisch <clemens@ladisch.de>

Thanks, applied now.  I put Cc to stable as this is a clear bug fix.


Takashi

> ---
>  sound/core/pcm_lib.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
> index b03c7ae..dfc2854 100644
> --- a/sound/core/pcm_lib.c
> +++ b/sound/core/pcm_lib.c
> @@ -1784,14 +1784,16 @@ static int snd_pcm_lib_ioctl_fifo_size(struct snd_pcm_substream *substream,
>  {
>  	struct snd_pcm_hw_params *params = arg;
>  	snd_pcm_format_t format;
> -	int channels, width;
> +	int channels;
> +	ssize_t frame_size;
> 
>  	params->fifo_size = substream->runtime->hw.fifo_size;
>  	if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_FIFO_IN_FRAMES)) {
>  		format = params_format(params);
>  		channels = params_channels(params);
> -		width = snd_pcm_format_physical_width(format);
> -		params->fifo_size /= width * channels;
> +		frame_size = snd_pcm_format_size(format, channels);
> +		if (frame_size > 0)
> +			params->fifo_size /= (unsigned)frame_size;
>  	}
>  	return 0;
>  }
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-09-22  7:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-21 20:50 ALSA: pcm: fix fifo_size frame calculation Clemens Ladisch
2014-09-22  7:02 ` Takashi Iwai

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.