ALSA: hda: Simplify snd_hdac_refresh_widgets()
authorTakashi Iwai <tiwai@suse.de>
Wed, 3 Jul 2019 12:35:12 +0000 (14:35 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 5 Jul 2019 10:01:06 +0000 (12:01 +0200)
Along with the recent fix for the races of snd_hdac_refresh_widgets()
it turned out that the instantiation of widgets sysfs at
snd_hdac_sysfs_reinit() could cause a race.  The race itself was
already covered later by extending the mutex protection range, the
commit 98482377dc72 ("ALSA: hda: Fix widget_mutex incomplete
protection"), but this also indicated that the call of *_reinit() is
basically superfluous, as the widgets shall be created sooner or later
from snd_hdac_device_register().

This patch removes the redundant call of snd_hdac_sysfs_reinit() at
first.  By this removal, the sysfs argument itself in
snd_hdac_refresh_widgets() becomes superfluous, too, because the only
case sysfs=false is always with codec->widgets=NULL.  So, we drop this
redundant argument as well.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/hdaudio.h
sound/hda/hdac_device.c
sound/hda/hdac_sysfs.c
sound/pci/hda/hda_codec.c
sound/soc/codecs/hdac_hdmi.c

index e8346784cf3f8d1afdf23d3c2e0f7e99ca909538..f475293d06680494092262b7507a070a1caa2fdc 100644 (file)
@@ -120,7 +120,7 @@ void snd_hdac_device_unregister(struct hdac_device *codec);
 int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name);
 int snd_hdac_codec_modalias(struct hdac_device *hdac, char *buf, size_t size);
 
-int snd_hdac_refresh_widgets(struct hdac_device *codec, bool sysfs);
+int snd_hdac_refresh_widgets(struct hdac_device *codec);
 
 unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
                               unsigned int verb, unsigned int parm);
index 11050bfd8068d26d3bec198f9d63160779cc2696..a265c1d688766882a046dda5622ace56f05e02f5 100644 (file)
@@ -89,7 +89,7 @@ int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus,
 
        fg = codec->afg ? codec->afg : codec->mfg;
 
-       err = snd_hdac_refresh_widgets(codec, false);
+       err = snd_hdac_refresh_widgets(codec);
        if (err < 0)
                goto error;
 
@@ -394,9 +394,8 @@ static void setup_fg_nodes(struct hdac_device *codec)
 /**
  * snd_hdac_refresh_widgets - Reset the widget start/end nodes
  * @codec: the codec object
- * @sysfs: re-initialize sysfs tree, too
  */
-int snd_hdac_refresh_widgets(struct hdac_device *codec, bool sysfs)
+int snd_hdac_refresh_widgets(struct hdac_device *codec)
 {
        hda_nid_t start_nid;
        int nums, err = 0;
@@ -414,11 +413,9 @@ int snd_hdac_refresh_widgets(struct hdac_device *codec, bool sysfs)
                goto unlock;
        }
 
-       if (sysfs) {
-               err = hda_widget_sysfs_reinit(codec, start_nid, nums);
-               if (err < 0)
-                       goto unlock;
-       }
+       err = hda_widget_sysfs_reinit(codec, start_nid, nums);
+       if (err < 0)
+               goto unlock;
 
        codec->num_nodes = nums;
        codec->start_nid = start_nid;
index 909d5ef1179c92d3d33f5bb60aa5a5378e30db0b..e56e8332590310f8de65efd3701553544d0e1b0b 100644 (file)
@@ -428,7 +428,7 @@ int hda_widget_sysfs_reinit(struct hdac_device *codec,
        int i;
 
        if (!codec->widgets)
-               return hda_widget_sysfs_init(codec);
+               return 0;
 
        tree = kmemdup(codec->widgets, sizeof(*tree), GFP_KERNEL);
        if (!tree)
index fcdf2cd3783b5c19d1c4ce6c426bc794c6bc0b28..d1a0e0de80ac1d622098463464ff2daad854fb50 100644 (file)
@@ -1016,7 +1016,7 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec)
        hda_nid_t fg;
        int err;
 
-       err = snd_hdac_refresh_widgets(&codec->core, true);
+       err = snd_hdac_refresh_widgets(&codec->core);
        if (err < 0)
                return err;
 
index 660e0587f3999394296c37f8975c7f27b078d7ed..6302ad5b712807dffe305402956ebfaa521e02ad 100644 (file)
@@ -2043,7 +2043,7 @@ static int hdac_hdmi_dev_probe(struct hdac_device *hdev)
                        "Failed in parse and map nid with err: %d\n", ret);
                return ret;
        }
-       snd_hdac_refresh_widgets(hdev, true);
+       snd_hdac_refresh_widgets(hdev);
 
        /* ASoC specific initialization */
        ret = devm_snd_soc_register_component(&hdev->dev, &hdmi_hda_codec,