LCOV - code coverage report
Current view: top level - drivers/base/power - common.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 16 0.0 %
Date: 2014-02-18 Functions: 0 2 0.0 %
Branches: 0 8 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * drivers/base/power/common.c - Common device power management code.
       3                 :            :  *
       4                 :            :  * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
       5                 :            :  *
       6                 :            :  * This file is released under the GPLv2.
       7                 :            :  */
       8                 :            : 
       9                 :            : #include <linux/init.h>
      10                 :            : #include <linux/kernel.h>
      11                 :            : #include <linux/device.h>
      12                 :            : #include <linux/export.h>
      13                 :            : #include <linux/slab.h>
      14                 :            : #include <linux/pm_clock.h>
      15                 :            : 
      16                 :            : /**
      17                 :            :  * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
      18                 :            :  * @dev: Device to handle.
      19                 :            :  *
      20                 :            :  * If power.subsys_data is NULL, point it to a new object, otherwise increment
      21                 :            :  * its reference counter.  Return 1 if a new object has been created, otherwise
      22                 :            :  * return 0 or error code.
      23                 :            :  */
      24                 :          0 : int dev_pm_get_subsys_data(struct device *dev)
      25                 :            : {
      26                 :            :         struct pm_subsys_data *psd;
      27                 :            : 
      28                 :            :         psd = kzalloc(sizeof(*psd), GFP_KERNEL);
      29         [ #  # ]:          0 :         if (!psd)
      30                 :            :                 return -ENOMEM;
      31                 :            : 
      32                 :            :         spin_lock_irq(&dev->power.lock);
      33                 :            : 
      34         [ #  # ]:          0 :         if (dev->power.subsys_data) {
      35                 :          0 :                 dev->power.subsys_data->refcount++;
      36                 :            :         } else {
      37                 :          0 :                 spin_lock_init(&psd->lock);
      38                 :          0 :                 psd->refcount = 1;
      39                 :          0 :                 dev->power.subsys_data = psd;
      40                 :          0 :                 pm_clk_init(dev);
      41                 :            :                 psd = NULL;
      42                 :            :         }
      43                 :            : 
      44                 :            :         spin_unlock_irq(&dev->power.lock);
      45                 :            : 
      46                 :            :         /* kfree() verifies that its argument is nonzero. */
      47                 :          0 :         kfree(psd);
      48                 :            : 
      49                 :          0 :         return 0;
      50                 :            : }
      51                 :            : EXPORT_SYMBOL_GPL(dev_pm_get_subsys_data);
      52                 :            : 
      53                 :            : /**
      54                 :            :  * dev_pm_put_subsys_data - Drop reference to power.subsys_data.
      55                 :            :  * @dev: Device to handle.
      56                 :            :  *
      57                 :            :  * If the reference counter of power.subsys_data is zero after dropping the
      58                 :            :  * reference, power.subsys_data is removed.  Return 1 if that happens or 0
      59                 :            :  * otherwise.
      60                 :            :  */
      61                 :          0 : int dev_pm_put_subsys_data(struct device *dev)
      62                 :            : {
      63                 :            :         struct pm_subsys_data *psd;
      64                 :            :         int ret = 1;
      65                 :            : 
      66                 :            :         spin_lock_irq(&dev->power.lock);
      67                 :            : 
      68                 :            :         psd = dev_to_psd(dev);
      69         [ #  # ]:          0 :         if (!psd)
      70                 :            :                 goto out;
      71                 :            : 
      72         [ #  # ]:          0 :         if (--psd->refcount == 0) {
      73                 :          0 :                 dev->power.subsys_data = NULL;
      74                 :            :         } else {
      75                 :            :                 psd = NULL;
      76                 :            :                 ret = 0;
      77                 :            :         }
      78                 :            : 
      79                 :            :  out:
      80                 :            :         spin_unlock_irq(&dev->power.lock);
      81                 :          0 :         kfree(psd);
      82                 :            : 
      83                 :          0 :         return ret;
      84                 :            : }
      85                 :            : EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data);

Generated by: LCOV version 1.9