[ALSA] sound: snd_register_device_for_dev fix
authorMariusz Kozlowski <m.kozlowski@tuxland.pl>
Tue, 9 Oct 2007 08:34:06 +0000 (10:34 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 16 Oct 2007 14:51:06 +0000 (16:51 +0200)
snd_register_device_for_dev() can oops when device_create() returns
ERR_PTR(err).
Scenario:
preg->dev = device_create(...); /* fails */
if (preg->dev) /* contains ERR_PTR(err) */
dev_set_drvdata(preg->dev, private_data);
and dev_set_drvdata() looks like this:
static inline void
dev_set_drvdata (struct device *dev, void *data)
{
dev->driver_data = data; <--- boom
}
This patch should prevent that.

Signed-off-by: Mariusz Kozlowski <m.kozlowski@tuxland.pl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
sound/core/sound.c

index 8dc7a3b32b98482bc12f1b60aa6cb25352d41bf3..f6ebce08b537a838ffb789b0782b3eed0b27c5d5 100644 (file)
@@ -266,6 +266,14 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
        snd_minors[minor] = preg;
        preg->dev = device_create(sound_class, device, MKDEV(major, minor),
                                  "%s", name);
+       if (IS_ERR(preg->dev)) {
+               snd_minors[minor] = NULL;
+               mutex_unlock(&sound_mutex);
+               minor = PTR_ERR(preg->dev);
+               kfree(preg);
+               return minor;
+       }
+
        if (preg->dev)
                dev_set_drvdata(preg->dev, private_data);