Commit 7e897bb7 authored by Mika Westerberg's avatar Mika Westerberg

thunderbolt: Check that both ports are reachable when allocating path

Add sanity check that given src and dst ports are reachable through path
walk before allocating a path. If they are not then bail out early.
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
parent c64c3f3a
...@@ -229,7 +229,7 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid, ...@@ -229,7 +229,7 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,
struct tb_port *dst, int dst_hopid, int link_nr, struct tb_port *dst, int dst_hopid, int link_nr,
const char *name) const char *name)
{ {
struct tb_port *in_port, *out_port; struct tb_port *in_port, *out_port, *first_port, *last_port;
int in_hopid, out_hopid; int in_hopid, out_hopid;
struct tb_path *path; struct tb_path *path;
size_t num_hops; size_t num_hops;
...@@ -239,9 +239,20 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid, ...@@ -239,9 +239,20 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,
if (!path) if (!path)
return NULL; return NULL;
first_port = last_port = NULL;
i = 0; i = 0;
tb_for_each_port_on_path(src, dst, in_port) tb_for_each_port_on_path(src, dst, in_port) {
if (!first_port)
first_port = in_port;
last_port = in_port;
i++; i++;
}
/* Check that src and dst are reachable */
if (first_port != src || last_port != dst) {
kfree(path);
return NULL;
}
/* Each hop takes two ports */ /* Each hop takes two ports */
num_hops = i / 2; num_hops = i / 2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment