Commit 5d99a8b8 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

SOUND: fix race in device_create

There is a race from when a device is created with device_create() and
then the drvdata is set with a call to dev_set_drvdata() in which a
sysfs file could be open, yet the drvdata will be NULL, causing all
sorts of bad things to happen.

This patch fixes the problem by using the new function,
device_create_drvdata().

Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 43691da4
...@@ -259,8 +259,9 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev, ...@@ -259,8 +259,9 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
return minor; return minor;
} }
snd_minors[minor] = preg; snd_minors[minor] = preg;
preg->dev = device_create(sound_class, device, MKDEV(major, minor), preg->dev = device_create_drvdata(sound_class, device,
"%s", name); MKDEV(major, minor),
private_data, "%s", name);
if (IS_ERR(preg->dev)) { if (IS_ERR(preg->dev)) {
snd_minors[minor] = NULL; snd_minors[minor] = NULL;
mutex_unlock(&sound_mutex); mutex_unlock(&sound_mutex);
...@@ -269,9 +270,6 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev, ...@@ -269,9 +270,6 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
return minor; return minor;
} }
if (preg->dev)
dev_set_drvdata(preg->dev, private_data);
mutex_unlock(&sound_mutex); mutex_unlock(&sound_mutex);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment