Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp593927ima; Wed, 6 Feb 2019 05:22:22 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ+nlsI6sE7MzpKpf1/4aq1S74IJqxguSbVy2UliB0Wse78YgNIBpMi1Zit6kkLQJ71dsJn X-Received: by 2002:a62:56c7:: with SMTP id h68mr10882960pfj.134.1549459342610; Wed, 06 Feb 2019 05:22:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549459342; cv=none; d=google.com; s=arc-20160816; b=TaYqsbsQpsDo3WhTgnkrtJE0tRVkHemVQVpGLGz1TfDhfo8ft0YQBiq44KisGgymbq LDx/Rz9L9Z9aXvtIEAiIkrwc6hGoSQ2vI5cblkzLIW2lMOEUnnraM5i70O98aCIra8B0 nR7qvtH7NkLm1K0bYhitm47hHRGiOvxi4abNeooHGE9VbiTxLgCQkZ+NzY6k/3TWZH4U rST6oaxw+XxlfqWf/n8epZ8X1SzmJ1uVVAJoGyWlbd0pmMvlOwAapyalaMPxI5NNvJxK Xpcq9/rfHk7qoxR+QlV7iTsJAYX7ALC+4+7t/v0FX959V/NEq/nWtdSAxnNTTUWqOd5C trNQ== 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=uNQe1WrX+papRXwYDnVmv4Xm1FbuXpqr9qqAHnkO6FMktJJDRsuJR21o0w5F+2iqUw l1aHe0nTiooxk/izyoNLMCBESukGHKqQ0QPcMfEfTH2VQR0fSrbNTOAAAB72nDscjojs P5VFlvHuTH+/b51r1cHS9he/4DrPF8uJsrOaF3Qq7A9htTR9BLKIzADIW+4kq88lMNu8 y4agPsAJyngvDtKYqAJ+w9FwFUmpqM1OMqgVsyu8NQeDgY0L5ZD5n5OZZ+F54e1b/4gL edxTJsVd7PGCd/PEVlqkXPVdD0Ihwcztwow0wuFCGsihlnSWOidhPwtgEhTLUsfF4sLs AV3g== 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 m61si6471107plb.43.2019.02.06.05.22.07; Wed, 06 Feb 2019 05:22:22 -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 S1730592AbfBFNRs (ORCPT + 99 others); Wed, 6 Feb 2019 08:17:48 -0500 Received: from mga03.intel.com ([134.134.136.65]:26743 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729596AbfBFNRo (ORCPT ); Wed, 6 Feb 2019 08:17:44 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2019 05:17:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,340,1544515200"; d="scan'208";a="120384281" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 06 Feb 2019 05:17:39 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 9B7EF10E; Wed, 6 Feb 2019 15:17:38 +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 v2 02/28] thunderbolt: Do not allocate switch if depth is greater than 6 Date: Wed, 6 Feb 2019 16:17:12 +0300 Message-Id: <20190206131738.43696-3-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190206131738.43696-1-mika.westerberg@linux.intel.com> References: <20190206131738.43696-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