[PATCH] mark struct file_operations const 9
[powerpc.git] / sound / core / rawmidi.c
index 8c15c66..d14dcbb 100644 (file)
@@ -55,21 +55,17 @@ static int snd_rawmidi_free(struct snd_rawmidi *rawmidi);
 static int snd_rawmidi_dev_free(struct snd_device *device);
 static int snd_rawmidi_dev_register(struct snd_device *device);
 static int snd_rawmidi_dev_disconnect(struct snd_device *device);
-static int snd_rawmidi_dev_unregister(struct snd_device *device);
 
 static LIST_HEAD(snd_rawmidi_devices);
 static DEFINE_MUTEX(register_mutex);
 
 static struct snd_rawmidi *snd_rawmidi_search(struct snd_card *card, int device)
 {
-       struct list_head *p;
        struct snd_rawmidi *rawmidi;
 
-       list_for_each(p, &snd_rawmidi_devices) {
-               rawmidi = list_entry(p, struct snd_rawmidi, list);
+       list_for_each_entry(rawmidi, &snd_rawmidi_devices, list)
                if (rawmidi->card == card && rawmidi->device == device)
                        return rawmidi;
-       }
        return NULL;
 }
 
@@ -390,7 +386,6 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
        struct snd_rawmidi *rmidi;
        struct snd_rawmidi_file *rawmidi_file;
        wait_queue_t wait;
-       struct list_head *list;
        struct snd_ctl_file *kctl;
 
        if (maj == snd_major) {
@@ -427,11 +422,11 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
        while (1) {
                subdevice = -1;
                down_read(&card->controls_rwsem);
-               list_for_each(list, &card->ctl_files) {
-                       kctl = snd_ctl_file(list);
+               list_for_each_entry(kctl, &card->ctl_files, list) {
                        if (kctl->pid == current->pid) {
                                subdevice = kctl->prefer_rawmidi_subdevice;
-                               break;
+                               if (subdevice != -1)
+                                       break;
                        }
                }
                up_read(&card->controls_rwsem);
@@ -575,7 +570,6 @@ int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info
        struct snd_rawmidi *rmidi;
        struct snd_rawmidi_str *pstr;
        struct snd_rawmidi_substream *substream;
-       struct list_head *list;
 
        mutex_lock(&register_mutex);
        rmidi = snd_rawmidi_search(card, info->device);
@@ -589,8 +583,7 @@ int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info
                return -ENOENT;
        if (info->subdevice >= pstr->substream_count)
                return -ENXIO;
-       list_for_each(list, &pstr->substreams) {
-               substream = list_entry(list, struct snd_rawmidi_substream, list);
+       list_for_each_entry(substream, &pstr->substreams, list) {
                if ((unsigned int)substream->number == info->subdevice)
                        return snd_rawmidi_info(substream, info);
        }
@@ -1313,14 +1306,14 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,
        struct snd_rawmidi *rmidi;
        struct snd_rawmidi_substream *substream;
        struct snd_rawmidi_runtime *runtime;
-       struct list_head *list;
 
        rmidi = entry->private_data;
        snd_iprintf(buffer, "%s\n\n", rmidi->name);
        mutex_lock(&rmidi->open_mutex);
        if (rmidi->info_flags & SNDRV_RAWMIDI_INFO_OUTPUT) {
-               list_for_each(list, &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams) {
-                       substream = list_entry(list, struct snd_rawmidi_substream, list);
+               list_for_each_entry(substream,
+                                   &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams,
+                                   list) {
                        snd_iprintf(buffer,
                                    "Output %d\n"
                                    "  Tx bytes     : %lu\n",
@@ -1339,8 +1332,9 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,
                }
        }
        if (rmidi->info_flags & SNDRV_RAWMIDI_INFO_INPUT) {
-               list_for_each(list, &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams) {
-                       substream = list_entry(list, struct snd_rawmidi_substream, list);
+               list_for_each_entry(substream,
+                                   &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams,
+                                   list) {
                        snd_iprintf(buffer,
                                    "Input %d\n"
                                    "  Rx bytes     : %lu\n",
@@ -1365,7 +1359,7 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,
  *  Register functions
  */
 
-static struct file_operations snd_rawmidi_f_ops =
+static const struct file_operations snd_rawmidi_f_ops =
 {
        .owner =        THIS_MODULE,
        .read =         snd_rawmidi_read,
@@ -1385,7 +1379,6 @@ static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
        struct snd_rawmidi_substream *substream;
        int idx;
 
-       INIT_LIST_HEAD(&stream->substreams);
        for (idx = 0; idx < count; idx++) {
                substream = kzalloc(sizeof(*substream), GFP_KERNEL);
                if (substream == NULL) {
@@ -1426,7 +1419,6 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
                .dev_free = snd_rawmidi_dev_free,
                .dev_register = snd_rawmidi_dev_register,
                .dev_disconnect = snd_rawmidi_dev_disconnect,
-               .dev_unregister = snd_rawmidi_dev_unregister
        };
 
        snd_assert(rrawmidi != NULL, return -EINVAL);
@@ -1441,6 +1433,9 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
        rmidi->device = device;
        mutex_init(&rmidi->open_mutex);
        init_waitqueue_head(&rmidi->open_wait);
+       INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams);
+       INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams);
+
        if (id != NULL)
                strlcpy(rmidi->id, id, sizeof(rmidi->id));
        if ((err = snd_rawmidi_alloc_substreams(rmidi,
@@ -1479,6 +1474,14 @@ static void snd_rawmidi_free_substreams(struct snd_rawmidi_str *stream)
 static int snd_rawmidi_free(struct snd_rawmidi *rmidi)
 {
        snd_assert(rmidi != NULL, return -ENXIO);       
+
+       snd_info_free_entry(rmidi->proc_entry);
+       rmidi->proc_entry = NULL;
+       mutex_lock(&register_mutex);
+       if (rmidi->ops && rmidi->ops->dev_unregister)
+               rmidi->ops->dev_unregister(rmidi);
+       mutex_unlock(&register_mutex);
+
        snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]);
        snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]);
        if (rmidi->private_free)
@@ -1587,21 +1590,6 @@ static int snd_rawmidi_dev_disconnect(struct snd_device *device)
 
        mutex_lock(&register_mutex);
        list_del_init(&rmidi->list);
-       mutex_unlock(&register_mutex);
-       return 0;
-}
-
-static int snd_rawmidi_dev_unregister(struct snd_device *device)
-{
-       struct snd_rawmidi *rmidi = device->device_data;
-
-       snd_assert(rmidi != NULL, return -ENXIO);
-       mutex_lock(&register_mutex);
-       list_del(&rmidi->list);
-       if (rmidi->proc_entry) {
-               snd_info_unregister(rmidi->proc_entry);
-               rmidi->proc_entry = NULL;
-       }
 #ifdef CONFIG_SND_OSSEMUL
        if (rmidi->ossreg) {
                if ((int)rmidi->device == midi_map[rmidi->card->number]) {
@@ -1615,17 +1603,9 @@ static int snd_rawmidi_dev_unregister(struct snd_device *device)
                rmidi->ossreg = 0;
        }
 #endif /* CONFIG_SND_OSSEMUL */
-       if (rmidi->ops && rmidi->ops->dev_unregister)
-               rmidi->ops->dev_unregister(rmidi);
        snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device);
        mutex_unlock(&register_mutex);
-#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
-       if (rmidi->seq_dev) {
-               snd_device_free(rmidi->card, rmidi->seq_dev);
-               rmidi->seq_dev = NULL;
-       }
-#endif
-       return snd_rawmidi_free(rmidi);
+       return 0;
 }
 
 /**
@@ -1639,13 +1619,10 @@ static int snd_rawmidi_dev_unregister(struct snd_device *device)
 void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
                         struct snd_rawmidi_ops *ops)
 {
-       struct list_head *list;
        struct snd_rawmidi_substream *substream;
        
-       list_for_each(list, &rmidi->streams[stream].substreams) {
-               substream = list_entry(list, struct snd_rawmidi_substream, list);
+       list_for_each_entry(substream, &rmidi->streams[stream].substreams, list)
                substream->ops = ops;
-       }
 }
 
 /*