public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Arnd Bergmann <arnd@arndb.de>
Cc: linux-arm-kernel@lists.infradead.org,
	Mark Brown <broonie@kernel.org>,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	Jaroslav Kysela <perex@perex.cz>,
	David Henningsson <david.henningsson@canonical.com>,
	Han Lu <han.lu@intel.com>,
	Libin Yang <libin.yang@linux.intel.com>,
	Thierry Reding <treding@nvidia.com>
Subject: Re: [PATCH] sound: hdmi: avoid dereferencing uninitialized 'jack' pointer
Date: Tue, 16 Feb 2016 18:10:02 +0100	[thread overview]
Message-ID: <s5hr3gc60ph.wl-tiwai@suse.de> (raw)
In-Reply-To: <112888486.mQgaWiH0PI@wuerfel>

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

---
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;
 }
 

  parent reply	other threads:[~2016-02-16 17:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-16 14:47 [PATCH] sound: hdmi: avoid dereferencing uninitialized 'jack' pointer Arnd Bergmann
2016-02-16 15:49 ` Takashi Iwai
2016-02-16 16:09   ` Arnd Bergmann
2016-02-16 16:18     ` Takashi Iwai
2016-02-16 16:38       ` Mark Brown
2016-02-16 16:43         ` Takashi Iwai
2016-02-16 16:59         ` Arnd Bergmann
2016-02-16 17:09           ` Arnd Bergmann
2016-02-16 17:10           ` Takashi Iwai [this message]
2016-02-16 17:26             ` Arnd Bergmann
2016-02-16 22:08               ` Arnd Bergmann
2016-02-17  9:03                 ` Takashi Iwai
2016-02-17  9:24                   ` [PATCH] ALSA: jack: Allow building the jack layer without input kbuild test robot
2016-02-17  9:35                   ` [PATCH] sound: hdmi: avoid dereferencing uninitialized 'jack' pointer Takashi Iwai
2016-02-17  9:40                     ` Arnd Bergmann
2016-02-24 16:18                     ` Arnd Bergmann
2016-02-24 16:25                       ` Takashi Iwai
2016-02-24 16:39                         ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hr3gc60ph.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=david.henningsson@canonical.com \
    --cc=han.lu@intel.com \
    --cc=libin.yang@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=treding@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox