lkml.org 
[lkml]   [2007]   [Sep]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] sound: snd_register_device_for_dev fix
Date
Now 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>

sound/core/sound.c | 8 ++++++++
1 file changed, 8 insertions(+)

--- linux-2.6.23-rc8-mm1-a/sound/core/sound.c 2007-09-26 12:07:01.000000000 +0200
+++ linux-2.6.23-rc8-mm1-b/sound/core/sound.c 2007-09-27 09:36:47.000000000 +0200
@@ -266,6 +266,14 @@ int snd_register_device_for_dev(int type
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);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2007-09-27 09:57    [W:0.032 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site