Merge branch 'topic/hda-refresh-cleanup' into for-next
authorTakashi Iwai <tiwai@suse.de>
Sun, 7 Jul 2019 09:29:03 +0000 (11:29 +0200)
committerTakashi Iwai <tiwai@suse.de>
Sun, 7 Jul 2019 09:29:30 +0000 (11:29 +0200)
Merge a cleanup for HD-audio widget refresh code

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
sound/usb/line6/pcm.c

index f49af557bdb0e8df308085901d12ffbb48171c95..612a17e375d026b0215572f6d9dec83e04ad0c37 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 4769f4c03e148a567288a61a92d833c8e983bef9..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,32 +394,35 @@ 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;
+       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;
-       }
+       err = hda_widget_sysfs_reinit(codec, start_nid, nums);
+       if (err < 0)
+               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);
 
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 ccb53f1c1e1a3553f9ab96fa2bf8a12d80362363..7d8834907f1fd6775d4303a1a850b0967133b5e2 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,
index 72c6f8e82a7e9cb06e9c4489064d05dc39891448..78c2d6cab3b52f7341e7f02ee1e7e0d502f8679b 100644 (file)
@@ -560,6 +560,11 @@ int line6_init_pcm(struct usb_line6 *line6,
        line6pcm->max_packet_size_out =
                usb_maxpacket(line6->usbdev,
                        usb_sndisocpipe(line6->usbdev, ep_write), 1);
+       if (!line6pcm->max_packet_size_in || !line6pcm->max_packet_size_out) {
+               dev_err(line6pcm->line6->ifcdev,
+                       "cannot get proper max packet size\n");
+               return -EINVAL;
+       }
 
        spin_lock_init(&line6pcm->out.lock);
        spin_lock_init(&line6pcm->in.lock);