acp: handle devices with no ports

Make sure we don't crash when there are no ports on a device.

See #321
This commit is contained in:
Wim Taymans 2020-10-08 18:04:34 +02:00
parent 5c048500cc
commit e7585bd7b8

View file

@ -1025,8 +1025,10 @@ static int device_enable(pa_card *impl, pa_alsa_mapping *mapping, pa_alsa_device
find_mixer(impl, dev, NULL, ignore_dB);
port_index = acp_device_find_best_port_index(&dev->device, NULL);
dev->active_port = (pa_device_port*)impl->card.ports[port_index];
if (port_index == ACP_INVALID_INDEX)
dev->active_port = NULL;
else
dev->active_port = (pa_device_port*)impl->card.ports[port_index];
if (dev->active_port)
dev->active_port->port.flags |= ACP_PORT_ACTIVE;
@ -1382,7 +1384,10 @@ uint32_t acp_device_find_best_port_index(struct acp_device *dev, const char *nam
best = best3;
if (best == ACP_INVALID_INDEX)
best = 0;
return ports[best]->index;
if (best < dev->n_ports)
return ports[best]->index;
else
return ACP_INVALID_INDEX;
}
int acp_device_set_port(struct acp_device *dev, uint32_t port_index)