ahci.device: Locking and flag race condition fixes