summaryrefslogtreecommitdiff
path: root/drivers/thunderbolt/path.c
diff options
context:
space:
mode:
authorMika Westerberg <mika.westerberg@linux.intel.com>2020-05-17 10:44:31 +0300
committerMika Westerberg <mika.westerberg@linux.intel.com>2020-06-22 19:58:19 +0300
commit7e897bb7be11983b0ef85be80e55ed6273540101 (patch)
tree36c7ae5a333a59d85e490372aa75bfaee747458d /drivers/thunderbolt/path.c
parentc64c3f3ac63a101a00bd316eaba63d359e9ba215 (diff)
downloadlinux-7e897bb7be11983b0ef85be80e55ed6273540101.tar.xz
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: Mika Westerberg <mika.westerberg@linux.intel.com>
Diffstat (limited to 'drivers/thunderbolt/path.c')
-rw-r--r--drivers/thunderbolt/path.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/thunderbolt/path.c b/drivers/thunderbolt/path.c
index 77abb1fa80c0..854ff3412161 100644
--- a/drivers/thunderbolt/path.c
+++ b/drivers/thunderbolt/path.c
@@ -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,
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;
struct tb_path *path;
size_t num_hops;
@@ -239,9 +239,20 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,
if (!path)
return NULL;
+ first_port = last_port = NULL;
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++;
+ }
+
+ /* Check that src and dst are reachable */
+ if (first_port != src || last_port != dst) {
+ kfree(path);
+ return NULL;
+ }
/* Each hop takes two ports */
num_hops = i / 2;