[S390] zcrypt device registration/unregistration race.

Fix a race condition during AP device registration and unregistration.

Signed-off-by: Ralph Wuerthner <rwuerthn@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by Ralph Wuerthner and committed by Martin Schwidefsky 4e56296d f1ee3281

+12 -11
+12 -11
drivers/s390/crypto/ap_bus.c
··· 449 449 450 450 ap_dev->drv = ap_drv; 451 451 rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV; 452 - if (rc) 453 - ap_dev->unregistered = 1; 454 452 return rc; 455 453 } 456 454 ··· 485 487 struct ap_device *ap_dev = to_ap_dev(dev); 486 488 struct ap_driver *ap_drv = ap_dev->drv; 487 489 488 - spin_lock_bh(&ap_dev->lock); 489 - __ap_flush_queue(ap_dev); 490 - /** 491 - * set ->unregistered to 1 while holding the lock. This prevents 492 - * new messages to be put on the queue from now on. 493 - */ 494 - ap_dev->unregistered = 1; 495 - spin_unlock_bh(&ap_dev->lock); 490 + ap_flush_queue(ap_dev); 496 491 if (ap_drv->remove) 497 492 ap_drv->remove(ap_dev); 498 493 return 0; ··· 754 763 break; 755 764 ap_dev->qid = qid; 756 765 ap_dev->queue_depth = queue_depth; 766 + ap_dev->unregistered = 1; 757 767 spin_lock_init(&ap_dev->lock); 758 768 INIT_LIST_HEAD(&ap_dev->pendingq); 759 769 INIT_LIST_HEAD(&ap_dev->requestq); ··· 776 784 /* Add device attributes. */ 777 785 rc = sysfs_create_group(&ap_dev->device.kobj, 778 786 &ap_dev_attr_group); 779 - if (rc) 787 + if (!rc) { 788 + spin_lock_bh(&ap_dev->lock); 789 + ap_dev->unregistered = 0; 790 + spin_unlock_bh(&ap_dev->lock); 791 + } 792 + else 780 793 device_unregister(&ap_dev->device); 781 794 } 782 795 } ··· 967 970 rc = __ap_queue_message(ap_dev, ap_msg); 968 971 if (!rc) 969 972 wake_up(&ap_poll_wait); 973 + if (rc == -ENODEV) 974 + ap_dev->unregistered = 1; 970 975 } else { 971 976 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); 972 977 rc = 0; ··· 1027 1028 spin_lock(&ap_dev->lock); 1028 1029 if (!ap_dev->unregistered) { 1029 1030 rc = ap_poll_queue(to_ap_dev(dev), (unsigned long *) data); 1031 + if (rc) 1032 + ap_dev->unregistered = 1; 1030 1033 } else 1031 1034 rc = 0; 1032 1035 spin_unlock(&ap_dev->lock);