From patchwork Tue Feb 16 17:10:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 8329631 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4BCE0C02AA for ; Tue, 16 Feb 2016 17:11:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 881732028D for ; Tue, 16 Feb 2016 17:11:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8CC1120272 for ; Tue, 16 Feb 2016 17:11:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aVj8v-0000NP-J4; Tue, 16 Feb 2016 17:10:29 +0000 Received: from mx2.suse.de ([195.135.220.15]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aVj8r-0007d4-Ug for linux-arm-kernel@lists.infradead.org; Tue, 16 Feb 2016 17:10:27 +0000 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 0DFABACBE; Tue, 16 Feb 2016 17:10:03 +0000 (UTC) Date: Tue, 16 Feb 2016 18:10:02 +0100 Message-ID: From: Takashi Iwai To: Arnd Bergmann Subject: Re: [PATCH] sound: hdmi: avoid dereferencing uninitialized 'jack' pointer In-Reply-To: <112888486.mQgaWiH0PI@wuerfel> References: <1455634059-1896914-1-git-send-email-arnd@arndb.de> <20160216163840.GA7544@sirena.org.uk> <112888486.mQgaWiH0PI@wuerfel> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/24.5 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160216_091026_459006_CD52CF58 X-CRM114-Status: GOOD ( 21.51 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Mark Brown , linux-arm-kernel@lists.infradead.org, Han Lu , Libin Yang , Thierry Reding , David Henningsson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, 16 Feb 2016 17:59:04 +0100, Arnd Bergmann wrote: > > On Tuesday 16 February 2016 16:38:40 Mark Brown wrote: > > On Tue, Feb 16, 2016 at 05:18:29PM +0100, Takashi Iwai wrote: > > > Arnd Bergmann wrote: > > > > > > Another option might would be to change snd_jack_new() to return > > > > an error if that SND_JACK is disabled, and then require all users > > > > to handle the error gracefully, i.e. not fail the probe() function > > > > but just not use the jack. > > > > > Yes, I thought of that, too. If select is no good option, it's a good > > > alternative, indeed. > > > > It's going to be a bunch of work to implement though. > > > > I've already sent a v2 to change the snd_jack_new() function, feel free > to ignore that. I also saw now that the same bug is present in hda_jack.c, > but I think the other drivers are fine. > > How about this approach below? That should also make it possible to > use the jack APIs without using a error return. I prefer setting NULL explicitly in snd_jack_new(), and let callers checking NULL. Then we can avoid ugly IS_ENABLE() while the compiler should be still capable to optimize out. OTOH, I think it'd be a waste of time to bikeshedding too much, so I don't care so much which to take :) Takashi Acked-by: Arnd Bergmann diff --git a/include/sound/jack.h b/include/sound/jack.h index 23bede121c78..a27c253a3207 100644 --- a/include/sound/jack.h +++ b/include/sound/jack.h @@ -99,6 +99,7 @@ void snd_jack_report(struct snd_jack *jack, int status); static inline int snd_jack_new(struct snd_card *card, const char *id, int type, struct snd_jack **jack, bool initial_kctl, bool phantom_jack) { + *jack = NULL; return 0; } diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c index a33234e04d4f..babd3a8864a1 100644 --- a/sound/pci/hda/hda_jack.c +++ b/sound/pci/hda/hda_jack.c @@ -403,10 +403,12 @@ int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid, jack->phantom_jack = !!phantom_jack; jack->type = type; - jack->jack->private_data = jack; - jack->jack->private_free = hda_free_jack_priv; - state = snd_hda_jack_detect(codec, nid); - snd_jack_report(jack->jack, state ? jack->type : 0); + if (jack->jack) { + jack->jack->private_data = jack; + jack->jack->private_free = hda_free_jack_priv; + state = snd_hda_jack_detect(codec, nid); + snd_jack_report(jack->jack, state ? jack->type : 0); + } return 0; } diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index 8ee78dbd4c60..34a7b3aaba11 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -2158,8 +2158,10 @@ static int add_acomp_jack_kctl(struct hda_codec *codec, if (err < 0) return err; per_pin->acomp_jack = jack; - jack->private_data = per_pin; - jack->private_free = free_acomp_jack_priv; + if (jack) { + jack->private_data = per_pin; + jack->private_free = free_acomp_jack_priv; + } return 0; }