From patchwork Tue Oct 25 10:18:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 10665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp907656wru; Tue, 25 Oct 2022 02:51:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5QNPS8Th/s66DIjGOW0sewVFE2Gmyp7HzLsUjXXaMhz6Pa/5SYhIeiCn4abOUIBmajcIeg X-Received: by 2002:a17:907:3ea9:b0:78d:fdf0:88fe with SMTP id hs41-20020a1709073ea900b0078dfdf088femr32860433ejc.667.1666691512402; Tue, 25 Oct 2022 02:51:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666691512; cv=none; d=google.com; s=arc-20160816; b=Ala9cdfnjJtoFH9p9PHy+2/8Wwwx183U4QaI2u+0hUxfEfPrUN1bN4wE8XuNNvdwrG xAW9m+GEhBpeeBbLzrI9/pQrT/KxkEyEkQTfa6jZpzMNTVgIp7P52DiKnXv1KrOxzz8H rilslBe29n9+qRoJeOBKcyma1hC4Hq0/q4OIRL+0aTVRdQXdnZhJsje7jeC1m8Hk6147 HynKx4Md0xtyRezRjEzHlLbDHT7FAMIUhq4VKtPByQwJcQ3V7SSA6jNTYSmEScZza0Nv 0r7v9xokxha31uTzDhPPHq1eYbue5BvRMY+ucEASEg7mkMfLtsmdV+MtyKmLbv51cSrt 6zew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=O16xvWrKFzhvh0L17SFR5/HZSvZr7N4IlJ/RNBEiZcs=; b=01ttwidL1aV+hmQkUnLO05uwJr6+hY8wDuFYAt8xf2eDqlILW8gEAHGSSVoe99EH4m es96lbtoZlNPzNsWHq4g/kvFSIiUMhMxpkbWZ/FRGjGJKEm0bIKsGNBbyDhA5jLgscZd T01dCQTx5GJ4+4YHdXbHB+ie+xx93o/ODDaLpfH2nCgrHwLCJwwfVJcfE8hU9vAKLTbs VESqDS+aOqxGAo6KgUoCpN7sX5ou5dcelDtNH736L+jzWMK1lE4xCFTO4SkWB9IZs8D0 hDZSvLGH8VFbdoB4omriUcUsSzMCLw1HlZ/ZJ2+WRf+qcO7dxM2662GgrjG311F2Mv5O 5NxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b14-20020a056402084e00b0045d9ceae6d8si2813837edz.492.2022.10.25.02.51.28; Tue, 25 Oct 2022 02:51:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbiJYJuA (ORCPT + 99 others); Tue, 25 Oct 2022 05:50:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232005AbiJYJsg (ORCPT ); Tue, 25 Oct 2022 05:48:36 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E70A1136423; Tue, 25 Oct 2022 02:48:20 -0700 (PDT) Received: from fraeml701-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MxRsY5jf1z6H72c; Tue, 25 Oct 2022 17:46:25 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by fraeml701-chm.china.huawei.com (10.206.15.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.31; Tue, 25 Oct 2022 11:48:18 +0200 Received: from localhost.localdomain (10.69.192.58) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 25 Oct 2022 10:48:14 +0100 From: John Garry To: , , , , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v3 06/22] scsi: libsas: Improve sas_ex_discover_expander() error handling Date: Tue, 25 Oct 2022 18:18:00 +0800 Message-ID: <1666693096-180008-7-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1666693096-180008-1-git-send-email-john.garry@huawei.com> References: <1666693096-180008-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To lhrpeml500003.china.huawei.com (7.191.162.67) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747652719611881581?= X-GMAIL-MSGID: =?utf-8?q?1747652719611881581?= Errors in function sas_ex_discover_expander() are generally ignored, so add handling to gracefully handles errors in all cases. Signed-off-by: John Garry --- drivers/scsi/libsas/sas_expander.c | 50 ++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index 2907ca5d0ed4..9e33014ec412 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -919,7 +919,6 @@ static struct domain_device *sas_ex_discover_expander( struct sas_rphy *rphy; struct sas_expander_device *edev; struct asd_sas_port *port; - int res; if (phy->routing_attr == DIRECT_ROUTING) { pr_warn("ex %016llx:%02d:D <--> ex %016llx:0x%x is not allowed\n", @@ -933,9 +932,11 @@ static struct domain_device *sas_ex_discover_expander( return NULL; phy->port = sas_port_alloc(&parent->rphy->dev, phy_id); - /* FIXME: better error handling */ - BUG_ON(sas_port_add(phy->port) != 0); + if (!phy->port) + goto err_put_child; + if (!sas_port_add(phy->port)) + goto err_delete_port; switch (phy->attached_dev_type) { case SAS_EDGE_EXPANDER_DEVICE: @@ -948,8 +949,15 @@ static struct domain_device *sas_ex_discover_expander( break; default: rphy = NULL; /* shut gcc up */ - BUG(); + pr_warn("ex unhandled dev type %d %016llx:%02d:D <--> ex %016llx:%02d\n", + phy->attached_dev_type, + SAS_ADDR(parent->sas_addr), phy_id, + SAS_ADDR(phy->attached_sas_addr), + phy->attached_phy_id); } + if (!rphy) + goto err_free_port; + port = parent->port; child->rphy = rphy; get_device(&rphy->dev); @@ -967,26 +975,36 @@ static struct domain_device *sas_ex_discover_expander( parent->port->disc.max_level = max(parent->port->disc.max_level, edev->level); sas_init_dev(child); + sas_fill_in_rphy(child, rphy); - sas_rphy_add(rphy); + if (!sas_rphy_add(rphy)) + goto err_rphy_free; spin_lock_irq(&parent->port->dev_list_lock); list_add_tail(&child->dev_list_node, &parent->port->dev_list); spin_unlock_irq(&parent->port->dev_list_lock); - res = sas_discover_expander(child); - if (res) { - sas_rphy_delete(rphy); - spin_lock_irq(&parent->port->dev_list_lock); - list_del(&child->dev_list_node); - spin_unlock_irq(&parent->port->dev_list_lock); - sas_put_device(child); - sas_port_delete(phy->port); - phy->port = NULL; - return NULL; - } + if (!sas_discover_expander(child)) + goto err_rphy_remove; + list_add_tail(&child->siblings, &parent->ex_dev.children); return child; + +err_rphy_remove: + spin_lock_irq(&parent->port->dev_list_lock); + list_del(&child->dev_list_node); + spin_unlock_irq(&parent->port->dev_list_lock); + sas_rphy_remove(rphy); +err_rphy_free: + sas_rphy_free(rphy); +err_free_port: + sas_port_free(phy->port); +err_delete_port: + sas_port_delete(phy->port); + phy->port = NULL; +err_put_child: + sas_put_device(child); + return NULL; } static int sas_ex_discover_dev(struct domain_device *dev, int phy_id)