summaryrefslogtreecommitdiffstats
path: root/drivers/scsi/device_handler/scsi_dh.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2014-09-14 05:08:44 +0200
committerChristoph Hellwig <hch@lst.de>2014-11-12 11:19:33 +0100
commit1f12ffa51479741db7c4ac1b7abc21662e4ce119 (patch)
tree75b5a277b9299423ea5ae7f7cec6f7d8c7dc2bd5 /drivers/scsi/device_handler/scsi_dh.c
parentscsi: remove struct scsi_dh_devlist (diff)
downloadlinux-1f12ffa51479741db7c4ac1b7abc21662e4ce119.tar.xz
linux-1f12ffa51479741db7c4ac1b7abc21662e4ce119.zip
scsi: device handlers must have attach and detach methods
Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Mike Christie <michaelc@cs.wisc.edu> Reviewed-by: Hannes Reinecke <hare@suse.de>
Diffstat (limited to 'drivers/scsi/device_handler/scsi_dh.c')
-rw-r--r--drivers/scsi/device_handler/scsi_dh.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/drivers/scsi/device_handler/scsi_dh.c b/drivers/scsi/device_handler/scsi_dh.c
index 1a8dbf33f2ac..d8a8aac2c3db 100644
--- a/drivers/scsi/device_handler/scsi_dh.c
+++ b/drivers/scsi/device_handler/scsi_dh.c
@@ -108,19 +108,17 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,
return 0;
}
- if (scsi_dh->attach) {
- if (!try_module_get(scsi_dh->module))
- return -EINVAL;
-
- err = scsi_dh->attach(sdev);
- if (err) {
- module_put(scsi_dh->module);
- return err;
- }
+ if (!try_module_get(scsi_dh->module))
+ return -EINVAL;
- kref_init(&sdev->scsi_dh_data->kref);
- sdev->scsi_dh_data->sdev = sdev;
+ err = scsi_dh->attach(sdev);
+ if (err) {
+ module_put(scsi_dh->module);
+ return err;
}
+
+ kref_init(&sdev->scsi_dh_data->kref);
+ sdev->scsi_dh_data->sdev = sdev;
return err;
}
@@ -154,7 +152,7 @@ static void scsi_dh_handler_detach(struct scsi_device *sdev,
if (!scsi_dh)
scsi_dh = sdev->scsi_dh_data->scsi_dh;
- if (scsi_dh && scsi_dh->detach)
+ if (scsi_dh)
kref_put(&sdev->scsi_dh_data->kref, __detach_handler);
}
@@ -343,6 +341,9 @@ int scsi_register_device_handler(struct scsi_device_handler *scsi_dh)
if (get_device_handler(scsi_dh->name))
return -EBUSY;
+ if (!scsi_dh->attach || !scsi_dh->detach)
+ return -EINVAL;
+
spin_lock(&list_lock);
list_add(&scsi_dh->list, &scsi_dh_list);
spin_unlock(&list_lock);