|
@@ -3064,6 +3064,23 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
|
|
put_device(&sdkp->dev);
|
|
put_device(&sdkp->dev);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+struct sd_devt {
|
|
|
|
+ int idx;
|
|
|
|
+ struct disk_devt disk_devt;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+void sd_devt_release(struct disk_devt *disk_devt)
|
|
|
|
+{
|
|
|
|
+ struct sd_devt *sd_devt = container_of(disk_devt, struct sd_devt,
|
|
|
|
+ disk_devt);
|
|
|
|
+
|
|
|
|
+ spin_lock(&sd_index_lock);
|
|
|
|
+ ida_remove(&sd_index_ida, sd_devt->idx);
|
|
|
|
+ spin_unlock(&sd_index_lock);
|
|
|
|
+
|
|
|
|
+ kfree(sd_devt);
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* sd_probe - called during driver initialization and whenever a
|
|
* sd_probe - called during driver initialization and whenever a
|
|
* new scsi device is attached to the system. It is called once
|
|
* new scsi device is attached to the system. It is called once
|
|
@@ -3085,6 +3102,7 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
|
|
static int sd_probe(struct device *dev)
|
|
static int sd_probe(struct device *dev)
|
|
{
|
|
{
|
|
struct scsi_device *sdp = to_scsi_device(dev);
|
|
struct scsi_device *sdp = to_scsi_device(dev);
|
|
|
|
+ struct sd_devt *sd_devt;
|
|
struct scsi_disk *sdkp;
|
|
struct scsi_disk *sdkp;
|
|
struct gendisk *gd;
|
|
struct gendisk *gd;
|
|
int index;
|
|
int index;
|
|
@@ -3110,9 +3128,13 @@ static int sd_probe(struct device *dev)
|
|
if (!sdkp)
|
|
if (!sdkp)
|
|
goto out;
|
|
goto out;
|
|
|
|
|
|
|
|
+ sd_devt = kzalloc(sizeof(*sd_devt), GFP_KERNEL);
|
|
|
|
+ if (!sd_devt)
|
|
|
|
+ goto out_free;
|
|
|
|
+
|
|
gd = alloc_disk(SD_MINORS);
|
|
gd = alloc_disk(SD_MINORS);
|
|
if (!gd)
|
|
if (!gd)
|
|
- goto out_free;
|
|
|
|
|
|
+ goto out_free_devt;
|
|
|
|
|
|
do {
|
|
do {
|
|
if (!ida_pre_get(&sd_index_ida, GFP_KERNEL))
|
|
if (!ida_pre_get(&sd_index_ida, GFP_KERNEL))
|
|
@@ -3128,6 +3150,11 @@ static int sd_probe(struct device *dev)
|
|
goto out_put;
|
|
goto out_put;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ atomic_set(&sd_devt->disk_devt.count, 1);
|
|
|
|
+ sd_devt->disk_devt.release = sd_devt_release;
|
|
|
|
+ sd_devt->idx = index;
|
|
|
|
+ gd->disk_devt = &sd_devt->disk_devt;
|
|
|
|
+
|
|
error = sd_format_disk_name("sd", index, gd->disk_name, DISK_NAME_LEN);
|
|
error = sd_format_disk_name("sd", index, gd->disk_name, DISK_NAME_LEN);
|
|
if (error) {
|
|
if (error) {
|
|
sdev_printk(KERN_WARNING, sdp, "SCSI disk (sd) name length exceeded.\n");
|
|
sdev_printk(KERN_WARNING, sdp, "SCSI disk (sd) name length exceeded.\n");
|
|
@@ -3167,13 +3194,14 @@ static int sd_probe(struct device *dev)
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
out_free_index:
|
|
out_free_index:
|
|
- spin_lock(&sd_index_lock);
|
|
|
|
- ida_remove(&sd_index_ida, index);
|
|
|
|
- spin_unlock(&sd_index_lock);
|
|
|
|
|
|
+ put_disk_devt(&sd_devt->disk_devt);
|
|
|
|
+ sd_devt = NULL;
|
|
out_put:
|
|
out_put:
|
|
put_disk(gd);
|
|
put_disk(gd);
|
|
out_free:
|
|
out_free:
|
|
kfree(sdkp);
|
|
kfree(sdkp);
|
|
|
|
+ out_free_devt:
|
|
|
|
+ kfree(sd_devt);
|
|
out:
|
|
out:
|
|
scsi_autopm_put_device(sdp);
|
|
scsi_autopm_put_device(sdp);
|
|
return error;
|
|
return error;
|
|
@@ -3232,10 +3260,7 @@ static void scsi_disk_release(struct device *dev)
|
|
struct scsi_disk *sdkp = to_scsi_disk(dev);
|
|
struct scsi_disk *sdkp = to_scsi_disk(dev);
|
|
struct gendisk *disk = sdkp->disk;
|
|
struct gendisk *disk = sdkp->disk;
|
|
|
|
|
|
- spin_lock(&sd_index_lock);
|
|
|
|
- ida_remove(&sd_index_ida, sdkp->index);
|
|
|
|
- spin_unlock(&sd_index_lock);
|
|
|
|
-
|
|
|
|
|
|
+ put_disk_devt(disk->disk_devt);
|
|
disk->private_data = NULL;
|
|
disk->private_data = NULL;
|
|
put_disk(disk);
|
|
put_disk(disk);
|
|
put_device(&sdkp->device->sdev_gendev);
|
|
put_device(&sdkp->device->sdev_gendev);
|