ALSA: usb-audio: Pass direct struct pointer instead of list_head
authorTakashi Iwai <tiwai@suse.de>
Fri, 31 Oct 2014 10:24:32 +0000 (11:24 +0100)
committerTakashi Iwai <tiwai@suse.de>
Tue, 4 Nov 2014 14:09:10 +0000 (15:09 +0100)
Some functions in mixer.c and endpoint.c receive list_head instead of
the object itself.  This is not obvious and rather error-prone.  Let's
pass the proper object directly instead.

The functions in midi.c still receive list_head and this can't be
changed since the object definition isn't exposed to the outside of
midi.c, so left as is.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/card.c
sound/usb/endpoint.c
sound/usb/endpoint.h
sound/usb/mixer.c
sound/usb/mixer.h

index be16bdc53c2a90dc21cbf747f58646394e2ea0f6..fa6c0972aa23d9767d3e93a3e482f13d5324d6c9 100644 (file)
@@ -114,13 +114,11 @@ static struct usb_driver usb_audio_driver;
  * disconnect streams
  * called from usb_audio_disconnect()
  */
-static void snd_usb_stream_disconnect(struct list_head *head)
+static void snd_usb_stream_disconnect(struct snd_usb_stream *as)
 {
        int idx;
-       struct snd_usb_stream *as;
        struct snd_usb_substream *subs;
 
-       as = list_entry(head, struct snd_usb_stream, list);
        for (idx = 0; idx < 2; idx++) {
                subs = &as->substream[idx];
                if (!subs->num_formats)
@@ -307,10 +305,10 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
 
 static int snd_usb_audio_free(struct snd_usb_audio *chip)
 {
-       struct list_head *p, *n;
+       struct snd_usb_endpoint *ep, *n;
 
-       list_for_each_safe(p, n, &chip->ep_list)
-               snd_usb_endpoint_free(p);
+       list_for_each_entry_safe(ep, n, &chip->ep_list, list)
+               snd_usb_endpoint_free(ep);
 
        mutex_destroy(&chip->mutex);
        kfree(chip);
@@ -609,12 +607,14 @@ static void usb_audio_disconnect(struct usb_interface *intf)
        mutex_lock(&register_mutex);
        chip->num_interfaces--;
        if (chip->num_interfaces <= 0) {
+               struct snd_usb_stream *as;
                struct snd_usb_endpoint *ep;
+               struct usb_mixer_interface *mixer;
 
                snd_card_disconnect(card);
                /* release the pcm resources */
-               list_for_each(p, &chip->pcm_list) {
-                       snd_usb_stream_disconnect(p);
+               list_for_each_entry(as, &chip->pcm_list, list) {
+                       snd_usb_stream_disconnect(as);
                }
                /* release the endpoint resources */
                list_for_each_entry(ep, &chip->ep_list, list) {
@@ -625,8 +625,8 @@ static void usb_audio_disconnect(struct usb_interface *intf)
                        snd_usbmidi_disconnect(p);
                }
                /* release mixer resources */
-               list_for_each(p, &chip->mixer_list) {
-                       snd_usb_mixer_disconnect(p);
+               list_for_each_entry(mixer, &chip->mixer_list, list) {
+                       snd_usb_mixer_disconnect(mixer);
                }
                usb_chip[chip->index] = NULL;
                mutex_unlock(&register_mutex);
index 114e3e7ff511d49897d292b541c634872614c656..167d0c1643e1ac5b211365db6c5a80835dcb925b 100644 (file)
@@ -1002,15 +1002,12 @@ void snd_usb_endpoint_release(struct snd_usb_endpoint *ep)
 /**
  * snd_usb_endpoint_free: Free the resources of an snd_usb_endpoint
  *
- * @ep: the list header of the endpoint to free
+ * @ep: the endpoint to free
  *
  * This free all resources of the given ep.
  */
-void snd_usb_endpoint_free(struct list_head *head)
+void snd_usb_endpoint_free(struct snd_usb_endpoint *ep)
 {
-       struct snd_usb_endpoint *ep;
-
-       ep = list_entry(head, struct snd_usb_endpoint, list);
        kfree(ep);
 }
 
index e61ee5c356a3d3cbbc3d9ad6e1c6fa6f9d0d10d4..6428392d8f6244688e65d8be3d04bc9c30c68ce5 100644 (file)
@@ -24,7 +24,7 @@ void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep);
 int  snd_usb_endpoint_activate(struct snd_usb_endpoint *ep);
 void snd_usb_endpoint_deactivate(struct snd_usb_endpoint *ep);
 void snd_usb_endpoint_release(struct snd_usb_endpoint *ep);
-void snd_usb_endpoint_free(struct list_head *head);
+void snd_usb_endpoint_free(struct snd_usb_endpoint *ep);
 
 int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep);
 int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep);
index 63a8adb1705ea06a0a038ea5bf6601f98341deec..e4aaa21baed2c4f09d3b3aa9ba2d8999c9c5e5a3 100644 (file)
@@ -2483,11 +2483,8 @@ _error:
        return err;
 }
 
-void snd_usb_mixer_disconnect(struct list_head *p)
+void snd_usb_mixer_disconnect(struct usb_mixer_interface *mixer)
 {
-       struct usb_mixer_interface *mixer;
-
-       mixer = list_entry(p, struct usb_mixer_interface, list);
        usb_kill_urb(mixer->urb);
        usb_kill_urb(mixer->rc_urb);
 }
index 73b1f649447bdb8de4fdc18e9e0ce89407f10d6c..2c7b9c9c2aa642eea27f6d533c348e0043986b62 100644 (file)
@@ -57,7 +57,7 @@ struct usb_mixer_elem_info {
 
 int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
                         int ignore_error);
-void snd_usb_mixer_disconnect(struct list_head *p);
+void snd_usb_mixer_disconnect(struct usb_mixer_interface *mixer);
 
 void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid);