aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
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:55 -0400
commit6c06aec2487f7568cf57471a20f422568f25d551 (patch)
tree91ee5f4128333d7a10d634a209650381bc90ec06 /drivers
parent716ad8750a3ffe6b458d52da2d1c01cbf3e2f60d (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/infiniband/core/user_mad.c14
-rw-r--r--drivers/infiniband/core/uverbs_main.c11
2 files changed, 12 insertions, 13 deletions
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index 3aa2db54eae4..840ede9ae965 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -1005,8 +1005,9 @@ static int ib_umad_init_port(struct ib_device *device, int port_num,
1005 if (cdev_add(port->cdev, base_dev + port->dev_num, 1)) 1005 if (cdev_add(port->cdev, base_dev + port->dev_num, 1))
1006 goto err_cdev; 1006 goto err_cdev;
1007 1007
1008 port->dev = device_create(umad_class, device->dma_device, 1008 port->dev = device_create_drvdata(umad_class, device->dma_device,
1009 port->cdev->dev, "umad%d", port->dev_num); 1009 port->cdev->dev, port,
1010 "umad%d", port->dev_num);
1010 if (IS_ERR(port->dev)) 1011 if (IS_ERR(port->dev))
1011 goto err_cdev; 1012 goto err_cdev;
1012 1013
@@ -1024,15 +1025,12 @@ static int ib_umad_init_port(struct ib_device *device, int port_num,
1024 if (cdev_add(port->sm_cdev, base_dev + port->dev_num + IB_UMAD_MAX_PORTS, 1)) 1025 if (cdev_add(port->sm_cdev, base_dev + port->dev_num + IB_UMAD_MAX_PORTS, 1))
1025 goto err_sm_cdev; 1026 goto err_sm_cdev;
1026 1027
1027 port->sm_dev = device_create(umad_class, device->dma_device, 1028 port->sm_dev = device_create_drvdata(umad_class, device->dma_device,
1028 port->sm_cdev->dev, 1029 port->sm_cdev->dev, port,
1029 "issm%d", port->dev_num); 1030 "issm%d", port->dev_num);
1030 if (IS_ERR(port->sm_dev)) 1031 if (IS_ERR(port->sm_dev))
1031 goto err_sm_cdev; 1032 goto err_sm_cdev;
1032 1033
1033 dev_set_drvdata(port->dev, port);
1034 dev_set_drvdata(port->sm_dev, port);
1035
1036 if (device_create_file(port->sm_dev, &dev_attr_ibdev)) 1034 if (device_create_file(port->sm_dev, &dev_attr_ibdev))
1037 goto err_sm_dev; 1035 goto err_sm_dev;
1038 if (device_create_file(port->sm_dev, &dev_attr_port)) 1036 if (device_create_file(port->sm_dev, &dev_attr_port))
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index cc1afa28c181..f806da184b51 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -755,14 +755,15 @@ static void ib_uverbs_add_one(struct ib_device *device)
755 if (cdev_add(uverbs_dev->cdev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1)) 755 if (cdev_add(uverbs_dev->cdev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1))
756 goto err_cdev; 756 goto err_cdev;
757 757
758 uverbs_dev->dev = device_create(uverbs_class, device->dma_device, 758 uverbs_dev->dev = device_create_drvdata(uverbs_class,
759 uverbs_dev->cdev->dev, 759 device->dma_device,
760 "uverbs%d", uverbs_dev->devnum); 760 uverbs_dev->cdev->dev,
761 uverbs_dev,
762 "uverbs%d",
763 uverbs_dev->devnum);
761 if (IS_ERR(uverbs_dev->dev)) 764 if (IS_ERR(uverbs_dev->dev))
762 goto err_cdev; 765 goto err_cdev;
763 766
764 dev_set_drvdata(uverbs_dev->dev, uverbs_dev);
765
766 if (device_create_file(uverbs_dev->dev, &dev_attr_ibdev)) 767 if (device_create_file(uverbs_dev->dev, &dev_attr_ibdev))
767 goto err_class; 768 goto err_class;
768 if (device_create_file(uverbs_dev->dev, &dev_attr_abi_version)) 769 if (device_create_file(uverbs_dev->dev, &dev_attr_abi_version))