]> Pileus Git - ~andy/linux/blobdiff - sound/core/compress_offload.c
ALSA: compress_core: Rework writes to use cumulative values
[~andy/linux] / sound / core / compress_offload.c
index 36d7688fe69ab0a51c4fe3d0ef21411bcb1a2bc5..7941ace782833e78026cb9c9b8494f27fc8b2d2c 100644 (file)
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/list.h>
+#include <linux/math64.h>
 #include <linux/mm.h>
 #include <linux/mutex.h>
 #include <linux/poll.h>
 #include <linux/slab.h>
 #include <linux/sched.h>
+#include <linux/types.h>
 #include <linux/uio.h>
 #include <linux/uaccess.h>
 #include <linux/module.h>
@@ -223,21 +225,24 @@ static int snd_compr_write_data(struct snd_compr_stream *stream,
        void *dstn;
        size_t copy;
        struct snd_compr_runtime *runtime = stream->runtime;
+       /* 64-bit Modulus */
+       u64 app_pointer = div64_u64(runtime->total_bytes_available,
+                                   runtime->buffer_size);
+       app_pointer = runtime->total_bytes_available -
+                     (app_pointer * runtime->buffer_size);
 
-       dstn = runtime->buffer + runtime->app_pointer;
+       dstn = runtime->buffer + app_pointer;
        pr_debug("copying %ld at %lld\n",
-                       (unsigned long)count, runtime->app_pointer);
-       if (count < runtime->buffer_size - runtime->app_pointer) {
+                       (unsigned long)count, app_pointer);
+       if (count < runtime->buffer_size - app_pointer) {
                if (copy_from_user(dstn, buf, count))
                        return -EFAULT;
-               runtime->app_pointer += count;
        } else {
-               copy = runtime->buffer_size - runtime->app_pointer;
+               copy = runtime->buffer_size - app_pointer;
                if (copy_from_user(dstn, buf, copy))
                        return -EFAULT;
                if (copy_from_user(runtime->buffer, buf + copy, count - copy))
                        return -EFAULT;
-               runtime->app_pointer = count - copy;
        }
        /* if DSP cares, let it know data has been written */
        if (stream->ops->ack)
@@ -656,7 +661,6 @@ static int snd_compr_stop(struct snd_compr_stream *stream)
        if (!retval) {
                stream->runtime->state = SNDRV_PCM_STATE_SETUP;
                wake_up(&stream->runtime->sleep);
-               stream->runtime->app_pointer = 0;
                stream->runtime->total_bytes_available = 0;
                stream->runtime->total_bytes_transferred = 0;
        }