Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp12637589pxu; Sat, 2 Jan 2021 06:04:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPBkIKVsWRuntpkdMcvMrEgRCN2AepQLgHBTiRDgaxo05qJjw8kXYfd/7oFsmju48fKwTi X-Received: by 2002:a05:6402:1102:: with SMTP id u2mr33400651edv.18.1609596263799; Sat, 02 Jan 2021 06:04:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609596263; cv=none; d=google.com; s=arc-20160816; b=TdkvXfaMANdDhh/ANukkU2qJ4dp+Bd9Rjd2vRy/ItkQGGfHPsIz2jn+r2zkPePqSFx TYlNqwxGUbNCJPYj95BEJf7HglE9kiAih2DBb7ckWWVz1k/9GPlVZeDCuQFUT6caiCME hq9F4P5oXchC+p7VCWT017oyQ8oypxOXNzKfOdYJw/iaOw13JdG1wUkLgR0hvh90aYBh fAWGJedS/QfLtAZ5C6NxQGpgYAn934MkE9vvJYAA9Hq7djEOh2A6jkcHcOGV4AFr8htQ 4XR1A8Oy/3wl5+yswi+m5/hTZZeCXabaFuo7Y/fP5zDoMw1KKHuMSblN+ba6a8XuWxEa cc1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr; bh=2yvvU93zDgUbwBOcXtEyQ21HpthM+A+9l11QPJwkO5U=; b=UmWhNiqfrlePaW9zqiHnnenfNwu5i5tgz373bui9h+yjBHZ5LaXxwzOQy3WEUsZ4mp dIKj29ajpHldqFbRYptWrOh4xLmgl2XzLzTOQlU9aj0NhVMbDRtu7GsqF7xvW5gwSohc 0ol82PIX8IEBJ/M8tu9fmLdDZthVTP3OPURVq8ehWiBwo7CIGNmLnV14zwBZ4L1n3wXR WIiJS5wkwsnJnpziHJzTMON1bsTnFlgeGK5yKp6LSqO2pYwgfZR0fZSiZXMli/e2kQtU qEQcAcldLXpAlwH0iySfDuuU4UwMrPiS8/CaR5J+NTZJO9p71DEiVC1tzRDgPJfYOXP5 cECg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pk26si24470923ejb.584.2021.01.02.06.03.36; Sat, 02 Jan 2021 06:04:23 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726640AbhABOAh (ORCPT + 99 others); Sat, 2 Jan 2021 09:00:37 -0500 Received: from labrats.qualcomm.com ([199.106.110.90]:20241 "EHLO labrats.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726561AbhABOAh (ORCPT ); Sat, 2 Jan 2021 09:00:37 -0500 IronPort-SDR: RKLfSV7ITHhdpTzWS3qwDiMgrp8Wrwz6QVWwflSxipDQJCAgb8hsmEkvkMAy2gYoBow4RAU7KB IIO7AhpWX3dh5ftwh7Re2mfNvDbkA3EptFSP4/o/lwbSJJKjKDIpsDrZ/MahdrBBlnDQzH388q GK28O2fZpe7J037fDEVUlZxXgcnyqZPMhMteIHtm0dhc+8xyUSN/shyEVy8vEbxHFdOo1WxfRa A+9RmcxxPRz0HtXRw/iWmD2vT8LRGfVeoIJ2Z7tzU+yqH2Q6Pn/+iHa2bSUZKdK1OxKlGT3uIX 3lk= X-IronPort-AV: E=Sophos;i="5.78,469,1599548400"; d="scan'208";a="29476449" Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by labrats.qualcomm.com with ESMTP; 02 Jan 2021 05:59:44 -0800 X-QCInternal: smtphost Received: from wsp769891wss.qualcomm.com (HELO stor-presley.qualcomm.com) ([192.168.140.85]) by ironmsg01-sd.qualcomm.com with ESMTP; 02 Jan 2021 05:59:43 -0800 Received: by stor-presley.qualcomm.com (Postfix, from userid 359480) id 075EE2187E; Sat, 2 Jan 2021 05:59:44 -0800 (PST) From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, ziqichen@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Bart Van Assche , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/2] scsi: ufs: Fix a possible NULL pointer issue Date: Sat, 2 Jan 2021 05:59:33 -0800 Message-Id: <1609595975-12219-2-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1609595975-12219-1-git-send-email-cang@codeaurora.org> References: <1609595975-12219-1-git-send-email-cang@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During system resume/suspend, hba could be NULL. In this case, do not touch eh_sem. Fixes: 88a92d6ae4fe ("scsi: ufs: Serialize eh_work with system PM events and async scan") Signed-off-by: Can Guo diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index e221add..9829c8d 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -94,6 +94,8 @@ 16, 4, buf, __len, false); \ } while (0) +static bool early_suspend; + int ufshcd_dump_regs(struct ufs_hba *hba, size_t offset, size_t len, const char *prefix) { @@ -8896,8 +8898,14 @@ int ufshcd_system_suspend(struct ufs_hba *hba) int ret = 0; ktime_t start = ktime_get(); + if (!hba) { + early_suspend = true; + return 0; + } + down(&hba->eh_sem); - if (!hba || !hba->is_powered) + + if (!hba->is_powered) return 0; if ((ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl) == @@ -8945,9 +8953,12 @@ int ufshcd_system_resume(struct ufs_hba *hba) int ret = 0; ktime_t start = ktime_get(); - if (!hba) { - up(&hba->eh_sem); + if (!hba) return -EINVAL; + + if (unlikely(early_suspend)) { + early_suspend = false; + down(&hba->eh_sem); } if (!hba->is_powered || pm_runtime_suspended(hba->dev)) -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.