ALSA: hda: hda_component: Initialize shared data during bind callback
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Wed, 8 May 2024 10:03:47 +0000 (11:03 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 8 May 2024 16:18:23 +0000 (18:18 +0200)
Move the initialization of the shared struct hda_component array into
hda_component_manager_bind().

The purpose of the manager bind() callback is to allow it to perform
initialization before binding in the component drivers. This is the
correct place to initialize the shared data.

The original implementation initialized the shared data in
hda_component_manager_init(). This is only done once during probe()
of the manager driver. So if the component binding was unbound and
then rebound, the shared data would not be re-initialized.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Fixes: fd895a74dc1d ("ALSA: hda: realtek: Move hda_component implementation to module")
Link: https://lore.kernel.org/r/20240508100347.47283-1-rf@opensource.cirrus.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/hda_component.c
sound/pci/hda/hda_component.h
sound/pci/hda/patch_realtek.c

index cd299d7d84bafc133b7ef340b40d2e5b3bf1da83..d02589014a3fa6305a80e3420c67b1a0fc53b193 100644 (file)
@@ -123,6 +123,21 @@ static int hda_comp_match_dev_name(struct device *dev, void *data)
        return !strcmp(d + n, tmp);
 }
 
+int hda_component_manager_bind(struct hda_codec *cdc,
+                              struct hda_component *comps, int count)
+{
+       int i;
+
+       /* Init shared data */
+       for (i = 0; i < count; ++i) {
+               memset(&comps[i], 0, sizeof(comps[i]));
+               comps[i].codec = cdc;
+       }
+
+       return component_bind_all(hda_codec_dev(cdc), comps);
+}
+EXPORT_SYMBOL_NS_GPL(hda_component_manager_bind, SND_HDA_SCODEC_COMPONENT);
+
 int hda_component_manager_init(struct hda_codec *cdc,
                               struct hda_component *comps, int count,
                               const char *bus, const char *hid,
@@ -143,7 +158,6 @@ int hda_component_manager_init(struct hda_codec *cdc,
                sm->hid = hid;
                sm->match_str = match_str;
                sm->index = i;
-               comps[i].codec = cdc;
                component_match_add(dev, &match, hda_comp_match_dev_name, sm);
        }
 
index c80a66691b5d86c5b27f99abfe127a2f1fafaf7f..c70b3de68ab2063c2807af0771f34646b136a107 100644 (file)
@@ -75,11 +75,8 @@ int hda_component_manager_init(struct hda_codec *cdc,
 void hda_component_manager_free(struct hda_codec *cdc,
                                const struct component_master_ops *ops);
 
-static inline int hda_component_manager_bind(struct hda_codec *cdc,
-                                            struct hda_component *comps)
-{
-       return component_bind_all(hda_codec_dev(cdc), comps);
-}
+int hda_component_manager_bind(struct hda_codec *cdc,
+                              struct hda_component *comps, int count);
 
 static inline void hda_component_manager_unbind(struct hda_codec *cdc,
                                               struct hda_component *comps)
index 8c157158f1cb3e0141800ec80bf729a359d1e50b..8c39bbdc6c5e28e3102074c95dfee017efdb9bee 100644 (file)
@@ -6785,7 +6785,7 @@ static int comp_bind(struct device *dev)
        struct alc_spec *spec = cdc->spec;
        int ret;
 
-       ret = hda_component_manager_bind(cdc, spec->comps);
+       ret = hda_component_manager_bind(cdc, spec->comps, ARRAY_SIZE(spec->comps));
        if (ret)
                return ret;