diff options
author | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2009-12-07 06:52:03 -0500 |
---|---|---|
committer | Martin Schwidefsky <sky@mschwide.boeblingen.de.ibm.com> | 2009-12-07 06:51:36 -0500 |
commit | 8fd138c366a8a302d9da8a428c6e927c8bff7d35 (patch) | |
tree | 23b406a120390a6631fab5ca2f35d91395971c3c /drivers/s390 | |
parent | 1b52fff059d660d4bf83d97c389dd80f1e6aad9a (diff) |
[S390] tape: cleanup reference counting
Rename tape_get_device to tape_find_device and tape_get_device_reference
to tape_get_device. The old names didn't make too much sense.
Follow the get_device()/put_device() semantic and convert tape_put_device
to a void function.
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'drivers/s390')
-rw-r--r-- | drivers/s390/char/tape.h | 6 | ||||
-rw-r--r-- | drivers/s390/char/tape_34xx.c | 8 | ||||
-rw-r--r-- | drivers/s390/char/tape_3590.c | 2 | ||||
-rw-r--r-- | drivers/s390/char/tape_block.c | 15 | ||||
-rw-r--r-- | drivers/s390/char/tape_char.c | 7 | ||||
-rw-r--r-- | drivers/s390/char/tape_core.c | 61 | ||||
-rw-r--r-- | drivers/s390/char/tape_proc.c | 2 |
7 files changed, 50 insertions, 51 deletions
diff --git a/drivers/s390/char/tape.h b/drivers/s390/char/tape.h index a26333774701..fbe41e0377b8 100644 --- a/drivers/s390/char/tape.h +++ b/drivers/s390/char/tape.h | |||
@@ -292,9 +292,9 @@ extern int tape_generic_pm_suspend(struct ccw_device *); | |||
292 | extern int tape_generic_probe(struct ccw_device *); | 292 | extern int tape_generic_probe(struct ccw_device *); |
293 | extern void tape_generic_remove(struct ccw_device *); | 293 | extern void tape_generic_remove(struct ccw_device *); |
294 | 294 | ||
295 | extern struct tape_device *tape_get_device(int devindex); | 295 | extern struct tape_device *tape_find_device(int devindex); |
296 | extern struct tape_device *tape_get_device_reference(struct tape_device *); | 296 | extern struct tape_device *tape_get_device(struct tape_device *); |
297 | extern struct tape_device *tape_put_device(struct tape_device *); | 297 | extern void tape_put_device(struct tape_device *); |
298 | 298 | ||
299 | /* Externals from tape_char.c */ | 299 | /* Externals from tape_char.c */ |
300 | extern int tapechar_init(void); | 300 | extern int tapechar_init(void); |
diff --git a/drivers/s390/char/tape_34xx.c b/drivers/s390/char/tape_34xx.c index 2fe45ff77b75..3657fe103c27 100644 --- a/drivers/s390/char/tape_34xx.c +++ b/drivers/s390/char/tape_34xx.c | |||
@@ -113,16 +113,16 @@ tape_34xx_work_handler(struct work_struct *work) | |||
113 | { | 113 | { |
114 | struct tape_34xx_work *p = | 114 | struct tape_34xx_work *p = |
115 | container_of(work, struct tape_34xx_work, work); | 115 | container_of(work, struct tape_34xx_work, work); |
116 | struct tape_device *device = p->device; | ||
116 | 117 | ||
117 | switch(p->op) { | 118 | switch(p->op) { |
118 | case TO_MSEN: | 119 | case TO_MSEN: |
119 | tape_34xx_medium_sense(p->device); | 120 | tape_34xx_medium_sense(device); |
120 | break; | 121 | break; |
121 | default: | 122 | default: |
122 | DBF_EVENT(3, "T34XX: internal error: unknown work\n"); | 123 | DBF_EVENT(3, "T34XX: internal error: unknown work\n"); |
123 | } | 124 | } |
124 | 125 | tape_put_device(device); | |
125 | p->device = tape_put_device(p->device); | ||
126 | kfree(p); | 126 | kfree(p); |
127 | } | 127 | } |
128 | 128 | ||
@@ -136,7 +136,7 @@ tape_34xx_schedule_work(struct tape_device *device, enum tape_op op) | |||
136 | 136 | ||
137 | INIT_WORK(&p->work, tape_34xx_work_handler); | 137 | INIT_WORK(&p->work, tape_34xx_work_handler); |
138 | 138 | ||
139 | p->device = tape_get_device_reference(device); | 139 | p->device = tape_get_device(device); |
140 | p->op = op; | 140 | p->op = op; |
141 | 141 | ||
142 | schedule_work(&p->work); | 142 | schedule_work(&p->work); |
diff --git a/drivers/s390/char/tape_3590.c b/drivers/s390/char/tape_3590.c index e4cc3aae9162..0c72aadb8391 100644 --- a/drivers/s390/char/tape_3590.c +++ b/drivers/s390/char/tape_3590.c | |||
@@ -608,7 +608,7 @@ tape_3590_schedule_work(struct tape_device *device, enum tape_op op) | |||
608 | 608 | ||
609 | INIT_WORK(&p->work, tape_3590_work_handler); | 609 | INIT_WORK(&p->work, tape_3590_work_handler); |
610 | 610 | ||
611 | p->device = tape_get_device_reference(device); | 611 | p->device = tape_get_device(device); |
612 | p->op = op; | 612 | p->op = op; |
613 | 613 | ||
614 | schedule_work(&p->work); | 614 | schedule_work(&p->work); |
diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c index 0c0705b91c28..c97c6aac8ed5 100644 --- a/drivers/s390/char/tape_block.c +++ b/drivers/s390/char/tape_block.c | |||
@@ -239,7 +239,7 @@ tapeblock_setup_device(struct tape_device * device) | |||
239 | disk->major = tapeblock_major; | 239 | disk->major = tapeblock_major; |
240 | disk->first_minor = device->first_minor; | 240 | disk->first_minor = device->first_minor; |
241 | disk->fops = &tapeblock_fops; | 241 | disk->fops = &tapeblock_fops; |
242 | disk->private_data = tape_get_device_reference(device); | 242 | disk->private_data = tape_get_device(device); |
243 | disk->queue = blkdat->request_queue; | 243 | disk->queue = blkdat->request_queue; |
244 | set_capacity(disk, 0); | 244 | set_capacity(disk, 0); |
245 | sprintf(disk->disk_name, "btibm%d", | 245 | sprintf(disk->disk_name, "btibm%d", |
@@ -247,11 +247,11 @@ tapeblock_setup_device(struct tape_device * device) | |||
247 | 247 | ||
248 | blkdat->disk = disk; | 248 | blkdat->disk = disk; |
249 | blkdat->medium_changed = 1; | 249 | blkdat->medium_changed = 1; |
250 | blkdat->request_queue->queuedata = tape_get_device_reference(device); | 250 | blkdat->request_queue->queuedata = tape_get_device(device); |
251 | 251 | ||
252 | add_disk(disk); | 252 | add_disk(disk); |
253 | 253 | ||
254 | tape_get_device_reference(device); | 254 | tape_get_device(device); |
255 | INIT_WORK(&blkdat->requeue_task, tapeblock_requeue); | 255 | INIT_WORK(&blkdat->requeue_task, tapeblock_requeue); |
256 | 256 | ||
257 | return 0; | 257 | return 0; |
@@ -274,13 +274,14 @@ tapeblock_cleanup_device(struct tape_device *device) | |||
274 | } | 274 | } |
275 | 275 | ||
276 | del_gendisk(device->blk_data.disk); | 276 | del_gendisk(device->blk_data.disk); |
277 | device->blk_data.disk->private_data = | 277 | device->blk_data.disk->private_data = NULL; |
278 | tape_put_device(device->blk_data.disk->private_data); | 278 | tape_put_device(device); |
279 | put_disk(device->blk_data.disk); | 279 | put_disk(device->blk_data.disk); |
280 | 280 | ||
281 | device->blk_data.disk = NULL; | 281 | device->blk_data.disk = NULL; |
282 | cleanup_queue: | 282 | cleanup_queue: |
283 | device->blk_data.request_queue->queuedata = tape_put_device(device); | 283 | device->blk_data.request_queue->queuedata = NULL; |
284 | tape_put_device(device); | ||
284 | 285 | ||
285 | blk_cleanup_queue(device->blk_data.request_queue); | 286 | blk_cleanup_queue(device->blk_data.request_queue); |
286 | device->blk_data.request_queue = NULL; | 287 | device->blk_data.request_queue = NULL; |
@@ -363,7 +364,7 @@ tapeblock_open(struct block_device *bdev, fmode_t mode) | |||
363 | struct tape_device * device; | 364 | struct tape_device * device; |
364 | int rc; | 365 | int rc; |
365 | 366 | ||
366 | device = tape_get_device_reference(disk->private_data); | 367 | device = tape_get_device(disk->private_data); |
367 | 368 | ||
368 | if (device->required_tapemarks) { | 369 | if (device->required_tapemarks) { |
369 | DBF_EVENT(2, "TBLOCK: missing tapemarks\n"); | 370 | DBF_EVENT(2, "TBLOCK: missing tapemarks\n"); |
diff --git a/drivers/s390/char/tape_char.c b/drivers/s390/char/tape_char.c index b47e20d3d1da..d44e6981eeac 100644 --- a/drivers/s390/char/tape_char.c +++ b/drivers/s390/char/tape_char.c | |||
@@ -286,9 +286,9 @@ tapechar_open (struct inode *inode, struct file *filp) | |||
286 | 286 | ||
287 | lock_kernel(); | 287 | lock_kernel(); |
288 | minor = iminor(filp->f_path.dentry->d_inode); | 288 | minor = iminor(filp->f_path.dentry->d_inode); |
289 | device = tape_get_device(minor / TAPE_MINORS_PER_DEV); | 289 | device = tape_find_device(minor / TAPE_MINORS_PER_DEV); |
290 | if (IS_ERR(device)) { | 290 | if (IS_ERR(device)) { |
291 | DBF_EVENT(3, "TCHAR:open: tape_get_device() failed\n"); | 291 | DBF_EVENT(3, "TCHAR:open: tape_find_device() failed\n"); |
292 | rc = PTR_ERR(device); | 292 | rc = PTR_ERR(device); |
293 | goto out; | 293 | goto out; |
294 | } | 294 | } |
@@ -340,7 +340,8 @@ tapechar_release(struct inode *inode, struct file *filp) | |||
340 | device->char_data.idal_buf = NULL; | 340 | device->char_data.idal_buf = NULL; |
341 | } | 341 | } |
342 | tape_release(device); | 342 | tape_release(device); |
343 | filp->private_data = tape_put_device(device); | 343 | filp->private_data = NULL; |
344 | tape_put_device(device); | ||
344 | 345 | ||
345 | return 0; | 346 | return 0; |
346 | } | 347 | } |
diff --git a/drivers/s390/char/tape_core.c b/drivers/s390/char/tape_core.c index 6311018e6543..a7b7e72c691b 100644 --- a/drivers/s390/char/tape_core.c +++ b/drivers/s390/char/tape_core.c | |||
@@ -511,11 +511,12 @@ tape_alloc_device(void) | |||
511 | * increment the reference count. | 511 | * increment the reference count. |
512 | */ | 512 | */ |
513 | struct tape_device * | 513 | struct tape_device * |
514 | tape_get_device_reference(struct tape_device *device) | 514 | tape_get_device(struct tape_device *device) |
515 | { | 515 | { |
516 | DBF_EVENT(4, "tape_get_device_reference(%p) = %i\n", device, | 516 | int count; |
517 | atomic_inc_return(&device->ref_count)); | ||
518 | 517 | ||
518 | count = atomic_inc_return(&device->ref_count); | ||
519 | DBF_EVENT(4, "tape_get_device(%p) = %i\n", device, count); | ||
519 | return device; | 520 | return device; |
520 | } | 521 | } |
521 | 522 | ||
@@ -525,32 +526,25 @@ tape_get_device_reference(struct tape_device *device) | |||
525 | * The function returns a NULL pointer to be used by the caller | 526 | * The function returns a NULL pointer to be used by the caller |
526 | * for clearing reference pointers. | 527 | * for clearing reference pointers. |
527 | */ | 528 | */ |
528 | struct tape_device * | 529 | void |
529 | tape_put_device(struct tape_device *device) | 530 | tape_put_device(struct tape_device *device) |
530 | { | 531 | { |
531 | int remain; | 532 | int count; |
532 | 533 | ||
533 | remain = atomic_dec_return(&device->ref_count); | 534 | count = atomic_dec_return(&device->ref_count); |
534 | if (remain > 0) { | 535 | DBF_EVENT(4, "tape_put_device(%p) -> %i\n", device, count); |
535 | DBF_EVENT(4, "tape_put_device(%p) -> %i\n", device, remain); | 536 | BUG_ON(count < 0); |
536 | } else { | 537 | if (count == 0) { |
537 | if (remain < 0) { | 538 | kfree(device->modeset_byte); |
538 | DBF_EVENT(4, "put device without reference\n"); | 539 | kfree(device); |
539 | } else { | ||
540 | DBF_EVENT(4, "tape_free_device(%p)\n", device); | ||
541 | kfree(device->modeset_byte); | ||
542 | kfree(device); | ||
543 | } | ||
544 | } | 540 | } |
545 | |||
546 | return NULL; | ||
547 | } | 541 | } |
548 | 542 | ||
549 | /* | 543 | /* |
550 | * Find tape device by a device index. | 544 | * Find tape device by a device index. |
551 | */ | 545 | */ |
552 | struct tape_device * | 546 | struct tape_device * |
553 | tape_get_device(int devindex) | 547 | tape_find_device(int devindex) |
554 | { | 548 | { |
555 | struct tape_device *device, *tmp; | 549 | struct tape_device *device, *tmp; |
556 | 550 | ||
@@ -558,7 +552,7 @@ tape_get_device(int devindex) | |||
558 | read_lock(&tape_device_lock); | 552 | read_lock(&tape_device_lock); |
559 | list_for_each_entry(tmp, &tape_device_list, node) { | 553 | list_for_each_entry(tmp, &tape_device_list, node) { |
560 | if (tmp->first_minor / TAPE_MINORS_PER_DEV == devindex) { | 554 | if (tmp->first_minor / TAPE_MINORS_PER_DEV == devindex) { |
561 | device = tape_get_device_reference(tmp); | 555 | device = tape_get_device(tmp); |
562 | break; | 556 | break; |
563 | } | 557 | } |
564 | } | 558 | } |
@@ -607,7 +601,8 @@ __tape_discard_requests(struct tape_device *device) | |||
607 | list_del(&request->list); | 601 | list_del(&request->list); |
608 | 602 | ||
609 | /* Decrease ref_count for removed request. */ | 603 | /* Decrease ref_count for removed request. */ |
610 | request->device = tape_put_device(device); | 604 | request->device = NULL; |
605 | tape_put_device(device); | ||
611 | request->rc = -EIO; | 606 | request->rc = -EIO; |
612 | if (request->callback != NULL) | 607 | if (request->callback != NULL) |
613 | request->callback(request, request->callback_data); | 608 | request->callback(request, request->callback_data); |
@@ -665,9 +660,11 @@ tape_generic_remove(struct ccw_device *cdev) | |||
665 | tape_cleanup_device(device); | 660 | tape_cleanup_device(device); |
666 | } | 661 | } |
667 | 662 | ||
668 | if (dev_get_drvdata(&cdev->dev)) { | 663 | device = dev_get_drvdata(&cdev->dev); |
664 | if (device) { | ||
669 | sysfs_remove_group(&cdev->dev.kobj, &tape_attr_group); | 665 | sysfs_remove_group(&cdev->dev.kobj, &tape_attr_group); |
670 | dev_set_drvdata(&cdev->dev, tape_put_device(dev_get_drvdata(&cdev->dev))); | 666 | dev_set_drvdata(&cdev->dev, NULL); |
667 | tape_put_device(device); | ||
671 | } | 668 | } |
672 | } | 669 | } |
673 | 670 | ||
@@ -722,9 +719,8 @@ tape_free_request (struct tape_request * request) | |||
722 | { | 719 | { |
723 | DBF_LH(6, "Free request %p\n", request); | 720 | DBF_LH(6, "Free request %p\n", request); |
724 | 721 | ||
725 | if (request->device != NULL) { | 722 | if (request->device) |
726 | request->device = tape_put_device(request->device); | 723 | tape_put_device(request->device); |
727 | } | ||
728 | kfree(request->cpdata); | 724 | kfree(request->cpdata); |
729 | kfree(request->cpaddr); | 725 | kfree(request->cpaddr); |
730 | kfree(request); | 726 | kfree(request); |
@@ -839,7 +835,8 @@ static void tape_long_busy_timeout(unsigned long data) | |||
839 | BUG_ON(request->status != TAPE_REQUEST_LONG_BUSY); | 835 | BUG_ON(request->status != TAPE_REQUEST_LONG_BUSY); |
840 | DBF_LH(6, "%08x: Long busy timeout.\n", device->cdev_id); | 836 | DBF_LH(6, "%08x: Long busy timeout.\n", device->cdev_id); |
841 | __tape_start_next_request(device); | 837 | __tape_start_next_request(device); |
842 | device->lb_timeout.data = (unsigned long) tape_put_device(device); | 838 | device->lb_timeout.data = 0UL; |
839 | tape_put_device(device); | ||
843 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); | 840 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
844 | } | 841 | } |
845 | 842 | ||
@@ -919,7 +916,7 @@ __tape_start_request(struct tape_device *device, struct tape_request *request) | |||
919 | } | 916 | } |
920 | 917 | ||
921 | /* Increase use count of device for the added request. */ | 918 | /* Increase use count of device for the added request. */ |
922 | request->device = tape_get_device_reference(device); | 919 | request->device = tape_get_device(device); |
923 | 920 | ||
924 | if (list_empty(&device->req_queue)) { | 921 | if (list_empty(&device->req_queue)) { |
925 | /* No other requests are on the queue. Start this one. */ | 922 | /* No other requests are on the queue. Start this one. */ |
@@ -1118,8 +1115,8 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb) | |||
1118 | if (req->status == TAPE_REQUEST_LONG_BUSY) { | 1115 | if (req->status == TAPE_REQUEST_LONG_BUSY) { |
1119 | DBF_EVENT(3, "(%08x): del timer\n", device->cdev_id); | 1116 | DBF_EVENT(3, "(%08x): del timer\n", device->cdev_id); |
1120 | if (del_timer(&device->lb_timeout)) { | 1117 | if (del_timer(&device->lb_timeout)) { |
1121 | device->lb_timeout.data = (unsigned long) | 1118 | device->lb_timeout.data = 0UL; |
1122 | tape_put_device(device); | 1119 | tape_put_device(device); |
1123 | __tape_start_next_request(device); | 1120 | __tape_start_next_request(device); |
1124 | } | 1121 | } |
1125 | return; | 1122 | return; |
@@ -1174,7 +1171,7 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb) | |||
1174 | break; | 1171 | break; |
1175 | case TAPE_IO_LONG_BUSY: | 1172 | case TAPE_IO_LONG_BUSY: |
1176 | device->lb_timeout.data = | 1173 | device->lb_timeout.data = |
1177 | (unsigned long)tape_get_device_reference(device); | 1174 | (unsigned long) tape_get_device(device); |
1178 | device->lb_timeout.expires = jiffies + | 1175 | device->lb_timeout.expires = jiffies + |
1179 | LONG_BUSY_TIMEOUT * HZ; | 1176 | LONG_BUSY_TIMEOUT * HZ; |
1180 | DBF_EVENT(3, "(%08x): add timer\n", device->cdev_id); | 1177 | DBF_EVENT(3, "(%08x): add timer\n", device->cdev_id); |
@@ -1327,7 +1324,7 @@ EXPORT_SYMBOL(tape_generic_online); | |||
1327 | EXPORT_SYMBOL(tape_generic_offline); | 1324 | EXPORT_SYMBOL(tape_generic_offline); |
1328 | EXPORT_SYMBOL(tape_generic_pm_suspend); | 1325 | EXPORT_SYMBOL(tape_generic_pm_suspend); |
1329 | EXPORT_SYMBOL(tape_put_device); | 1326 | EXPORT_SYMBOL(tape_put_device); |
1330 | EXPORT_SYMBOL(tape_get_device_reference); | 1327 | EXPORT_SYMBOL(tape_get_device); |
1331 | EXPORT_SYMBOL(tape_state_verbose); | 1328 | EXPORT_SYMBOL(tape_state_verbose); |
1332 | EXPORT_SYMBOL(tape_op_verbose); | 1329 | EXPORT_SYMBOL(tape_op_verbose); |
1333 | EXPORT_SYMBOL(tape_state_set); | 1330 | EXPORT_SYMBOL(tape_state_set); |
diff --git a/drivers/s390/char/tape_proc.c b/drivers/s390/char/tape_proc.c index 202f42132939..ebd820ccfb24 100644 --- a/drivers/s390/char/tape_proc.c +++ b/drivers/s390/char/tape_proc.c | |||
@@ -45,7 +45,7 @@ static int tape_proc_show(struct seq_file *m, void *v) | |||
45 | seq_printf(m, "TapeNo\tBusID CuType/Model\t" | 45 | seq_printf(m, "TapeNo\tBusID CuType/Model\t" |
46 | "DevType/Model\tBlkSize\tState\tOp\tMedState\n"); | 46 | "DevType/Model\tBlkSize\tState\tOp\tMedState\n"); |
47 | } | 47 | } |
48 | device = tape_get_device(n); | 48 | device = tape_find_device(n); |
49 | if (IS_ERR(device)) | 49 | if (IS_ERR(device)) |
50 | return 0; | 50 | return 0; |
51 | spin_lock_irq(get_ccwdev_lock(device->cdev)); | 51 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |