Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2980530pxb; Tue, 12 Jan 2021 03:29:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYlZaKdee8iZ8Cxzd+J4dJeTD3uXiurKYqWVgK50fSK2sXzYt2iQKaKND0+tupo3VctQ3c X-Received: by 2002:a05:6402:2694:: with SMTP id w20mr347346edd.200.1610450946286; Tue, 12 Jan 2021 03:29:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610450946; cv=none; d=google.com; s=arc-20160816; b=HTU6vbzepNPVLM4cH7UAhizVFheb13yyFakaqI4rp+iQNy/vj8lTbDGyhn3eTbA/9p fJqwLNJjkO3+hJ2XWxm5UxDVJT3NWvbm/RPA9QRD0zagqmET6HelHkQYsChcB9UHgnFm D2H9mqUa79JUiZOXh/wXbwnanBcfJ3YWa39FllUBlduGPnvtpTS0IdSKcHwUBm9/1rD5 zBf6Ifij5r2DA6ytOZ4ntzmOa39Cq28DOB/Ib4R32lcBAhGp91Wn+YMHKOhZ+qw5xlAi XIeoFoan8P/7mnk+DCrGjRL6IvVXGiZHvoaEg5ShmjZSNDibhUYF/daSGNrYIf1eBrq6 DZcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :sender:dkim-signature; bh=AMekzKIoXfjswvih+CfUuEZfypT+jF7HVNK0MT9+CpY=; b=coOTxZzgM9TU4sEc6puruFdSFCAT6YFZoCDrYkpRX9HEW8t3TddhvaDA5nem+HNfmz A/xrUEl2xcFJJKN9AGf3ddXfHmu11NFg+0QjFxjgqwFf6a5OGLhLMC690T3HFWYaXO3L aWOabpMRmnWot9EDHjTsR6eT+/ra2Q10el+8qyDXyNOFiAYc9TPsjYhDKhLmABnryWVA Xgl6b0l4o6eJGg8dAXBB7fj8hMSi59aA4eYEbAYQoDWrM26VOEOxKnJdS3qr51FK/uoA RBISi4ceA7fJa24Zatul2+JpudZHL6Ur2I68YIAYNhiN30nSJudNVqBaxPj4h9ibZpD4 FcYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=qICvhmeE; 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 p18si974450ejd.518.2021.01.12.03.28.41; Tue, 12 Jan 2021 03:29:06 -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; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=qICvhmeE; 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 S2391439AbhALGxB (ORCPT + 99 others); Tue, 12 Jan 2021 01:53:01 -0500 Received: from m43-15.mailgun.net ([69.72.43.15]:10752 "EHLO m43-15.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388066AbhALGxA (ORCPT ); Tue, 12 Jan 2021 01:53:00 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1610434360; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=AMekzKIoXfjswvih+CfUuEZfypT+jF7HVNK0MT9+CpY=; b=qICvhmeEdxwObK5YPAvd8gEwFmI2CqzpdJwam95TBZps/0Lw7CcqC+UJIzR7NBcgIodza4Y3 2k37q+ZcCNMz0mQpf0vqUtfAw6rzy7mT/nQcnTQw5SCC2fUxsShahmf3sfjmgzYKpHO49gv2 PRlhufpHBp2EN3y73uRdr6ptF4k= X-Mailgun-Sending-Ip: 69.72.43.15 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n10.prod.us-east-1.postgun.com with SMTP id 5ffd471ef1be2d22c46eb43a (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 12 Jan 2021 06:52:14 GMT Sender: cang=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 032EAC43463; Tue, 12 Jan 2021 06:52:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: cang) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2FBACC433CA; Tue, 12 Jan 2021 06:52:13 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 12 Jan 2021 14:52:13 +0800 From: Can Guo To: Stanley Chu Cc: 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, Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Bean Huo , Bart Van Assche , open list Subject: Re: [PATCH 1/2] scsi: ufs: Fix a possible NULL pointer issue In-Reply-To: <1610433327.17820.5.camel@mtkswgap22> References: <1609595975-12219-1-git-send-email-cang@codeaurora.org> <1609595975-12219-2-git-send-email-cang@codeaurora.org> <1610433327.17820.5.camel@mtkswgap22> Message-ID: <6d03cdacda2f757ba0d0f39ce625eaec@codeaurora.org> X-Sender: cang@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-12 14:35, Stanley Chu wrote: > Hi Can, > > On Sat, 2021-01-02 at 05:59 -0800, Can Guo wrote: >> 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); >> } > > I guess early_suspend here is to handle the case that hba is null > during > ufshcd_system_suspend() but !null during ufshcd_system_resume(). If > yes, > would it be possible? If no, may I know what is the purpose? > Yes, you are right. I think it is possible. platform_set_drvdata() is called in ufshcd_pltfrm_init(). Say suspend happens before platform_set_drvdata() is called, but resume comes back after platform_set_drvdata() is called. What do you think? Thanks, Can Guo. > Thanks a lot. > Stanley Chu > >> >> if (!hba->is_powered || pm_runtime_suspended(hba->dev))