aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sg.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2008-05-16 20:55:12 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-05-20 16:31:56 -0400
commit24b42566c3fcbb5a9011d1446783d0f5844ccd45 (patch)
tree0e1de28631d02446580adf5fbb98feb981b20b5a /drivers/scsi/sg.c
parentc013d040b70bc2bff5465917ebb255a70b650396 (diff)
SCSI: 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(). It fixes the problem in all of the scsi drivers that need it. Cc: Kay Sievers <kay.sievers@vrfy.org> Cc: Doug Gilbert <dgilbert@interlog.com> Cc: James E.J. Bottomley <James.Bottomley@HansenPartnership.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/scsi/sg.c')
-rw-r--r--drivers/scsi/sg.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index c9d7f721b9e2..ea0edd1b2e76 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1441,17 +1441,18 @@ sg_add(struct device *cl_dev, struct class_interface *cl_intf)
1441 if (sg_sysfs_valid) { 1441 if (sg_sysfs_valid) {
1442 struct device *sg_class_member; 1442 struct device *sg_class_member;
1443 1443
1444 sg_class_member = device_create(sg_sysfs_class, cl_dev->parent, 1444 sg_class_member = device_create_drvdata(sg_sysfs_class,
1445 MKDEV(SCSI_GENERIC_MAJOR, 1445 cl_dev->parent,
1446 sdp->index), 1446 MKDEV(SCSI_GENERIC_MAJOR,
1447 "%s", disk->disk_name); 1447 sdp->index),
1448 sdp,
1449 "%s", disk->disk_name);
1448 if (IS_ERR(sg_class_member)) { 1450 if (IS_ERR(sg_class_member)) {
1449 printk(KERN_ERR "sg_add: " 1451 printk(KERN_ERR "sg_add: "
1450 "device_create failed\n"); 1452 "device_create failed\n");
1451 error = PTR_ERR(sg_class_member); 1453 error = PTR_ERR(sg_class_member);
1452 goto cdev_add_err; 1454 goto cdev_add_err;
1453 } 1455 }
1454 dev_set_drvdata(sg_class_member, sdp);
1455 error = sysfs_create_link(&scsidp->sdev_gendev.kobj, 1456 error = sysfs_create_link(&scsidp->sdev_gendev.kobj,
1456 &sg_class_member->kobj, "generic"); 1457 &sg_class_member->kobj, "generic");
1457 if (error) 1458 if (error)