Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1094241lql; Tue, 12 Mar 2024 07:14:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWHJuVI/iK4rScFZGtPzaB3oAL5p040ETY1R5A/HHMJzSPNrozmOaZFkwrupYrkZSW4fik/SGrGT7+suvWJM0Adm9TlfAwaGfy6RClwuQ== X-Google-Smtp-Source: AGHT+IFmKOIadCYjwtTmIHB3Gfj+hqlH8aQI8kGZfe5Q+aFa8ZDaegcMasBRILGBKqbd96G1hFcS X-Received: by 2002:a17:902:d50e:b0:1dd:9fef:67b3 with SMTP id b14-20020a170902d50e00b001dd9fef67b3mr6198813plg.13.1710252861296; Tue, 12 Mar 2024 07:14:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710252861; cv=pass; d=google.com; s=arc-20160816; b=UMXqpr0qk50zOLUClR7hwrq0rv0ejHiJOEFMIhJz/l9WO/C4nvSO8ljcWORQxoCYV/ jRL7v+fGVrJqqQZtA4UGx4FJytU4in7lC5ZCkrFSwerwddU1p8UcXqeFtL4HTgULD+nN rNhcmeLVZ1zsDAhzdTaXOVeSzar+GBEGxUGnhDo0PZmduIxdAZj04tHAwAnqsTYhG4Za E5W/d18QKbeWPIdQeHWty6OTUDnVbAekAcEoYnMUc/UKn1w873YFKYKVpqnA8TR+Z1TK rPDWyTaLdSp6Cv/dfEmQIp2odt1JxCyRXkKGkAGtGzzo7N91ItL1DRuVPulHmyxLIiyb GNLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from; bh=f/rR0kYgcOku0r50ItZqpDxz62cy3Cw3RFe9RnT7uE0=; fh=PKov2v7mtZqWrG2ToL14QCqscLF6oofVifdomTnOWI8=; b=eZMOv80IRvLwKBMrLITTLtnZCl967ksjYhKlClBtM1F5CgBuNwszv/1Th+u8sywyyS udAjCqhphgQXpuuIK4pPfo3/FJOidc65AJ5c7BxIWdI9ZQvoBOC1lGy3okm6Qbzt4SoW 3nghOtTEvtlkGrd/0tpS0ZDGQ+2SwCJBgAsc/93a3F+WxYsFEIigq9Qg5cnSRlNv9s7w 2Fu0LIgN8rYfupyTZAN/Y0tAMFAHcCjXLcwImwKA6xWwWyigXqtHLn02R1f/vH/jg3kS 5yeRhgTgT3pZO4M8Q1VVwmlYDNhjUzd2Ixm60XfDANk7Pwpk4X159J0ujP7emaumQ2cM nx9g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-100327-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100327-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l7-20020a170903244700b001dcb3b34b57si7152862pls.101.2024.03.12.07.14.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 07:14:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100327-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-100327-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100327-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2DE9A2860AD for ; Tue, 12 Mar 2024 14:13:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78DE17B3F5; Tue, 12 Mar 2024 14:12:49 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 591CC7A726; Tue, 12 Mar 2024 14:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710252768; cv=none; b=KY9fALph9YN12QZrB8qtHCRn657gTtb+nA7QPQBta3uHYQiRv/13rKXdWWQZJYKFLvXxwhae4rBviavlw5kCNRUTyrDYUga8eP3weXaI92e3yYm/EXH84Sl44PZWxKKmoBNAHX2iMDA8AeYpEZ19UoX2mjNzn1DVstvTYJgGPww= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710252768; c=relaxed/simple; bh=bmvQ8hOTiSgg1gYAFFWH60u0ekOQ2rtDYr9n67KF1Kk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QH6yFUxPypxwxm0Vcv6/2EmNzOTf3Qkxbb9S4Yldgub1zXjPHxsOwSahsBznM/oVEfU1d1gI7OjVHgTu9ip77sa5bMUqBC1B3H1l8sHjaiSX9sdzZgFw3IVpDMdAfanmyawrqFitEGCifXoRYkMWeEkulpmA1KVdMe2XC0//sco= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TvFvw1DzFz1FM6g; Tue, 12 Mar 2024 22:12:28 +0800 (CST) Received: from dggpemd100001.china.huawei.com (unknown [7.185.36.94]) by mail.maildlp.com (Postfix) with ESMTPS id EA44718001B; Tue, 12 Mar 2024 22:12:42 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpemd100001.china.huawei.com (7.185.36.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Tue, 12 Mar 2024 22:12:42 +0800 From: Xingui Yang To: , , , , CC: , , , , , Subject: [PATCH v6 3/4] scsi: libsas: Set port when ex_phy is added or deleted Date: Tue, 12 Mar 2024 14:11:02 +0000 Message-ID: <20240312141103.31358-4-yangxingui@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240312141103.31358-1-yangxingui@huawei.com> References: <20240312141103.31358-1-yangxingui@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemd100001.china.huawei.com (7.185.36.94) We found that when ex_phy was attached and added to the parent wide port, ex_phy->port was not set, resulting in sas_unregister_devs_sas_addr() not calling sas_port_delete_phy() when deleting the phy, and the deleted phy was still on the parent wide port's phy_list. When we use sas_port_add_ex_phy() to set ex_phy->port to solve the above problem, we find that after all the phys of the parent_port are removed and the number of phy becomes 0, the parent_port will not be set to NULL. Causes the freed parent port to be used when attaching a new ex_phy in sas_ex_add_parent_port(). So use sas_port_add_ex_phy() instead of sas_port_add_phy() to set ex_phy->port when ex_phy is added to the parent port, and set ex_dev->parent_port to NULL when the number of phy on the port becomes 0. Signed-off-by: Xingui Yang --- drivers/scsi/libsas/sas_expander.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index f28a83803947..77daae36232b 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -45,7 +45,7 @@ static void sas_ex_add_parent_port(struct domain_device *dev, int phy_id) BUG_ON(sas_port_add(ex->parent_port)); sas_port_mark_backlink(ex->parent_port); } - sas_port_add_phy(ex->parent_port, ex_phy->phy); + sas_port_add_ex_phy(ex->parent_port, ex_phy); } /* ---------- SMP task management ---------- */ @@ -1879,9 +1879,12 @@ static void sas_unregister_devs_sas_addr(struct domain_device *parent, if (phy->port) { sas_port_delete_phy(phy->port, phy->phy); sas_device_set_phy(found, phy->port); - if (phy->port->num_phys == 0) + if (phy->port->num_phys == 0) { list_add_tail(&phy->port->del_list, &parent->port->sas_port_del_list); + if (ex_dev->parent_port == phy->port) + ex_dev->parent_port = NULL; + } phy->port = NULL; } } -- 2.17.1