IB: 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>
Reviewed-by: Roland Dreier <rolandd@cisco.com>
Cc: Sean Hefty <sean.hefty@intel.com>
Cc: Hal Rosenstock <hal.rosenstock@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Greg Kroah-Hartman
2008-05-16 17:55:12 -07:00
parent 716ad8750a
commit 6c06aec248
2 changed files with 12 additions and 13 deletions

View File

@@ -755,14 +755,15 @@ static void ib_uverbs_add_one(struct ib_device *device)
if (cdev_add(uverbs_dev->cdev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1))
goto err_cdev;
uverbs_dev->dev = device_create(uverbs_class, device->dma_device,
uverbs_dev->cdev->dev,
"uverbs%d", uverbs_dev->devnum);
uverbs_dev->dev = device_create_drvdata(uverbs_class,
device->dma_device,
uverbs_dev->cdev->dev,
uverbs_dev,
"uverbs%d",
uverbs_dev->devnum);
if (IS_ERR(uverbs_dev->dev))
goto err_cdev;
dev_set_drvdata(uverbs_dev->dev, uverbs_dev);
if (device_create_file(uverbs_dev->dev, &dev_attr_ibdev))
goto err_class;
if (device_create_file(uverbs_dev->dev, &dev_attr_abi_version))