Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thunderbolt: Do not allocate switch if depth is greater than 6

Maximum depth in Thunderbolt topology is 6 so make sure it is not
possible to allocate switches that exceed the depth limit.

While at it update tb_switch_alloc() to use upper/lower_32_bits()
following tb_switch_alloc_safe_mode().

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>

+15 -9
+2 -3
drivers/thunderbolt/icm.c
··· 42 42 #define ICM_TIMEOUT 5000 /* ms */ 43 43 #define ICM_APPROVE_TIMEOUT 10000 /* ms */ 44 44 #define ICM_MAX_LINK 4 45 - #define ICM_MAX_DEPTH 6 46 45 47 46 /** 48 47 * struct icm - Internal connection manager private data ··· 713 714 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >> 714 715 ICM_LINK_INFO_DEPTH_SHIFT; 715 716 716 - if (link > ICM_MAX_LINK || depth > ICM_MAX_DEPTH) { 717 + if (link > ICM_MAX_LINK || depth > TB_SWITCH_MAX_DEPTH) { 717 718 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth); 718 719 return; 719 720 } ··· 743 744 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >> 744 745 ICM_LINK_INFO_DEPTH_SHIFT; 745 746 746 - if (link > ICM_MAX_LINK || depth > ICM_MAX_DEPTH) { 747 + if (link > ICM_MAX_LINK || depth > TB_SWITCH_MAX_DEPTH) { 747 748 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth); 748 749 return; 749 750 }
+12 -6
drivers/thunderbolt/switch.c
··· 1130 1130 struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent, 1131 1131 u64 route) 1132 1132 { 1133 - int i; 1134 - int cap; 1135 1133 struct tb_switch *sw; 1136 - int upstream_port = tb_cfg_get_upstream_port(tb->ctl, route); 1134 + int upstream_port; 1135 + int i, cap, depth; 1136 + 1137 + /* Make sure we do not exceed maximum topology limit */ 1138 + depth = tb_route_length(route); 1139 + if (depth > TB_SWITCH_MAX_DEPTH) 1140 + return NULL; 1141 + 1142 + upstream_port = tb_cfg_get_upstream_port(tb->ctl, route); 1137 1143 if (upstream_port < 0) 1138 1144 return NULL; 1139 1145 ··· 1156 1150 1157 1151 /* configure switch */ 1158 1152 sw->config.upstream_port_number = upstream_port; 1159 - sw->config.depth = tb_route_length(route); 1160 - sw->config.route_lo = route; 1161 - sw->config.route_hi = route >> 32; 1153 + sw->config.depth = depth; 1154 + sw->config.route_hi = upper_32_bits(route); 1155 + sw->config.route_lo = lower_32_bits(route); 1162 1156 sw->config.enabled = 0; 1163 1157 1164 1158 /* initialize ports */
+1
drivers/thunderbolt/tb.h
··· 43 43 }; 44 44 45 45 #define TB_SWITCH_KEY_SIZE 32 46 + #define TB_SWITCH_MAX_DEPTH 6 46 47 47 48 /** 48 49 * struct tb_switch - a thunderbolt switch