From 2469049e728ee0542d6617f81311a18a14e73826 Mon Sep 17 00:00:00 2001 From: Mariusz Kozlowski Date: Tue, 9 Oct 2007 10:34:06 +0200 Subject: [PATCH] [ALSA] sound: snd_register_device_for_dev fix 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 Signed-off-by: Andrew Morton Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela --- sound/core/sound.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sound/core/sound.c b/sound/core/sound.c index 8dc7a3b32b98..f6ebce08b537 100644 --- a/sound/core/sound.c +++ b/sound/core/sound.c @@ -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); -- 2.20.1