Skip to contentSkip to conversation

CVS: alsa-kernel/core/oss pcm_oss.c,1.87,1.88

alsa-cvslog Jaroslav Kysela 3 participants 4 messages May 27, 2005 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 11 lines · Clemens Ladisch

Update of /cvsroot/alsa/alsa-kernel/core/oss
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1617

Modified Files:
pcm_oss.c
Log Message:
Summary: pcm_oss - fix SNDCTL_DSP_GETOPTR not working correctly

This patch changes snd_pcm_oss_bytes() by adding a local variable for the frames -> bytes conversion, which means that the frame count is no longer corrupted by this conversion.

It seems like a wrong patch to me. We cannot mix frames with bytes (see last expression). I think that there is a overflow in the return expression.

Jaroslav

Quoted 15 lines

Index: pcm_oss.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/oss/pcm_oss.c,v retrieving revision 1.87
retrieving revision 1.88
diff -u -r1.87 -r1.88

pcm_oss.c +0 -0
@@ -124,11 +124,12 @@
 
 static long snd_pcm_oss_bytes(snd_pcm_substream_t *substream, long frames)
 {

pcm_oss.c line 134

Quoted 10 lines
pcm_oss.c +3 -2
+	long bytes = 0;
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	snd_pcm_uframes_t buffer_size = snd_pcm_lib_buffer_bytes(substream);
-	frames = frames_to_bytes(runtime, frames);
+	bytes = frames_to_bytes(runtime, frames);
 	if (buffer_size == runtime->oss.buffer_bytes)
-		return frames;
+		return bytes;
 	return (runtime->oss.buffer_bytes * frames) / buffer_size;
 }

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs

-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo! Search APIs Find out how you can build Yahoo! directly into your own Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005

#2 lore raw
Quoted 6 lines · Jaroslav Kysela
Quoted 5 lines · Clemens Ladisch

Modified Files:
pcm_oss.c
Log Message:
Summary: pcm_oss - fix SNDCTL_DSP_GETOPTR not working correctly

Quoted 6 lines
Quoted 3 lines

This patch changes snd_pcm_oss_bytes() by adding a local variable for the frames -> bytes conversion, which means that the frame count is no longer corrupted by this conversion.

It seems like a wrong patch to me. We cannot mix frames with bytes (see last expression).

I assumed that buffer_size would be in frames (due to its type), but this is obviously wroung.

Quoted 7 lines

This reverts the last patch which wrongly mixes bytes and frames. The real culprit might be the 32-bit overflow, so the return expression uses 64-bit values now in snd_pcm_oss_bytes().

static long snd_pcm_oss_bytes(snd_pcm_substream_t *substream, long frames) {

(quoted diff) +0 -1
-     long bytes = 0;

Review

Quoted 10 lines
(quoted diff) +3 -3
      snd_pcm_runtime_t *runtime = substream->runtime;
      snd_pcm_uframes_t buffer_size = snd_pcm_lib_buffer_bytes(substream);
-     bytes = frames_to_bytes(runtime, frames);
+     frames = frames_to_bytes(runtime, frames);
      if (buffer_size == runtime->oss.buffer_bytes)
-             return bytes;
-     return (runtime->oss.buffer_bytes * frames) / buffer_size;
+             return frames;
+     return (long)(((int64_t)runtime->oss.buffer_bytes * (int64_t)frames) / (int64_t)buffer_size);
 }

This still uses a misleading type for buffer_size, and uses 'frames' for a value not measure in frames. I think I'd better rename these. Any objections?

Regards,
Clemens

-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo! Search APIs Find out how you can build Yahoo! directly into your own Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005

#3 lore raw

At Fri, 27 May 2005 11:23:17 +0200 (METDST),

Quoted 19 lines · Clemens Ladisch
Quoted 8 lines

This reverts the last patch which wrongly mixes bytes and frames. The real culprit might be the 32-bit overflow, so the return expression uses 64-bit values now in snd_pcm_oss_bytes().

static long snd_pcm_oss_bytes(snd_pcm_substream_t *substream, long frames) {

(quoted diff) +0 -1
-     long bytes = 0;

Review

Quoted 10 lines
(quoted diff) +3 -3
      snd_pcm_runtime_t *runtime = substream->runtime;
      snd_pcm_uframes_t buffer_size = snd_pcm_lib_buffer_bytes(substream);
-     bytes = frames_to_bytes(runtime, frames);
+     frames = frames_to_bytes(runtime, frames);
      if (buffer_size == runtime->oss.buffer_bytes)
-             return bytes;
-     return (runtime->oss.buffer_bytes * frames) / buffer_size;
+             return frames;
+     return (long)(((int64_t)runtime->oss.buffer_bytes * (int64_t)frames) / (int64_t)buffer_size);
 }
Quoted 3 lines

This still uses a misleading type for buffer_size, and uses 'frames' for a value not measure in frames. I think I'd better rename these. Any objections?

I second.

Takashi

-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo! Search APIs Find out how you can build Yahoo! directly into your own Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005

#4 lore raw
In reply to Clemens Ladisch
Quoted 3 lines · Clemens Ladisch

This still uses a misleading type for buffer_size, and uses 'frames' for a value not measure in frames. I think I'd better rename these. Any objections?

Done.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs

-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo! Search APIs Find out how you can build Yahoo! directly into your own Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005