Skip to content

Commit

Permalink
ALSA: hda - Fix widget sysfs tree corruption after refresh
Browse files Browse the repository at this point in the history
When snd_hdac_refresh_widget_sysfs() is called before the first
hda_widget_sysfs_init(), the next call overrides and eventually
fails.  This results in unexpected Oops, something like:
  BUG: unable to handle kernel NULL pointer dereference at 00000000000000c8
  IP: [<ffffffff8180e2a3>] hdmi_chmap_ctl_info+0x23/0x40

The fix is to add a check of the existing sysfs tree.  Also, for more
safety, this patch adds the checks of device_is_registered() in
snd-hdac_refresh_wdiget_sysfs(), too.

Fixes: fa4f18b ('ALSA: hda - Refresh widgets sysfs at probing Haswell+ HDMI codecs')
Bugizlla: https://bugzilla.kernel.org/show_bug.cgi?id=103431
Reported-by: Andreas Reis <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Aug 26, 2015
1 parent 654e275 commit a92d5ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sound/hda/hdac_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,18 +384,20 @@ int snd_hdac_refresh_widget_sysfs(struct hdac_device *codec)
{
int ret;

hda_widget_sysfs_exit(codec);
if (device_is_registered(&codec->dev))
hda_widget_sysfs_exit(codec);
ret = snd_hdac_refresh_widgets(codec);
if (ret) {
dev_err(&codec->dev, "failed to refresh widget: %d\n", ret);
return ret;
}
ret = hda_widget_sysfs_init(codec);
if (ret) {
dev_err(&codec->dev, "failed to init sysfs: %d\n", ret);
return ret;
if (device_is_registered(&codec->dev)) {
ret = hda_widget_sysfs_init(codec);
if (ret) {
dev_err(&codec->dev, "failed to init sysfs: %d\n", ret);
return ret;
}
}

return ret;
}
EXPORT_SYMBOL_GPL(snd_hdac_refresh_widget_sysfs);
Expand Down
3 changes: 3 additions & 0 deletions sound/hda/hdac_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ int hda_widget_sysfs_init(struct hdac_device *codec)
{
int err;

if (codec->widgets)
return 0; /* already created */

err = widget_tree_create(codec);
if (err < 0) {
widget_tree_free(codec);
Expand Down

0 comments on commit a92d5ee

Please sign in to comment.