Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4761630imu; Tue, 29 Jan 2019 07:07:34 -0800 (PST) X-Google-Smtp-Source: ALg8bN5qGdQSjVxs8bBS9U6hv1PDck8Uipi2Tc7hjHRQ5ehjWiNvJPQxP0pM5Zlxzw2+s7DzWJfP X-Received: by 2002:a17:902:aa8c:: with SMTP id d12mr26801474plr.25.1548774454433; Tue, 29 Jan 2019 07:07:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548774454; cv=none; d=google.com; s=arc-20160816; b=bquWgrHdVKc6DaolpT3a/t3DS2YvRgV4t8BRWbOvtpLuX6uijXyvO+OXWYok7L42Or qWkXE1MQIIWxNlWYzIOfrk6KXFHbBaXk6H07e2CF3/g08dap3iQfvDuXa8Oc4NBnm51i WUT0rc2TXsIzM+Fu2mOl5XrZuOJcD1Q70HP876e32e2A3diCA7IGR3aX2RAYKoerjUjn RcTLFF91AEYIDavj5xxz56zq6yLoP8cadxaUebv42huyfDA31GlDY75RWzuIG8UMtJ+p lW1VVL/rMksDSN1oXo0FQCLTCuxUTv64Uya1M32jdg3gx1H57boYHZwzo93DCoTcQGNn /UoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=GKXTDmAhfTiceB9JF8ZdpDfLNP6aVCcSLuwgYOkexnk=; b=AsjG2PWbpfGlrXvms7y4NEAZLBzOMqaZdRLGV7wWRVbWSIoBnhZP6I0O4zg5wvorWP kjHAHRZoRLvPDcKntpjkwzUjnrMMZ2VRZQ5vBnSWSF7G5zLpEo0gbQ6LzCrxnqevk/2n TXZ+Ou/qSGTiC0H0fMxZ+z6TUB/UHwo3Dm+ulKD5CDx/l1k4TTB8QIhnpitb2HG8PGUU 4t/o3OJmnqfNq7kUZMh0bAGvHHJkf7hXx9hi57B0AbAs5n8TsazB/1U0YR5Ak0l616b5 2PV/fOQ3CLsUR/U8cao/OyH7NXmR3j058NumiYR8FisC2pqTJtHjjgSTuWTPw9wMbYmP 0bMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f10si8762527pgo.356.2019.01.29.07.07.17; Tue, 29 Jan 2019 07:07:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728230AbfA2PBw (ORCPT + 99 others); Tue, 29 Jan 2019 10:01:52 -0500 Received: from mga04.intel.com ([192.55.52.120]:40215 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbfA2PBs (ORCPT ); Tue, 29 Jan 2019 10:01:48 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2019 07:01:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,537,1539673200"; d="scan'208";a="122266112" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 29 Jan 2019 07:01:45 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 351712E0; Tue, 29 Jan 2019 17:01:44 +0200 (EET) From: Mika Westerberg To: linux-kernel@vger.kernel.org Cc: Michael Jamet , Yehezkel Bernat , Andreas Noever , Lukas Wunner , "David S . Miller" , Mika Westerberg , Andy Shevchenko , netdev@vger.kernel.org Subject: [PATCH 02/28] thunderbolt: Do not allocate switch if depth is greater than 6 Date: Tue, 29 Jan 2019 18:01:17 +0300 Message-Id: <20190129150143.12681-3-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129150143.12681-1-mika.westerberg@linux.intel.com> References: <20190129150143.12681-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/thunderbolt/icm.c | 5 ++--- drivers/thunderbolt/switch.c | 18 ++++++++++++------ drivers/thunderbolt/tb.h | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c index e3fc920af682..041e7ab0efd3 100644 --- a/drivers/thunderbolt/icm.c +++ b/drivers/thunderbolt/icm.c @@ -42,7 +42,6 @@ #define ICM_TIMEOUT 5000 /* ms */ #define ICM_APPROVE_TIMEOUT 10000 /* ms */ #define ICM_MAX_LINK 4 -#define ICM_MAX_DEPTH 6 /** * struct icm - Internal connection manager private data @@ -709,7 +708,7 @@ icm_fr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr) depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >> ICM_LINK_INFO_DEPTH_SHIFT; - if (link > ICM_MAX_LINK || depth > ICM_MAX_DEPTH) { + if (link > ICM_MAX_LINK || depth > TB_SWITCH_MAX_DEPTH) { tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth); return; } @@ -739,7 +738,7 @@ icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr) depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >> ICM_LINK_INFO_DEPTH_SHIFT; - if (link > ICM_MAX_LINK || depth > ICM_MAX_DEPTH) { + if (link > ICM_MAX_LINK || depth > TB_SWITCH_MAX_DEPTH) { tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth); return; } diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index cd96994dc094..a90d21abed88 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -1155,10 +1155,16 @@ static int tb_switch_get_generation(struct tb_switch *sw) struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent, u64 route) { - int i; - int cap; struct tb_switch *sw; - int upstream_port = tb_cfg_get_upstream_port(tb->ctl, route); + int upstream_port; + int i, cap, depth; + + /* Make sure we do not exceed maximum topology limit */ + depth = tb_route_length(route); + if (depth > TB_SWITCH_MAX_DEPTH) + return NULL; + + upstream_port = tb_cfg_get_upstream_port(tb->ctl, route); if (upstream_port < 0) return NULL; @@ -1175,9 +1181,9 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent, /* configure switch */ sw->config.upstream_port_number = upstream_port; - sw->config.depth = tb_route_length(route); - sw->config.route_lo = route; - sw->config.route_hi = route >> 32; + sw->config.depth = depth; + sw->config.route_hi = upper_32_bits(route); + sw->config.route_lo = lower_32_bits(route); sw->config.enabled = 0; /* initialize ports */ diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index 52584c4003e3..5faec5a8eb98 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -43,6 +43,7 @@ struct tb_switch_nvm { }; #define TB_SWITCH_KEY_SIZE 32 +#define TB_SWITCH_MAX_DEPTH 6 /** * struct tb_switch - a thunderbolt switch -- 2.20.1