ALSA: pcm: Call directly the common read/write helpers
authorTakashi Iwai <tiwai@suse.de>
Sun, 21 May 2017 07:35:21 +0000 (09:35 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 2 Jun 2017 17:38:21 +0000 (19:38 +0200)
Make snd_pcm_lib_read() and *_write() static inline functions that
call the common helper functions directly.  This reduces a slight
amount of codes, and at the same time, it's a preparation for the
further cleanups / fixes.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/pcm.h
sound/core/pcm_lib.c

index 0da5117..0fac948 100644 (file)
@@ -1072,15 +1072,40 @@ void snd_pcm_set_sync(struct snd_pcm_substream *substream);
 int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
                      unsigned int cmd, void *arg);                      
 void snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
-snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream,
-                                   const void __user *buf,
-                                   snd_pcm_uframes_t frames);
-snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream *substream,
-                                  void __user *buf, snd_pcm_uframes_t frames);
-snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream,
-                                    void __user **bufs, snd_pcm_uframes_t frames);
-snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream,
-                                   void __user **bufs, snd_pcm_uframes_t frames);
+snd_pcm_sframes_t __snd_pcm_lib_write(struct snd_pcm_substream *substream,
+                                     void *buf, bool interleaved,
+                                     snd_pcm_uframes_t frames);
+snd_pcm_sframes_t __snd_pcm_lib_read(struct snd_pcm_substream *substream,
+                                    void *buf, bool interleaved,
+                                    snd_pcm_uframes_t frames);
+
+static inline snd_pcm_sframes_t
+snd_pcm_lib_write(struct snd_pcm_substream *substream,
+                 const void __user *buf, snd_pcm_uframes_t frames)
+{
+       return __snd_pcm_lib_write(substream, (void *)buf, true, frames);
+}
+
+static inline snd_pcm_sframes_t
+snd_pcm_lib_read(struct snd_pcm_substream *substream,
+                void __user *buf, snd_pcm_uframes_t frames)
+{
+       return __snd_pcm_lib_read(substream, (void *)buf, true, frames);
+}
+
+static inline snd_pcm_sframes_t
+snd_pcm_lib_writev(struct snd_pcm_substream *substream,
+                  void __user **bufs, snd_pcm_uframes_t frames)
+{
+       return __snd_pcm_lib_write(substream, (void *)bufs, false, frames);
+}
+
+static inline snd_pcm_sframes_t
+snd_pcm_lib_readv(struct snd_pcm_substream *substream,
+                 void __user **bufs, snd_pcm_uframes_t frames)
+{
+       return __snd_pcm_lib_read(substream, (void *)bufs, false, frames);
+}
 
 int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
 unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
index 51eeea9..ae030c5 100644 (file)
@@ -1994,12 +1994,12 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
 }
        
 typedef int (*transfer_f)(struct snd_pcm_substream *substream, unsigned int hwoff,
-                         unsigned long data, unsigned int off,
+                         void  *data, unsigned int off,
                          snd_pcm_uframes_t size);
 
 static int snd_pcm_lib_write_transfer(struct snd_pcm_substream *substream,
                                      unsigned int hwoff,
-                                     unsigned long data, unsigned int off,
+                                     void *data, unsigned int off,
                                      snd_pcm_uframes_t frames)
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
@@ -2021,7 +2021,7 @@ static int snd_pcm_lib_write_transfer(struct snd_pcm_substream *substream,
  
 static int snd_pcm_lib_writev_transfer(struct snd_pcm_substream *substream,
                                       unsigned int hwoff,
-                                      unsigned long data, unsigned int off,
+                                      void *data, unsigned int off,
                                       snd_pcm_uframes_t frames)
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
@@ -2098,21 +2098,39 @@ static int pcm_accessible_state(struct snd_pcm_runtime *runtime)
        }
 }
 
-static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream, 
-                                           unsigned long data,
-                                           snd_pcm_uframes_t size,
-                                           int nonblock,
-                                           transfer_f transfer)
+snd_pcm_sframes_t __snd_pcm_lib_write(struct snd_pcm_substream *substream,
+                                     void *data, bool interleaved,
+                                     snd_pcm_uframes_t size)
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
        snd_pcm_uframes_t xfer = 0;
        snd_pcm_uframes_t offset = 0;
        snd_pcm_uframes_t avail;
-       int err = 0;
+       transfer_f transfer;
+       bool nonblock;
+       int err;
+
+       err = pcm_sanity_check(substream);
+       if (err < 0)
+               return err;
+       runtime = substream->runtime;
+
+       if (interleaved) {
+               if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED &&
+                   runtime->channels > 1)
+                       return -EINVAL;
+               transfer = snd_pcm_lib_write_transfer;
+       } else {
+               if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
+                       return -EINVAL;
+               transfer = snd_pcm_lib_writev_transfer;
+       }
 
        if (size == 0)
                return 0;
 
+       nonblock = !!(substream->f_flags & O_NONBLOCK);
+
        snd_pcm_stream_lock_irq(substream);
        err = pcm_accessible_state(runtime);
        if (err < 0)
@@ -2180,53 +2198,11 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
        snd_pcm_stream_unlock_irq(substream);
        return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
 }
-
-snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream, const void __user *buf, snd_pcm_uframes_t size)
-{
-       struct snd_pcm_runtime *runtime;
-       int nonblock;
-       int err;
-
-       err = pcm_sanity_check(substream);
-       if (err < 0)
-               return err;
-       runtime = substream->runtime;
-       nonblock = !!(substream->f_flags & O_NONBLOCK);
-
-       if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED &&
-           runtime->channels > 1)
-               return -EINVAL;
-       return snd_pcm_lib_write1(substream, (unsigned long)buf, size, nonblock,
-                                 snd_pcm_lib_write_transfer);
-}
-
-EXPORT_SYMBOL(snd_pcm_lib_write);
-
-snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream,
-                                    void __user **bufs,
-                                    snd_pcm_uframes_t frames)
-{
-       struct snd_pcm_runtime *runtime;
-       int nonblock;
-       int err;
-
-       err = pcm_sanity_check(substream);
-       if (err < 0)
-               return err;
-       runtime = substream->runtime;
-       nonblock = !!(substream->f_flags & O_NONBLOCK);
-
-       if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
-               return -EINVAL;
-       return snd_pcm_lib_write1(substream, (unsigned long)bufs, frames,
-                                 nonblock, snd_pcm_lib_writev_transfer);
-}
-
-EXPORT_SYMBOL(snd_pcm_lib_writev);
+EXPORT_SYMBOL(__snd_pcm_lib_write);
 
 static int snd_pcm_lib_read_transfer(struct snd_pcm_substream *substream, 
                                     unsigned int hwoff,
-                                    unsigned long data, unsigned int off,
+                                    void *data, unsigned int off,
                                     snd_pcm_uframes_t frames)
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
@@ -2248,7 +2224,7 @@ static int snd_pcm_lib_read_transfer(struct snd_pcm_substream *substream,
 
 static int snd_pcm_lib_readv_transfer(struct snd_pcm_substream *substream,
                                      unsigned int hwoff,
-                                     unsigned long data, unsigned int off,
+                                     void *data, unsigned int off,
                                      snd_pcm_uframes_t frames)
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
@@ -2286,21 +2262,39 @@ static int snd_pcm_lib_readv_transfer(struct snd_pcm_substream *substream,
        return 0;
 }
 
-static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream,
-                                          unsigned long data,
-                                          snd_pcm_uframes_t size,
-                                          int nonblock,
-                                          transfer_f transfer)
+snd_pcm_sframes_t __snd_pcm_lib_read(struct snd_pcm_substream *substream,
+                                    void *data, bool interleaved,
+                                    snd_pcm_uframes_t size)
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
        snd_pcm_uframes_t xfer = 0;
        snd_pcm_uframes_t offset = 0;
        snd_pcm_uframes_t avail;
-       int err = 0;
+       transfer_f transfer;
+       bool nonblock;
+       int err;
+
+       err = pcm_sanity_check(substream);
+       if (err < 0)
+               return err;
+       runtime = substream->runtime;
+
+       if (interleaved) {
+               if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED &&
+                   runtime->channels > 1)
+                       return -EINVAL;
+               transfer = snd_pcm_lib_read_transfer;
+       } else {
+               if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
+                       return -EINVAL;
+               transfer = snd_pcm_lib_readv_transfer;
+       }
 
        if (size == 0)
                return 0;
 
+       nonblock = !!(substream->f_flags & O_NONBLOCK);
+
        snd_pcm_stream_lock_irq(substream);
        err = pcm_accessible_state(runtime);
        if (err < 0)
@@ -2375,47 +2369,7 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream,
        snd_pcm_stream_unlock_irq(substream);
        return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
 }
-
-snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream *substream, void __user *buf, snd_pcm_uframes_t size)
-{
-       struct snd_pcm_runtime *runtime;
-       int nonblock;
-       int err;
-       
-       err = pcm_sanity_check(substream);
-       if (err < 0)
-               return err;
-       runtime = substream->runtime;
-       nonblock = !!(substream->f_flags & O_NONBLOCK);
-       if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED)
-               return -EINVAL;
-       return snd_pcm_lib_read1(substream, (unsigned long)buf, size, nonblock, snd_pcm_lib_read_transfer);
-}
-
-EXPORT_SYMBOL(snd_pcm_lib_read);
-
-snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream,
-                                   void __user **bufs,
-                                   snd_pcm_uframes_t frames)
-{
-       struct snd_pcm_runtime *runtime;
-       int nonblock;
-       int err;
-
-       err = pcm_sanity_check(substream);
-       if (err < 0)
-               return err;
-       runtime = substream->runtime;
-       if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
-               return -EBADFD;
-
-       nonblock = !!(substream->f_flags & O_NONBLOCK);
-       if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
-               return -EINVAL;
-       return snd_pcm_lib_read1(substream, (unsigned long)bufs, frames, nonblock, snd_pcm_lib_readv_transfer);
-}
-
-EXPORT_SYMBOL(snd_pcm_lib_readv);
+EXPORT_SYMBOL(__snd_pcm_lib_read);
 
 /*
  * standard channel mapping helpers