ALSA: firewire-digi00x: enclose identifiers referred by single function
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Thu, 5 Jan 2017 12:48:11 +0000 (21:48 +0900)
committerTakashi Iwai <tiwai@suse.de>
Thu, 5 Jan 2017 15:58:07 +0000 (16:58 +0100)
Some identifiers are referred just by one functions. In this case, they
can be put into the function definition. This brings two merits; readers
can easily follow codes related to the identifiers, developers are free
from name conflict.

This commit moves such identifiers to each function definition.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/firewire/digi00x/digi00x-hwdep.c
sound/firewire/digi00x/digi00x-midi.c
sound/firewire/digi00x/digi00x-pcm.c

index f188e4758fd295ecb9a3db341c1c6606d40d06c4..463c6b8e864d025bae08b931705c0fae2d71d952 100644 (file)
@@ -173,16 +173,15 @@ static int hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file,
 #define hwdep_compat_ioctl NULL
 #endif
 
-static const struct snd_hwdep_ops hwdep_ops = {
-       .read           = hwdep_read,
-       .release        = hwdep_release,
-       .poll           = hwdep_poll,
-       .ioctl          = hwdep_ioctl,
-       .ioctl_compat   = hwdep_compat_ioctl,
-};
-
 int snd_dg00x_create_hwdep_device(struct snd_dg00x *dg00x)
 {
+       static const struct snd_hwdep_ops ops = {
+               .read           = hwdep_read,
+               .release        = hwdep_release,
+               .poll           = hwdep_poll,
+               .ioctl          = hwdep_ioctl,
+               .ioctl_compat   = hwdep_compat_ioctl,
+       };
        struct snd_hwdep *hwdep;
        int err;
 
@@ -192,7 +191,7 @@ int snd_dg00x_create_hwdep_device(struct snd_dg00x *dg00x)
 
        strcpy(hwdep->name, "Digi00x");
        hwdep->iface = SNDRV_HWDEP_IFACE_FW_DIGI00X;
-       hwdep->ops = hwdep_ops;
+       hwdep->ops = ops;
        hwdep->private_data = dg00x;
        hwdep->exclusive = true;
 
index 1a72a382b384beb5b8ab92c3f65c72920c4d510b..8689c3bb4c6a114ee68082458dbbfe48d7d376f1 100644 (file)
@@ -76,18 +76,6 @@ static void midi_phys_playback_trigger(struct snd_rawmidi_substream *substream,
        spin_unlock_irqrestore(&dg00x->lock, flags);
 }
 
-static struct snd_rawmidi_ops midi_phys_capture_ops = {
-       .open           = midi_phys_open,
-       .close          = midi_phys_close,
-       .trigger        = midi_phys_capture_trigger,
-};
-
-static struct snd_rawmidi_ops midi_phys_playback_ops = {
-       .open           = midi_phys_open,
-       .close          = midi_phys_close,
-       .trigger        = midi_phys_playback_trigger,
-};
-
 static int midi_ctl_open(struct snd_rawmidi_substream *substream)
 {
        /* Do nothing. */
@@ -139,18 +127,6 @@ static void midi_ctl_playback_trigger(struct snd_rawmidi_substream *substream,
        spin_unlock_irqrestore(&dg00x->lock, flags);
 }
 
-static struct snd_rawmidi_ops midi_ctl_capture_ops = {
-       .open           = midi_ctl_open,
-       .close          = midi_ctl_capture_close,
-       .trigger        = midi_ctl_capture_trigger,
-};
-
-static struct snd_rawmidi_ops midi_ctl_playback_ops = {
-       .open           = midi_ctl_open,
-       .close          = midi_ctl_playback_close,
-       .trigger        = midi_ctl_playback_trigger,
-};
-
 static void set_midi_substream_names(struct snd_dg00x *dg00x,
                                     struct snd_rawmidi_str *str,
                                     bool is_ctl)
@@ -172,6 +148,26 @@ static void set_midi_substream_names(struct snd_dg00x *dg00x,
 
 int snd_dg00x_create_midi_devices(struct snd_dg00x *dg00x)
 {
+       static struct snd_rawmidi_ops phys_capture_ops = {
+               .open           = midi_phys_open,
+               .close          = midi_phys_close,
+               .trigger        = midi_phys_capture_trigger,
+       };
+       static struct snd_rawmidi_ops phys_playback_ops = {
+               .open           = midi_phys_open,
+               .close          = midi_phys_close,
+               .trigger        = midi_phys_playback_trigger,
+       };
+       static struct snd_rawmidi_ops ctl_capture_ops = {
+               .open           = midi_ctl_open,
+               .close          = midi_ctl_capture_close,
+               .trigger        = midi_ctl_capture_trigger,
+       };
+       static struct snd_rawmidi_ops ctl_playback_ops = {
+               .open           = midi_ctl_open,
+               .close          = midi_ctl_playback_close,
+               .trigger        = midi_ctl_playback_trigger,
+       };
        struct snd_rawmidi *rmidi[2];
        struct snd_rawmidi_str *str;
        unsigned int i;
@@ -187,9 +183,9 @@ int snd_dg00x_create_midi_devices(struct snd_dg00x *dg00x)
                 "%s MIDI", dg00x->card->shortname);
 
        snd_rawmidi_set_ops(rmidi[0], SNDRV_RAWMIDI_STREAM_INPUT,
-                           &midi_phys_capture_ops);
+                           &phys_capture_ops);
        snd_rawmidi_set_ops(rmidi[0], SNDRV_RAWMIDI_STREAM_OUTPUT,
-                           &midi_phys_playback_ops);
+                           &phys_playback_ops);
 
        /* Add a pair of control midi ports. */
        err = snd_rawmidi_new(dg00x->card, dg00x->card->driver, 1,
@@ -201,9 +197,9 @@ int snd_dg00x_create_midi_devices(struct snd_dg00x *dg00x)
                 "%s control", dg00x->card->shortname);
 
        snd_rawmidi_set_ops(rmidi[1], SNDRV_RAWMIDI_STREAM_INPUT,
-                           &midi_ctl_capture_ops);
+                           &ctl_capture_ops);
        snd_rawmidi_set_ops(rmidi[1], SNDRV_RAWMIDI_STREAM_OUTPUT,
-                           &midi_ctl_playback_ops);
+                           &ctl_playback_ops);
 
        for (i = 0; i < ARRAY_SIZE(rmidi); i++) {
                rmidi[i]->private_data = dg00x;
index 613f05872770807698a58ad64fb8de8018c43f6f..68d1c52db051f13629aee1a6d291f1061338b954 100644 (file)
@@ -329,33 +329,31 @@ static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstrm)
        return amdtp_stream_pcm_pointer(&dg00x->rx_stream);
 }
 
-static const struct snd_pcm_ops pcm_capture_ops = {
-       .open           = pcm_open,
-       .close          = pcm_close,
-       .ioctl          = snd_pcm_lib_ioctl,
-       .hw_params      = pcm_capture_hw_params,
-       .hw_free        = pcm_capture_hw_free,
-       .prepare        = pcm_capture_prepare,
-       .trigger        = pcm_capture_trigger,
-       .pointer        = pcm_capture_pointer,
-       .page           = snd_pcm_lib_get_vmalloc_page,
-};
-
-static const struct snd_pcm_ops pcm_playback_ops = {
-       .open           = pcm_open,
-       .close          = pcm_close,
-       .ioctl          = snd_pcm_lib_ioctl,
-       .hw_params      = pcm_playback_hw_params,
-       .hw_free        = pcm_playback_hw_free,
-       .prepare        = pcm_playback_prepare,
-       .trigger        = pcm_playback_trigger,
-       .pointer        = pcm_playback_pointer,
-       .page           = snd_pcm_lib_get_vmalloc_page,
-       .mmap           = snd_pcm_lib_mmap_vmalloc,
-};
-
 int snd_dg00x_create_pcm_devices(struct snd_dg00x *dg00x)
 {
+       static const struct snd_pcm_ops capture_ops = {
+               .open           = pcm_open,
+               .close          = pcm_close,
+               .ioctl          = snd_pcm_lib_ioctl,
+               .hw_params      = pcm_capture_hw_params,
+               .hw_free        = pcm_capture_hw_free,
+               .prepare        = pcm_capture_prepare,
+               .trigger        = pcm_capture_trigger,
+               .pointer        = pcm_capture_pointer,
+               .page           = snd_pcm_lib_get_vmalloc_page,
+       };
+       static const struct snd_pcm_ops playback_ops = {
+               .open           = pcm_open,
+               .close          = pcm_close,
+               .ioctl          = snd_pcm_lib_ioctl,
+               .hw_params      = pcm_playback_hw_params,
+               .hw_free        = pcm_playback_hw_free,
+               .prepare        = pcm_playback_prepare,
+               .trigger        = pcm_playback_trigger,
+               .pointer        = pcm_playback_pointer,
+               .page           = snd_pcm_lib_get_vmalloc_page,
+               .mmap           = snd_pcm_lib_mmap_vmalloc,
+       };
        struct snd_pcm *pcm;
        int err;
 
@@ -366,8 +364,8 @@ int snd_dg00x_create_pcm_devices(struct snd_dg00x *dg00x)
        pcm->private_data = dg00x;
        snprintf(pcm->name, sizeof(pcm->name),
                 "%s PCM", dg00x->card->shortname);
-       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &pcm_playback_ops);
-       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pcm_capture_ops);
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_ops);
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_ops);
 
        return 0;
 }