From e7585bd7b8e326343a0a2b798ae17fbfb80a87fa Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 8 Oct 2020 18:04:34 +0200 Subject: [PATCH] acp: handle devices with no ports Make sure we don't crash when there are no ports on a device. See #321 --- spa/plugins/alsa/acp/acp.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spa/plugins/alsa/acp/acp.c b/spa/plugins/alsa/acp/acp.c index 39c06343b..45afaa806 100644 --- a/spa/plugins/alsa/acp/acp.c +++ b/spa/plugins/alsa/acp/acp.c @@ -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)