[PATCH 09/13] SOUND: fix race in device_create

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>
Cc: Greg Kroah-Hartman <gregkh@...>, Kay Sievers <kay.sievers@...>, Jaroslav Kysela <perex@...>
Date: Tuesday, May 20, 2008 - 6:34 pm

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: Greg Kroah-Hartman <gregkh@suse.de>
---
 sound/core/sound.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/sound/core/sound.c b/sound/core/sound.c
index 812f91b..6c8ab48 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -259,8 +259,9 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
 		return minor;
 	}
 	snd_minors[minor] = preg;
-	preg->dev = device_create(sound_class, device, MKDEV(major, minor),
-				  "%s", name);
+	preg->dev = device_create_drvdata(sound_class, device,
+					  MKDEV(major, minor),
+					  private_data, "%s", name);
 	if (IS_ERR(preg->dev)) {
 		snd_minors[minor] = NULL;
 		mutex_unlock(&sound_mutex);
@@ -269,9 +270,6 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
 		return minor;
 	}
 
-	if (preg->dev)
-		dev_set_drvdata(preg->dev, private_data);
-
 	mutex_unlock(&sound_mutex);
 	return 0;
 }
-- 
1.5.5.1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GIT PATCH] driver core fixes against 2.6.26-rc3, Greg KH, (Tue May 20, 6:32 pm)
[PATCH 13/13] SCSI: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:35 pm)
[PATCH 12/13] USB: Core: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 11/13] USB: Phidget: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 10/13] s390: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 09/13] SOUND: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 08/13] UIO: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 07/13] Power Supply: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 06/13] LEDS: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 05/13] IB: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 03/13] fbdev: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 04/13] ide: fix race in device_create, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 02/13] mm: bdi: fix race in bdi_class device creation, Greg Kroah-Hartman, (Tue May 20, 6:34 pm)
[PATCH 01/13] Driver core: add device_create_vargs and devic..., Greg Kroah-Hartman, (Tue May 20, 6:34 pm)