Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp373530pxv; Thu, 8 Jul 2021 23:46:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6K6zp/wyWyx7tpwyzEdfUI6LIoT9ZUe/Z09noTNp0DWuH8KyWjFrqAYa13+N4Aqm/V/ZH X-Received: by 2002:a02:818c:: with SMTP id n12mr30822319jag.2.1625813194030; Thu, 08 Jul 2021 23:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625813194; cv=none; d=google.com; s=arc-20160816; b=Ott1C4/ov/kGiwFxcgOTxI3boGyggRR5o5+N7Rugg3+GiR136Ngrc5zV5InDIZC113 KcvMWBAtkIi+mmC6U57FLkxwz0C87s5HLPYNieDDFnYUhpDQwfN1eTwXqY6TXlu7TzaB 8GkdovAppm91FMmNYfncaNI2E/5S05mziktSDnFEFu6Z+sR84HUv9fUIzb2Ne2XtG/mu uZvhop/UDaSzGILp+rNeQP0yHmjtddPftZPytMXPcdYrdw2UIxZLlZcLu0SsTtTyzK64 y0D+chfAXZ61YMbtbQYc/z88eNordFcdRogXuy8qT4+hYnyQ1EEh7kCY/laq2xsTFdFP ct3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:references:in-reply-to:message-id :date:subject:cc:to:from; bh=U9JLLKSXzRitwcRXclmTIKrTLO+luuv2s7LfOVzi5Qk=; b=aki6mQROdsREEwkUZ1lNYJ+qWCE6fJoM9tPBH02giF9FGuKF7LLdwklwivHY6pUHaH 703yC+F3+flKMsTWMcaF/BLyMqzOnbwRiEMolc1Fof7ojazrYeSWEpnQ6Yo7Vw4Yf/eE tWA7OlAWQSIN1FYHi5a7ODMtzrjf4YimjQuySBd1LukodtGvG0QG7OydsuoLmhu2Gw9y 9FtcWang29+4T4+le+HMIxzrDVYrP9VK8MR0qzhvYPs1Mosqf5O1ydfs2Z0Zs5mnSr+t IWg50PboiPwjkmoD3/1q7nD+JRIC6aBIarcn+80VSdZtmLHoeSUn5q4tXNIPBzsVBSVI afQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id n3si5487373ioh.98.2021.07.08.23.46.22; Thu, 08 Jul 2021 23:46:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231149AbhGIGqX (ORCPT + 99 others); Fri, 9 Jul 2021 02:46:23 -0400 Received: from mga04.intel.com ([192.55.52.120]:52839 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230494AbhGIGqX (ORCPT ); Fri, 9 Jul 2021 02:46:23 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10039"; a="207832915" X-IronPort-AV: E=Sophos;i="5.84,226,1620716400"; d="scan'208";a="207832915" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2021 23:43:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,226,1620716400"; d="scan'208";a="648869612" Received: from ahunter-desktop.fi.intel.com ([10.237.72.79]) by fmsmga005.fm.intel.com with ESMTP; 08 Jul 2021 23:43:35 -0700 From: Adrian Hunter To: "Rafael J . Wysocki" Cc: Greg Kroah-Hartman , Saravana Kannan , "Martin K . Petersen" , "James E . J . Bottomley" , linux-scsi@vger.kernel.org, Avri Altman , Bean Huo , Can Guo , Asutosh Das , Bart Van Assche , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 2/2] scsi: ufshcd: Fix device links when BOOT WLUN fails to probe Date: Fri, 9 Jul 2021 09:43:41 +0300 Message-Id: <20210709064341.6206-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210709064341.6206-1-adrian.hunter@intel.com> References: <20210709064341.6206-1-adrian.hunter@intel.com> Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a LUN fails to probe (e.g. absent BOOT WLUN), the device will not have been registered but can still have a device link holding a reference to the device. The unwanted device link will prevent runtime suspend indefinitely, and cause some warnings if the supplier is ever deleted (e.g. by unbinding the UFS host controller). Fix by explicitly deleting the device link when SCSI destroys the SCSI device. Fixes: b294ff3e34490 ("scsi: ufs: core: Enable power management for wlun") Signed-off-by: Adrian Hunter --- drivers/scsi/ufs/ufshcd.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 708b3b62fc4d..9864a8ee0263 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -5020,15 +5020,34 @@ static int ufshcd_slave_configure(struct scsi_device *sdev) static void ufshcd_slave_destroy(struct scsi_device *sdev) { struct ufs_hba *hba; + unsigned long flags; hba = shost_priv(sdev->host); /* Drop the reference as it won't be needed anymore */ if (ufshcd_scsi_to_upiu_lun(sdev->lun) == UFS_UPIU_UFS_DEVICE_WLUN) { - unsigned long flags; - spin_lock_irqsave(hba->host->host_lock, flags); hba->sdev_ufs_device = NULL; spin_unlock_irqrestore(hba->host->host_lock, flags); + } else if (hba->sdev_ufs_device) { + struct device *supplier = NULL; + + /* Ensure UFS Device WLUN exists and does not disappear */ + spin_lock_irqsave(hba->host->host_lock, flags); + if (hba->sdev_ufs_device) { + supplier = &hba->sdev_ufs_device->sdev_gendev; + get_device(supplier); + } + spin_unlock_irqrestore(hba->host->host_lock, flags); + + if (supplier) { + /* + * If a LUN fails to probe (e.g. absent BOOT WLUN), the + * device will not have been registered but can still + * have a device link holding a reference to the device. + */ + device_link_remove(&sdev->sdev_gendev, supplier); + put_device(supplier); + } } } -- 2.17.1