Commit 0592c217 authored by Vivek Gautam's avatar Vivek Gautam Committed by Greg Kroah-Hartman

scsi: ufshcd: Fix NULL pointer dereference for in ufshcd_init

[ Upstream commit eebcc196 ]

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: 401f1e44 ("scsi: ufs: don't suspend clock scaling during clock
gating")
Signed-off-by: default avatarVivek 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: default avatarEvan Green <evgreen@chromium.org>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 6745591c
...@@ -1772,6 +1772,34 @@ static ssize_t ufshcd_clkgate_enable_store(struct device *dev, ...@@ -1772,6 +1772,34 @@ static ssize_t ufshcd_clkgate_enable_store(struct device *dev,
return count; 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) static void ufshcd_init_clk_gating(struct ufs_hba *hba)
{ {
char wq_name[sizeof("ufs_clk_gating_00")]; char wq_name[sizeof("ufs_clk_gating_00")];
...@@ -6676,6 +6704,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) ...@@ -6676,6 +6704,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)
*/ */
if (ret && !ufshcd_eh_in_progress(hba) && !hba->pm_op_in_progress) { if (ret && !ufshcd_eh_in_progress(hba) && !hba->pm_op_in_progress) {
pm_runtime_put_sync(hba->dev); pm_runtime_put_sync(hba->dev);
ufshcd_exit_clk_scaling(hba);
ufshcd_hba_exit(hba); ufshcd_hba_exit(hba);
} }
...@@ -7223,12 +7252,9 @@ static void ufshcd_hba_exit(struct ufs_hba *hba) ...@@ -7223,12 +7252,9 @@ static void ufshcd_hba_exit(struct ufs_hba *hba)
ufshcd_variant_hba_exit(hba); ufshcd_variant_hba_exit(hba);
ufshcd_setup_vreg(hba, false); ufshcd_setup_vreg(hba, false);
ufshcd_suspend_clkscaling(hba); ufshcd_suspend_clkscaling(hba);
if (ufshcd_is_clkscaling_supported(hba)) { if (ufshcd_is_clkscaling_supported(hba))
if (hba->devfreq) if (hba->devfreq)
ufshcd_suspend_clkscaling(hba); ufshcd_suspend_clkscaling(hba);
destroy_workqueue(hba->clk_scaling.workq);
ufshcd_devfreq_remove(hba);
}
ufshcd_setup_clocks(hba, false); ufshcd_setup_clocks(hba, false);
ufshcd_setup_hba_vreg(hba, false); ufshcd_setup_hba_vreg(hba, false);
hba->is_powered = false; hba->is_powered = false;
...@@ -7908,6 +7934,7 @@ void ufshcd_remove(struct ufs_hba *hba) ...@@ -7908,6 +7934,7 @@ void ufshcd_remove(struct ufs_hba *hba)
ufshcd_disable_intr(hba, hba->intr_mask); ufshcd_disable_intr(hba, hba->intr_mask);
ufshcd_hba_stop(hba, true); ufshcd_hba_stop(hba, true);
ufshcd_exit_clk_scaling(hba);
ufshcd_exit_clk_gating(hba); ufshcd_exit_clk_gating(hba);
if (ufshcd_is_clkscaling_supported(hba)) if (ufshcd_is_clkscaling_supported(hba))
device_remove_file(hba->dev, &hba->clk_scaling.enable_attr); 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) ...@@ -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_gating(hba);
ufshcd_init_clk_scaling(hba);
/* /*
* In order to avoid any spurious interrupt immediately after * In order to avoid any spurious interrupt immediately after
* registering UFS controller interrupt handler, clear any pending UFS * 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) ...@@ -8117,21 +8146,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
goto out_remove_scsi_host; 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. * Set the default power management level for runtime and system PM.
* Default power saving mode is to keep UFS link in Hibern8 state * 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) ...@@ -8169,6 +8183,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
out_remove_scsi_host: out_remove_scsi_host:
scsi_remove_host(hba->host); scsi_remove_host(hba->host);
exit_gating: exit_gating:
ufshcd_exit_clk_scaling(hba);
ufshcd_exit_clk_gating(hba); ufshcd_exit_clk_gating(hba);
out_disable: out_disable:
hba->is_irq_enabled = false; hba->is_irq_enabled = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment