[S390] zcrypt: fix ap_device_list handling

In ap_device_probe() we can add the new ap device to the internal
device list only if the device probe function successfully returns.
Otherwise we might end up with an invalid device in the internal ap
device list.

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 faa582ca fa331ffc

+7 -5
+7 -5
drivers/s390/crypto/ap_bus.c
··· 490 490 int rc; 491 491 492 492 ap_dev->drv = ap_drv; 493 - spin_lock_bh(&ap_device_lock); 494 - list_add(&ap_dev->list, &ap_device_list); 495 - spin_unlock_bh(&ap_device_lock); 496 493 rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV; 494 + if (!rc) { 495 + spin_lock_bh(&ap_device_lock); 496 + list_add(&ap_dev->list, &ap_device_list); 497 + spin_unlock_bh(&ap_device_lock); 498 + } 497 499 return rc; 498 500 } 499 501 ··· 534 532 535 533 ap_flush_queue(ap_dev); 536 534 del_timer_sync(&ap_dev->timeout); 537 - if (ap_drv->remove) 538 - ap_drv->remove(ap_dev); 539 535 spin_lock_bh(&ap_device_lock); 540 536 list_del_init(&ap_dev->list); 541 537 spin_unlock_bh(&ap_device_lock); 538 + if (ap_drv->remove) 539 + ap_drv->remove(ap_dev); 542 540 spin_lock_bh(&ap_dev->lock); 543 541 atomic_sub(ap_dev->queue_count, &ap_poll_requests); 544 542 spin_unlock_bh(&ap_dev->lock);