]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - sound/hda/hdac_device.c
Merge tag 'sound-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
[linux.git] / sound / hda / hdac_device.c
index 6907dbefd08c17ce72849ab96b307140ecbebbc2..3842f9d34b7cfc2f7db7ee865a6922876918c176 100644 (file)
@@ -400,27 +400,33 @@ static void setup_fg_nodes(struct hdac_device *codec)
 int snd_hdac_refresh_widgets(struct hdac_device *codec, bool sysfs)
 {
        hda_nid_t start_nid;
-       int nums, err;
+       int nums, err = 0;
 
+       /*
+        * Serialize against multiple threads trying to update the sysfs
+        * widgets array.
+        */
+       mutex_lock(&codec->widget_lock);
        nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid);
        if (!start_nid || nums <= 0 || nums >= 0xff) {
                dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n",
                        codec->afg);
-               return -EINVAL;
+               err = -EINVAL;
+               goto unlock;
        }
 
        if (sysfs) {
-               mutex_lock(&codec->widget_lock);
                err = hda_widget_sysfs_reinit(codec, start_nid, nums);
-               mutex_unlock(&codec->widget_lock);
                if (err < 0)
-                       return err;
+                       goto unlock;
        }
 
        codec->num_nodes = nums;
        codec->start_nid = start_nid;
        codec->end_nid = start_nid + nums;
-       return 0;
+unlock:
+       mutex_unlock(&codec->widget_lock);
+       return err;
 }
 EXPORT_SYMBOL_GPL(snd_hdac_refresh_widgets);