Received: by 10.192.165.148 with SMTP id m20csp2429109imm; Sun, 22 Apr 2018 06:59:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx49mUsJPxUl4F0p38ubj32R3H4NF2WgYAHD1hPEgB2O2d/xdcC8/NznuQ3CguhS7V/6Q/DQF X-Received: by 2002:a17:902:5417:: with SMTP id d23-v6mr16779764pli.386.1524405576754; Sun, 22 Apr 2018 06:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524405576; cv=none; d=google.com; s=arc-20160816; b=GzJs5ydwLxELVi0UpUIs8umC9N39Q5UO69WT5Tw4dW1cMULggTAm4WegvQJ4hQHcqS k6kZQOcH7xzB3oMnHBUFreeXCkJti06i9uPdazdlrPlf/0VXUOiSgXXFy4tYxHk0SK8d 2hDAL3oLTxituFlmWrKvJBeqWkEOmHM6BVAujcPVBrwg8Zk+c8bS5W5oAAGUdCTCnZxf W/UgWAvCkIVYs1i/QRD7Yp/pVyx4B3jFHOCwgpGK0jRqAflc3aXsj7ipsbxXzZFSWhpL fwjUN+dtfZmAX8EMY0rME0HmEhsJ1C1hANrMQEPdxcDSLQyaBRP8haLyECbRYkxC3/11 /enQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Dk2n9829aY/ZduMsVa3mhlcokTfjSAMKX13BvUvFsYs=; b=kvVWCuabURnEh5zOazWTEh7NLsrhVrwEPYWy8wmaiam79YyqNj81+G4P2MhyM9atCp 9wdZuM6RP5yLUtNecVfz4yTJQZpNNlvyGntEB3K8ZRYM2D8as0/zfVaTr3TVV5w3/5sG RCWu3h3l/1S9bQ6opST1fXc5/83ZYpbBxWPqFWfG9D2fWt48Hwat9T0EiDsaOTh9ncxL z2BRHpvk+hRms1EI2K0z0aKBDqdRjM4aCRSsTEN31a0vCUSdK7qMKb40MOenVY4dqw6Z +vik97nBq2MhYd+vbnG8zHuesaPRA9c/+ycVEGj8JLhI9sMygxSgQd5JQ3mulvpLl5Hs NjHQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13-v6si9990671pll.416.2018.04.22.06.59.22; Sun, 22 Apr 2018 06:59:36 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754059AbeDVN54 (ORCPT + 99 others); Sun, 22 Apr 2018 09:57:56 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45976 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751301AbeDVN5w (ORCPT ); Sun, 22 Apr 2018 09:57:52 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2C600CE6; Sun, 22 Apr 2018 13:57:52 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mika Westerberg , Andy Shevchenko Subject: [PATCH 4.16 078/196] thunderbolt: Handle connecting device in place of host properly Date: Sun, 22 Apr 2018 15:51:38 +0200 Message-Id: <20180422135108.274849570@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mika Westerberg commit 79fae987518a3aa6c3c7b2e3ad5fe1e4080c12bc upstream. If the system is suspended and user disconnects cable to another host and connects it to a Thunderbolt device instead we get a warning from driver core about adding duplicate sysfs attribute and adding the new device fails. Handle this properly so that we first remove the existing XDomain connection before adding new devices. Fixes: d1ff70241a27 ("thunderbolt: Add support for XDomain discovery protocol") Signed-off-by: Mika Westerberg Reviewed-by: Andy Shevchenko Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/thunderbolt/icm.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) --- a/drivers/thunderbolt/icm.c +++ b/drivers/thunderbolt/icm.c @@ -383,6 +383,15 @@ static void remove_switch(struct tb_swit tb_switch_remove(sw); } +static void remove_xdomain(struct tb_xdomain *xd) +{ + struct tb_switch *sw; + + sw = tb_to_switch(xd->dev.parent); + tb_port_at(xd->route, sw)->xdomain = NULL; + tb_xdomain_remove(xd); +} + static void icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) { @@ -391,6 +400,7 @@ icm_fr_device_connected(struct tb *tb, c struct tb_switch *sw, *parent_sw; struct icm *icm = tb_priv(tb); bool authorized = false; + struct tb_xdomain *xd; u8 link, depth; u64 route; int ret; @@ -467,6 +477,13 @@ icm_fr_device_connected(struct tb *tb, c tb_switch_put(sw); } + /* Remove existing XDomain connection if found */ + xd = tb_xdomain_find_by_link_depth(tb, link, depth); + if (xd) { + remove_xdomain(xd); + tb_xdomain_put(xd); + } + parent_sw = tb_switch_find_by_link_depth(tb, link, depth - 1); if (!parent_sw) { tb_err(tb, "failed to find parent switch for %u.%u\n", @@ -529,15 +546,6 @@ icm_fr_device_disconnected(struct tb *tb tb_switch_put(sw); } -static void remove_xdomain(struct tb_xdomain *xd) -{ - struct tb_switch *sw; - - sw = tb_to_switch(xd->dev.parent); - tb_port_at(xd->route, sw)->xdomain = NULL; - tb_xdomain_remove(xd); -} - static void icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr) {