From patchwork Wed Aug 26 05:50:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 7074391 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E77059F374 for ; Wed, 26 Aug 2015 05:51:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B2AC5208DB for ; Wed, 26 Aug 2015 05:51:23 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id E1971208D7 for ; Wed, 26 Aug 2015 05:51:21 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 19E0F26533D; Wed, 26 Aug 2015 07:51:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id E690A26530B; Wed, 26 Aug 2015 07:51:06 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 98F56265310; Wed, 26 Aug 2015 07:51:05 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 864B3265307 for ; Wed, 26 Aug 2015 07:50:58 +0200 (CEST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3ABECAC4A for ; Wed, 26 Aug 2015 05:50:58 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Date: Wed, 26 Aug 2015 07:50:56 +0200 Message-Id: <1440568256-14336-1-git-send-email-tiwai@suse.de> X-Mailer: git-send-email 2.5.0 Subject: [alsa-devel] [PATCH] ALSA: hda - Fix widget sysfs tree corruption after refresh X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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: [] 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: fa4f18b4f402 ('ALSA: hda - Refresh widgets sysfs at probing Haswell+ HDMI codecs') Bugizlla: https://bugzilla.kernel.org/show_bug.cgi?id=103431 Reported-by: Andreas Reis Signed-off-by: Takashi Iwai --- sound/hda/hdac_device.c | 14 ++++++++------ sound/hda/hdac_sysfs.c | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c index aa6d6cec2380..db96042a497f 100644 --- a/sound/hda/hdac_device.c +++ b/sound/hda/hdac_device.c @@ -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); diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c index 089b35f6f108..c71142dea98a 100644 --- a/sound/hda/hdac_sysfs.c +++ b/sound/hda/hdac_sysfs.c @@ -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);