From 9019edec31332e5b0cae673c5d029ed5c11b48f6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 8 Apr 2021 15:32:06 +0200 Subject: [PATCH] pw-link: improve unlink When we only have one argument, just check the link id and if that fails don't try to check the second argument because we would crash. --- src/tools/pw-link.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/tools/pw-link.c b/src/tools/pw-link.c index 7b4045363..73f4cfddb 100644 --- a/src/tools/pw-link.c +++ b/src/tools/pw-link.c @@ -339,25 +339,26 @@ static int do_unlink_ports(struct data *data) if (l->type != OBJECT_LINK) continue; - if (data->opt_input == NULL && - l->id == (uint32_t)atoi(data->opt_output)) - goto found; + if (data->opt_input == NULL) { + /* 1 arg, check link id */ + if (l->id != (uint32_t)atoi(data->opt_output)) + continue; + } else { + /* 2 args, check port names */ + if ((p = find_object(data, OBJECT_PORT, l->extra[0])) == NULL) + continue; + if ((n = find_object(data, OBJECT_NODE, p->extra[1])) == NULL) + continue; + if (!port_matches(data, n, p, data->opt_output)) + continue; - if ((p = find_object(data, OBJECT_PORT, l->extra[0])) == NULL) - continue; - if ((n = find_object(data, OBJECT_NODE, p->extra[1])) == NULL) - continue; - if (!port_matches(data, n, p, data->opt_output)) - continue; - - if ((p = find_object(data, OBJECT_PORT, l->extra[1])) == NULL) - continue; - if ((n = find_object(data, OBJECT_NODE, p->extra[1])) == NULL) - continue; - if (!port_matches(data, n, p, data->opt_input)) - continue; - -found: + if ((p = find_object(data, OBJECT_PORT, l->extra[1])) == NULL) + continue; + if ((n = find_object(data, OBJECT_NODE, p->extra[1])) == NULL) + continue; + if (!port_matches(data, n, p, data->opt_input)) + continue; + } link_id = l->id; break; }