ALSA: info - Implement common llseek for binary mode
[deliverable/linux.git] / sound / drivers / opl4 / opl4_proc.c
index f4b4e74fcc18564acc2fdf8f5af9d91a90a8b2b0..c5c13c4c260e91009f0eafc8e8e500328e9c7849 100644 (file)
@@ -28,13 +28,13 @@ static int snd_opl4_mem_proc_open(struct snd_info_entry *entry,
 {
        struct snd_opl4 *opl4 = entry->private_data;
 
-       down(&opl4->access_mutex);
+       mutex_lock(&opl4->access_mutex);
        if (opl4->memory_access) {
-               up(&opl4->access_mutex);
+               mutex_unlock(&opl4->access_mutex);
                return -EBUSY;
        }
        opl4->memory_access++;
-       up(&opl4->access_mutex);
+       mutex_unlock(&opl4->access_mutex);
        return 0;
 }
 
@@ -43,83 +43,51 @@ static int snd_opl4_mem_proc_release(struct snd_info_entry *entry,
 {
        struct snd_opl4 *opl4 = entry->private_data;
 
-       down(&opl4->access_mutex);
+       mutex_lock(&opl4->access_mutex);
        opl4->memory_access--;
-       up(&opl4->access_mutex);
+       mutex_unlock(&opl4->access_mutex);
        return 0;
 }
 
-static long snd_opl4_mem_proc_read(struct snd_info_entry *entry, void *file_private_data,
-                                  struct file *file, char __user *_buf,
-                                  unsigned long count, unsigned long pos)
+static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,
+                                     void *file_private_data,
+                                     struct file *file, char __user *_buf,
+                                     size_t count, loff_t pos)
 {
        struct snd_opl4 *opl4 = entry->private_data;
-       long size;
        char* buf;
 
-       size = count;
-       if (pos + size > entry->size)
-               size = entry->size - pos;
-       if (size > 0) {
-               buf = vmalloc(size);
-               if (!buf)
-                       return -ENOMEM;
-               snd_opl4_read_memory(opl4, buf, pos, size);
-               if (copy_to_user(_buf, buf, size)) {
-                       vfree(buf);
-                       return -EFAULT;
-               }
+       buf = vmalloc(count);
+       if (!buf)
+               return -ENOMEM;
+       snd_opl4_read_memory(opl4, buf, pos, count);
+       if (copy_to_user(_buf, buf, count)) {
                vfree(buf);
-               return size;
+               return -EFAULT;
        }
-       return 0;
+       vfree(buf);
+       return count;
 }
 
-static long snd_opl4_mem_proc_write(struct snd_info_entry *entry, void *file_private_data,
-                                   struct file *file, const char __user *_buf,
-                                   unsigned long count, unsigned long pos)
+static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
+                                      void *file_private_data,
+                                      struct file *file,
+                                      const char __user *_buf,
+                                      size_t count, size_t pos)
 {
        struct snd_opl4 *opl4 = entry->private_data;
-       long size;
        char *buf;
 
-       size = count;
-       if (pos + size > entry->size)
-               size = entry->size - pos;
-       if (size > 0) {
-               buf = vmalloc(size);
-               if (!buf)
-                       return -ENOMEM;
-               if (copy_from_user(buf, _buf, size)) {
-                       vfree(buf);
-                       return -EFAULT;
-               }
-               snd_opl4_write_memory(opl4, buf, pos, size);
+       buf = vmalloc(count);
+       if (!buf)
+               return -ENOMEM;
+       if (copy_from_user(buf, _buf, count)) {
                vfree(buf);
-               return size;
-       }
-       return 0;
-}
-
-static long long snd_opl4_mem_proc_llseek(struct snd_info_entry *entry, void *file_private_data,
-                                         struct file *file, long long offset, int orig)
-{
-       switch (orig) {
-       case 0: /* SEEK_SET */
-               file->f_pos = offset;
-               break;
-       case 1: /* SEEK_CUR */
-               file->f_pos += offset;
-               break;
-       case 2: /* SEEK_END, offset is negative */
-               file->f_pos = entry->size + offset;
-               break;
-       default:
-               return -EINVAL;
+               return -EFAULT;
        }
-       if (file->f_pos > entry->size)
-               file->f_pos = entry->size;
-       return file->f_pos;
+       snd_opl4_write_memory(opl4, buf, pos, count);
+       vfree(buf);
+       return count;
 }
 
 static struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
@@ -127,7 +95,6 @@ static struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
        .release = snd_opl4_mem_proc_release,
        .read = snd_opl4_mem_proc_read,
        .write = snd_opl4_mem_proc_write,
-       .llseek = snd_opl4_mem_proc_llseek,
 };
 
 int snd_opl4_create_proc(struct snd_opl4 *opl4)
@@ -159,8 +126,7 @@ int snd_opl4_create_proc(struct snd_opl4 *opl4)
 
 void snd_opl4_free_proc(struct snd_opl4 *opl4)
 {
-       if (opl4->proc_entry)
-               snd_info_unregister(opl4->proc_entry);
+       snd_info_free_entry(opl4->proc_entry);
 }
 
 #endif /* CONFIG_PROC_FS */
This page took 0.026842 seconds and 5 git commands to generate.