Commit a968bed78b549b4c61d4a46e59161fc1f60f96a6

Authored by Geert Uytterhoeven
Committed by Rafael J. Wysocki
1 parent fe82dcec64

PM / clk: Fix crash in clocks management code if !CONFIG_PM_RUNTIME

Unlike the clocks management code for runtime PM, the code used for
system suspend does not check the pm_clock_entry.status field.
If pm_clk_acquire() failed, ce->status will be PCE_STATUS_ERROR, and
ce->clk will be a negative error code (e.g. 0xfffffffe = -2 = -ENOENT).

Depending on the clock implementation, suspend or resume may crash with:

    Unable to handle kernel NULL pointer dereference at virtual address 00000026

(CCF clk_disable() has an IS_ERR_OR_NULL() check, while CCF clk_enable()
 only has a NULL check; pre-CCF implementations may behave differently)

While just checking for PCE_STATUS_ERROR would be sufficient, it doesn't
hurt to use the same state machine as is done for runtime PM, as this
makes the two versions more similar, and eligible for a future
consolidation.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Showing 1 changed file with 15 additions and 4 deletions Side-by-side Diff

drivers/base/power/clock_ops.c
... ... @@ -368,8 +368,13 @@
368 368  
369 369 spin_lock_irqsave(&psd->lock, flags);
370 370  
371   - list_for_each_entry_reverse(ce, &psd->clock_list, node)
372   - clk_disable(ce->clk);
  371 + list_for_each_entry_reverse(ce, &psd->clock_list, node) {
  372 + if (ce->status < PCE_STATUS_ERROR) {
  373 + if (ce->status == PCE_STATUS_ENABLED)
  374 + clk_disable(ce->clk);
  375 + ce->status = PCE_STATUS_ACQUIRED;
  376 + }
  377 + }
373 378  
374 379 spin_unlock_irqrestore(&psd->lock, flags);
375 380  
... ... @@ -385,6 +390,7 @@
385 390 struct pm_subsys_data *psd = dev_to_psd(dev);
386 391 struct pm_clock_entry *ce;
387 392 unsigned long flags;
  393 + int ret;
388 394  
389 395 dev_dbg(dev, "%s()\n", __func__);
390 396  
... ... @@ -394,8 +400,13 @@
394 400  
395 401 spin_lock_irqsave(&psd->lock, flags);
396 402  
397   - list_for_each_entry(ce, &psd->clock_list, node)
398   - __pm_clk_enable(dev, ce->clk);
  403 + list_for_each_entry(ce, &psd->clock_list, node) {
  404 + if (ce->status < PCE_STATUS_ERROR) {
  405 + ret = __pm_clk_enable(dev, ce->clk);
  406 + if (!ret)
  407 + ce->status = PCE_STATUS_ENABLED;
  408 + }
  409 + }
399 410  
400 411 spin_unlock_irqrestore(&psd->lock, flags);
401 412