[Bug 71268] Kernel bug?: read() from /dev/dsp returns more data than read size

Timothy Miller theosib at gmail.com
Sat Nov 11 07:14:40 UTC 2006

Public bug reported:

I've written a program that reads from /dev/dsp at its default rate of
8KHz and 8 bits per sample.  I'm using kernel "2.6.15-27-386 #1

Here's a snippet of code from my program:

    int in;
    int i;
    int n, status, blocksize, divisor=16;
    unsigned char buf[8192];
    in = open("/dev/dsp", O_RDONLY | O_NONBLOCK);
    status = ioctl(in, SNDCTL_DSP_GETBLKSIZE, &blocksize);
    if (status ==  -1)
        perror("SNFCTL_DSP_GETBLKSIZE ioctl failed");
    printf("%d\n", blocksize);
    ioctl(in, SOUND_PCM_SUBDIVIDE, &divisor);
    while (1) {
        n = read(in, buf, 1024);
        if (n<0) continue;

Note how the read() requests only 1024 bytes. 

The first time this read() is done, the return value is 4096.

Now, 4096 is the default size of the DMA buffer in the kernel.  So what
I think is happening here is that since I'm doing something unusual
(requesting less than one block of data), a kernel bug is showing up
where it pushes more data into my buffer than what I asked for.

Please push this to LKML.

** Affects: linux-source-2.6.15 (Ubuntu)
     Importance: Undecided
         Status: Unconfirmed

Kernel bug?: read() from /dev/dsp returns more data than read size

More information about the kernel-bugs mailing list