path: root/drivers/s390/block/dasd_devmap.c
diff options
authorStefan Weinhuber <wein@de.ibm.com>2011-04-20 10:15:30 +0200
committerMartin Schwidefsky <sky@mschwide.boeblingen.de.ibm.com>2011-04-20 10:15:43 +0200
commit65f8da475995f667af5298c644707dbd9d646ca6 (patch)
treebca8597443060e79f09a8843903bbc55b2dece52 /drivers/s390/block/dasd_devmap.c
parent2f666bcf757cb72549f360ef6da02f03620a48b6 (diff)
[S390] dasd: fix race between open and offline
The dasd_open function uses the private_data pointer of the gendisk to find the dasd_block structure that matches the gendisk. When a DASD device is set offline, we set the private_data pointer of the gendisk to NULL and later remove the dasd_block structure, but there is still a small race window, in which dasd_open could first read a pointer from the private_data field and then try to use it, after the structure has already been freed. To close this race window, we will store a pointer to the dasd_devmap structure of the base device in the private_data field. The devmap entries are not deleted, and we already have proper locking and reference counting in place, so that we can safely get from a devmap pointer to the dasd_device and dasd_block structures of the device. Signed-off-by: Stefan Weinhuber <wein@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'drivers/s390/block/dasd_devmap.c')
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index 42e1bf35f68..d71511c7850 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -674,6 +674,36 @@ dasd_device_from_cdev(struct ccw_device *cdev)
return device;
+void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
+ struct dasd_devmap *devmap;
+ devmap = dasd_find_busid(dev_name(&device->cdev->dev));
+ if (IS_ERR(devmap))
+ return;
+ spin_lock(&dasd_devmap_lock);
+ gdp->private_data = devmap;
+ spin_unlock(&dasd_devmap_lock);
+struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
+ struct dasd_device *device;
+ struct dasd_devmap *devmap;
+ if (!gdp->private_data)
+ return NULL;
+ device = NULL;
+ spin_lock(&dasd_devmap_lock);
+ devmap = gdp->private_data;
+ if (devmap && devmap->device) {
+ device = devmap->device;
+ dasd_get_device(device);
+ }
+ spin_unlock(&dasd_devmap_lock);
+ return device;
* SECTION: files in sysfs