+ // First try to find an exact match on a dead card.
+ for (unsigned i = 0; i < devices.size(); ++i) {
+ if (devices[i].state == Device::State::DEAD &&
+ devices[i].address == address &&
+ devices[i].name == name &&
+ devices[i].info == info &&
+ devices[i].num_channels == num_channels) {
+ devices[i].state = Device::State::READY;
+ return i;
+ }
+ }
+
+ // Then try to find a match on everything but the address
+ // (probably that devices were plugged back in a different order).
+ // If we have two cards that are equal, this might get them mixed up,
+ // but we don't have anything better.
+ for (unsigned i = 0; i < devices.size(); ++i) {
+ if (devices[i].state == Device::State::DEAD &&
+ devices[i].name == name &&
+ devices[i].info == info &&
+ devices[i].num_channels == num_channels) {
+ devices[i].state = Device::State::READY;
+ return i;
+ }
+ }
+
+ // OK, so we didn't find a match; see if there are any empty slots.