@@ -104,10 +104,8 @@ static ssize_t zfcp_sysfs_##_feat##_failed_store(struct device *dev, \
104104 unsigned long val; \
105105 int retval = 0; \
106106 \
107- if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_REMOVE) { \
108- retval = -EBUSY; \
109- goto out; \
110- } \
107+ if (!(_feat && get_device(&_feat->sysfs_device))) \
108+ return -EBUSY; \
111109 \
112110 if (strict_strtoul(buf, 0, &val) || val != 0) { \
113111 retval = -EINVAL; \
@@ -120,6 +118,7 @@ static ssize_t zfcp_sysfs_##_feat##_failed_store(struct device *dev, \
120118 _reopen_id, NULL); \
121119 zfcp_erp_wait(_adapter); \
122120out: \
121+ put_device(&_feat->sysfs_device); \
123122 return retval ? retval : (ssize_t) count; \
124123} \
125124static ZFCP_DEV_ATTR(_feat, failed, S_IWUSR | S_IRUGO, \
@@ -161,11 +160,6 @@ static ssize_t zfcp_sysfs_adapter_failed_store(struct device *dev,
161160 if (!adapter )
162161 return - ENODEV ;
163162
164- if (atomic_read (& adapter -> status ) & ZFCP_STATUS_COMMON_REMOVE ) {
165- retval = - EBUSY ;
166- goto out ;
167- }
168-
169163 if (strict_strtoul (buf , 0 , & val ) || val != 0 ) {
170164 retval = - EINVAL ;
171165 goto out ;
@@ -195,14 +189,9 @@ static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev,
195189 if (!adapter )
196190 return - ENODEV ;
197191
198- if (atomic_read (& adapter -> status ) & ZFCP_STATUS_COMMON_REMOVE ) {
199- ret = - EBUSY ;
200- goto out ;
201- }
202-
203192 ret = zfcp_fc_scan_ports (adapter );
204- out :
205193 zfcp_ccw_adapter_put (adapter );
194+
206195 return ret ? ret : (ssize_t ) count ;
207196}
208197static ZFCP_DEV_ATTR (adapter , port_rescan , S_IWUSR , NULL,
@@ -216,28 +205,19 @@ static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
216205 struct zfcp_adapter * adapter = zfcp_ccw_adapter_by_cdev (cdev );
217206 struct zfcp_port * port ;
218207 u64 wwpn ;
219- int retval = 0 ;
208+ int retval = - EINVAL ;
220209
221210 if (!adapter )
222211 return - ENODEV ;
223212
224- if (atomic_read (& adapter -> status ) & ZFCP_STATUS_COMMON_REMOVE ) {
225- retval = - EBUSY ;
213+ if (strict_strtoull (buf , 0 , (unsigned long long * ) & wwpn ))
226214 goto out ;
227- }
228-
229- if (strict_strtoull (buf , 0 , (unsigned long long * ) & wwpn )) {
230- retval = - EINVAL ;
231- goto out ;
232- }
233215
234216 port = zfcp_get_port_by_wwpn (adapter , wwpn );
235- if (!port ) {
236- retval = - ENXIO ;
217+ if (!port )
237218 goto out ;
238- }
239-
240- atomic_set_mask (ZFCP_STATUS_COMMON_REMOVE , & port -> status );
219+ else
220+ retval = 0 ;
241221
242222 write_lock_irq (& adapter -> port_list_lock );
243223 list_del (& port -> list );
@@ -283,24 +263,23 @@ static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
283263 u64 fcp_lun ;
284264 int retval = - EINVAL ;
285265
286- if (atomic_read (& port -> status ) & ZFCP_STATUS_COMMON_REMOVE ) {
287- retval = - EBUSY ;
288- goto out ;
289- }
266+ if (!(port && get_device (& port -> sysfs_device )))
267+ return - EBUSY ;
290268
291269 if (strict_strtoull (buf , 0 , (unsigned long long * ) & fcp_lun ))
292270 goto out ;
293271
294272 unit = zfcp_unit_enqueue (port , fcp_lun );
295273 if (IS_ERR (unit ))
296274 goto out ;
297-
298- retval = 0 ;
275+ else
276+ retval = 0 ;
299277
300278 zfcp_erp_unit_reopen (unit , 0 , "syuas_1" , NULL );
301279 zfcp_erp_wait (unit -> port -> adapter );
302280 flush_work (& unit -> scsi_work );
303281out :
282+ put_device (& port -> sysfs_device );
304283 return retval ? retval : (ssize_t ) count ;
305284}
306285static DEVICE_ATTR (unit_add , S_IWUSR , NULL, zfcp_sysfs_unit_add_store ) ;
@@ -313,29 +292,23 @@ static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev,
313292 sysfs_device );
314293 struct zfcp_unit * unit ;
315294 u64 fcp_lun ;
316- int retval = 0 ;
295+ int retval = - EINVAL ;
317296
318- if (atomic_read (& port -> status ) & ZFCP_STATUS_COMMON_REMOVE ) {
319- retval = - EBUSY ;
320- goto out ;
321- }
297+ if (!(port && get_device (& port -> sysfs_device )))
298+ return - EBUSY ;
322299
323- if (strict_strtoull (buf , 0 , (unsigned long long * ) & fcp_lun )) {
324- retval = - EINVAL ;
300+ if (strict_strtoull (buf , 0 , (unsigned long long * ) & fcp_lun ))
325301 goto out ;
326- }
327302
328303 unit = zfcp_get_unit_by_lun (port , fcp_lun );
329- if (!unit ) {
330- retval = - EINVAL ;
304+ if (!unit )
331305 goto out ;
332- }
306+ else
307+ retval = 0 ;
333308
334309 /* wait for possible timeout during SCSI probe */
335310 flush_work (& unit -> scsi_work );
336311
337- atomic_set_mask (ZFCP_STATUS_COMMON_REMOVE , & unit -> status );
338-
339312 write_lock_irq (& port -> unit_list_lock );
340313 list_del (& unit -> list );
341314 write_unlock_irq (& port -> unit_list_lock );
@@ -345,6 +318,7 @@ static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev,
345318 zfcp_erp_unit_shutdown (unit , 0 , "syurs_1" , NULL );
346319 zfcp_device_unregister (& unit -> sysfs_device , & zfcp_sysfs_unit_attrs );
347320out :
321+ put_device (& port -> sysfs_device );
348322 return retval ? retval : (ssize_t ) count ;
349323}
350324static DEVICE_ATTR (unit_remove , S_IWUSR , NULL, zfcp_sysfs_unit_remove_store ) ;
0 commit comments