On 10/29/24 3:29 AM, Avri Altman wrote:
+ scoped_guard(spinlock_irqsave, &hba->clk_gating.lock) {
+ /*
+ * In case you are here to cancel this work the gating state
+ * would be marked as REQ_CLKS_ON. In this case save time by
+ * skipping the gating work and exit after changing the clock
+ * state to CLKS_ON.
+ */
+ if (hba->clk_gating.is_suspended || (hba->clk_gating.state != REQ_CLKS_OFF)) {
+ hba->clk_gating.state = CLKS_ON;
+ trace_ufshcd_clk_gating(dev_name(hba->dev), hba->clk_gating.state);
+ return;
+ }
+ if (ufshcd_is_ufs_dev_busy(hba) || hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL)
+ return;
}
Please remove the superfluous parentheses from around the REQ_CLKS_OFF
test and do not exceed the 80 column limit. git clang-format HEAD^ can
help with restricting code to the 80 column limit.
@@ -2072,18 +2055,18 @@ static ssize_t ufshcd_clkgate_enable_store(struct device *dev,
value = !!value;
- spin_lock_irqsave(hba->host->host_lock, flags);
- if (value == hba->clk_gating.is_enabled)
- goto out;
+ scoped_guard(spinlock_irqsave, &hba->clk_gating.lock) {
+ if (value == hba->clk_gating.is_enabled)
+ goto out;
- if (value)
- __ufshcd_release(hba);
- else
- hba->clk_gating.active_reqs++;
+ if (value)
+ __ufshcd_release(hba);
+ else
+ hba->clk_gating.active_reqs++;
- hba->clk_gating.is_enabled = value;
+ hba->clk_gating.is_enabled = value;
+ }
out:
- spin_unlock_irqrestore(hba->host->host_lock, flags);
return count;
}
Please use guard() instead of scoped_guard() and remove the "out:"
label.
@@ -9173,11 +9157,10 @@ static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
clk_disable_unprepare(clki->clk);
}
} else if (!ret && on) {
- spin_lock_irqsave(hba->host->host_lock, flags);
- hba->clk_gating.state = CLKS_ON;
+ scoped_guard(spinlock_irqsave, &hba->clk_gating.lock)
+ hba->clk_gating.state = CLKS_ON;
trace_ufshcd_clk_gating(dev_name(hba->dev),
hba->clk_gating.state);
- spin_unlock_irqrestore(hba->host->host_lock, flags);
}
The above change moves the trace_ufshcd_clk_gating() call from inside
the region protected by the host lock to outside the region protected
by clk_gating.lock. If this is intentional, shouldn't this be mentioned
in the patch description?
Thanks,
Bart.