aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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,
108 return 0; 108 return 0;
109 } 109 }
110 110
111 if (scsi_dh->attach) { 111 if (!try_module_get(scsi_dh->module))
112 if (!try_module_get(scsi_dh->module)) 112 return -EINVAL;
113 return -EINVAL;
114
115 err = scsi_dh->attach(sdev);
116 if (err) {
117 module_put(scsi_dh->module);
118 return err;
119 }
120 113
121 kref_init(&sdev->scsi_dh_data->kref); 114 err = scsi_dh->attach(sdev);
122 sdev->scsi_dh_data->sdev = sdev; 115 if (err) {
116 module_put(scsi_dh->module);
117 return err;
123 } 118 }
119
120 kref_init(&sdev->scsi_dh_data->kref);
121 sdev->scsi_dh_data->sdev = sdev;
124 return err; 122 return err;
125} 123}
126 124
@@ -154,7 +152,7 @@ static void scsi_dh_handler_detach(struct scsi_device *sdev,
154 if (!scsi_dh) 152 if (!scsi_dh)
155 scsi_dh = sdev->scsi_dh_data->scsi_dh; 153 scsi_dh = sdev->scsi_dh_data->scsi_dh;
156 154
157 if (scsi_dh && scsi_dh->detach) 155 if (scsi_dh)
158 kref_put(&sdev->scsi_dh_data->kref, __detach_handler); 156 kref_put(&sdev->scsi_dh_data->kref, __detach_handler);
159} 157}
160 158
@@ -343,6 +341,9 @@ int scsi_register_device_handler(struct scsi_device_handler *scsi_dh)
343 if (get_device_handler(scsi_dh->name)) 341 if (get_device_handler(scsi_dh->name))
344 return -EBUSY; 342 return -EBUSY;
345 343
344 if (!scsi_dh->attach || !scsi_dh->detach)
345 return -EINVAL;
346
346 spin_lock(&list_lock); 347 spin_lock(&list_lock);
347 list_add(&scsi_dh->list, &scsi_dh_list); 348 list_add(&scsi_dh->list, &scsi_dh_list);
348 spin_unlock(&list_lock); 349 spin_unlock(&list_lock);