Skip to contentSkip to conversation

ALSA: hda: Avoid racy recreation of widget kobjects

PATCH New Takashi Iwai 1 participant 1 message Oct 19, 2017 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda: Avoid racy recreation of widget kobjects

The refresh of HD-audio widget sysfs kobjects via snd_hdac_refresh_widget_sysfs() is slightly racy.
The driver recreates the whole tree from scratch after deleting the whole. When CONFIG_DEBUG_KOBJECT_RELEASE option is used, kobject release doesn't happen immediately but delayed, while the re-creation of the same named kobject happens soon after invoking kobject_put(). This may end up with the conflicts of duplicated kobjects, as found in the bug report below.

In this patch, we take another approach to refresh the tree: instead of recreating the whole tree, just add the new nodes and delete the non-existing nodes. Since the refresh happens only once at initialization, no longer race would happen.

Along with the code change, merge snd_hdac_refresh_widget_sysfs() with the existing snd_hdac_refresh_widgets() with an additional bool flag for simplifying the code.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=197307

---
 include/sound/hdaudio.h   |  3 +--
 sound/hda/hdac_device.c   | 43 ++++++++++---------------------------------
 sound/hda/hdac_sysfs.c    | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 sound/hda/local.h         |  2 ++
 sound/pci/hda/hda_codec.c |  2 +-
 5 files changed, 61 insertions(+), 36 deletions(-)
include/sound/hdaudio.h +1 -2
index 96546b30e900..6f1118545bb8 100644
@@ -111,8 +111,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);
-int snd_hdac_refresh_widget_sysfs(struct hdac_device *codec);
+int snd_hdac_refresh_widgets(struct hdac_device *codec, bool sysfs);
 
 unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
 			       unsigned int verb, unsigned int parm);
sound/hda/hdac_device.c +10 -33

70 lines not on this page · raw message

sound/hda/hdac_sysfs.c +47 -0

50 lines not on this page · raw message

sound/hda/local.h +2 -0
index 0d5bb159d538..c586ea62d49e 100644
@@ -28,6 +28,8 @@ static inline unsigned int get_wcaps_channels(u32 wcaps)
 
 extern const struct attribute_group *hdac_dev_attr_groups[];
 int hda_widget_sysfs_init(struct hdac_device *codec);
+int hda_widget_sysfs_reinit(struct hdac_device *codec, hda_nid_t start_nid,
+			    int num_nodes);
 void hda_widget_sysfs_exit(struct hdac_device *codec);
 
 #endif /* __HDAC_LOCAL_H */
sound/pci/hda/hda_codec.c +1 -1
index 3db26c451837..bb086665c3e0 100644
@@ -977,7 +977,7 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec)
 	hda_nid_t fg;
 	int err;
 
-	err = snd_hdac_refresh_widget_sysfs(&codec->core);
+	err = snd_hdac_refresh_widgets(&codec->core, true);
 	if (err < 0)
 		return err;
 
Signature · 1 line
2.14.2