From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Vivek Gautam <vivek.gautam@codeaurora.org>,
Bjorn Andersson <bjorn.andersson@linaro.org>,
Subhash Jadavani <subhashj@codeaurora.org>,
Matthias Kaehlcke <mka@chromium.org>,
Evan Green <evgreen@chromium.org>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Sasha Levin <sashal@kernel.org>,
linux-scsi@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 199/205] scsi: ufshcd: Fix NULL pointer dereference for in ufshcd_init
Date: Fri, 8 Nov 2019 06:37:46 -0500 [thread overview]
Message-ID: <20191108113752.12502-199-sashal@kernel.org> (raw)
In-Reply-To: <20191108113752.12502-1-sashal@kernel.org>
From: Vivek Gautam <vivek.gautam@codeaurora.org>
[ Upstream commit eebcc19646489b68399ce7b35d9c38eb9f4ec40f ]
Error paths in ufshcd_init() ufshcd_hba_exit() killed clk_scaling workqueue
when the workqueue is actually created quite late in ufshcd_init(). So, we
end up getting NULL pointer dereference in such error paths. Fix this by
moving clk_scaling initialization and kill codes to two separate methods, and
call them at required places.
Fixes: 401f1e4490ee ("scsi: ufs: don't suspend clock scaling during clock
gating")
Signed-off-by: Vivek Gautam <vivek.gautam@codeaurora.org>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Subhash Jadavani <subhashj@codeaurora.org>
Cc: Matthias Kaehlcke <mka@chromium.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Evan Green <evgreen@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/scsi/ufs/ufshcd.c | 53 +++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 19 deletions(-)
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 4aaba3e030554..8bce755e0f5bc 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -1772,6 +1772,34 @@ out:
return count;
}
+static void ufshcd_init_clk_scaling(struct ufs_hba *hba)
+{
+ char wq_name[sizeof("ufs_clkscaling_00")];
+
+ if (!ufshcd_is_clkscaling_supported(hba))
+ return;
+
+ INIT_WORK(&hba->clk_scaling.suspend_work,
+ ufshcd_clk_scaling_suspend_work);
+ INIT_WORK(&hba->clk_scaling.resume_work,
+ ufshcd_clk_scaling_resume_work);
+
+ snprintf(wq_name, sizeof(wq_name), "ufs_clkscaling_%d",
+ hba->host->host_no);
+ hba->clk_scaling.workq = create_singlethread_workqueue(wq_name);
+
+ ufshcd_clkscaling_init_sysfs(hba);
+}
+
+static void ufshcd_exit_clk_scaling(struct ufs_hba *hba)
+{
+ if (!ufshcd_is_clkscaling_supported(hba))
+ return;
+
+ destroy_workqueue(hba->clk_scaling.workq);
+ ufshcd_devfreq_remove(hba);
+}
+
static void ufshcd_init_clk_gating(struct ufs_hba *hba)
{
char wq_name[sizeof("ufs_clk_gating_00")];
@@ -6676,6 +6704,7 @@ out:
*/
if (ret && !ufshcd_eh_in_progress(hba) && !hba->pm_op_in_progress) {
pm_runtime_put_sync(hba->dev);
+ ufshcd_exit_clk_scaling(hba);
ufshcd_hba_exit(hba);
}
@@ -7223,12 +7252,9 @@ static void ufshcd_hba_exit(struct ufs_hba *hba)
ufshcd_variant_hba_exit(hba);
ufshcd_setup_vreg(hba, false);
ufshcd_suspend_clkscaling(hba);
- if (ufshcd_is_clkscaling_supported(hba)) {
+ if (ufshcd_is_clkscaling_supported(hba))
if (hba->devfreq)
ufshcd_suspend_clkscaling(hba);
- destroy_workqueue(hba->clk_scaling.workq);
- ufshcd_devfreq_remove(hba);
- }
ufshcd_setup_clocks(hba, false);
ufshcd_setup_hba_vreg(hba, false);
hba->is_powered = false;
@@ -7908,6 +7934,7 @@ void ufshcd_remove(struct ufs_hba *hba)
ufshcd_disable_intr(hba, hba->intr_mask);
ufshcd_hba_stop(hba, true);
+ ufshcd_exit_clk_scaling(hba);
ufshcd_exit_clk_gating(hba);
if (ufshcd_is_clkscaling_supported(hba))
device_remove_file(hba->dev, &hba->clk_scaling.enable_attr);
@@ -8079,6 +8106,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
ufshcd_init_clk_gating(hba);
+ ufshcd_init_clk_scaling(hba);
+
/*
* In order to avoid any spurious interrupt immediately after
* registering UFS controller interrupt handler, clear any pending UFS
@@ -8117,21 +8146,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
goto out_remove_scsi_host;
}
- if (ufshcd_is_clkscaling_supported(hba)) {
- char wq_name[sizeof("ufs_clkscaling_00")];
-
- INIT_WORK(&hba->clk_scaling.suspend_work,
- ufshcd_clk_scaling_suspend_work);
- INIT_WORK(&hba->clk_scaling.resume_work,
- ufshcd_clk_scaling_resume_work);
-
- snprintf(wq_name, sizeof(wq_name), "ufs_clkscaling_%d",
- host->host_no);
- hba->clk_scaling.workq = create_singlethread_workqueue(wq_name);
-
- ufshcd_clkscaling_init_sysfs(hba);
- }
-
/*
* Set the default power management level for runtime and system PM.
* Default power saving mode is to keep UFS link in Hibern8 state
@@ -8169,6 +8183,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
out_remove_scsi_host:
scsi_remove_host(hba->host);
exit_gating:
+ ufshcd_exit_clk_scaling(hba);
ufshcd_exit_clk_gating(hba);
out_disable:
hba->is_irq_enabled = false;
--
2.20.1
prev parent reply other threads:[~2019-11-08 12:02 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20191108113752.12502-1-sashal@kernel.org>
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 137/205] scsi: qla2xxx: Use correct qpair for ABTS/CMD Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 138/205] scsi: qla2xxx: Fix iIDMA error Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 139/205] scsi: qla2xxx: Defer chip reset until target mode is enabled Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 140/205] scsi: qla2xxx: Terminate Plogi/PRLI if WWN is 0 Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 141/205] scsi: qla2xxx: Fix deadlock between ATIO and HW lock Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 142/205] scsi: qla2xxx: Increase abort timeout value Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 143/205] scsi: qla2xxx: Check for Register disconnect Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 144/205] scsi: qla2xxx: Fix port speed display on chip reset Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 145/205] scsi: qla2xxx: Fix dropped srb resource Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 146/205] scsi: qla2xxx: Fix duplicate switch's Nport ID entries Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 147/205] scsi: lpfc: Fix GFT_ID and PRLI logic for RSCN Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 148/205] scsi: lpfc: Correct invalid EQ doorbell write on if_type=6 Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 149/205] scsi: lpfc: Fix errors in log messages Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 150/205] scsi: sym53c8xx: fix NULL pointer dereference panic in sym_int_sir() Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 152/205] scsi: pm80xx: Corrected dma_unmap_sg() parameter Sasha Levin
2019-11-08 11:37 ` [PATCH AUTOSEL 4.19 153/205] scsi: pm80xx: Fixed system hang issue during kexec boot Sasha Levin
2019-11-08 11:37 ` Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191108113752.12502-199-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=bjorn.andersson@linaro.org \
--cc=evgreen@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mka@chromium.org \
--cc=stable@vger.kernel.org \
--cc=subhashj@codeaurora.org \
--cc=vivek.gautam@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).