linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: Add legacy pm ops usage warning
@ 2013-11-01 15:07 Shuah Khan
  2013-11-01 23:04 ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2013-11-01 15:07 UTC (permalink / raw)
  To: pavel, rjw, len.brown, gregkh
  Cc: Shuah Khan, linux-pm, linux-kernel, shuahkhan

Add legacy pm_ops usage checks to device_pm_add() when a device gets added
to PM core's list of active devices. If legacy pm_ops usage is found at its
class, bus, driver level, print warning message to indicate the driver code
needs updating to use dev pm ops interfaces. This will help serve as a way
to track drivers that still use legacy pm ops and fix them.

Signed-off-by: Shuah Khan <shuah.kh@samsung.com>
---
 drivers/base/power/main.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 9f098a8..4dc26dc 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -112,6 +112,23 @@ void device_pm_unlock(void)
 }
 
 /**
+ * check for lgeacy pm_ops usage and warn
+ */
+static void device_legacy_pm_ops_check(struct device *dev)
+{
+	char *info = "Please update driver to use dev pm_ops";
+
+	if (dev->class && (dev->class->suspend || dev->class->resume))
+		dev_warn(dev, "Driver uses legacy class pm ops - %s\n", info);
+
+	if (dev->bus && (dev->bus->suspend || dev->bus->resume))
+		dev_warn(dev, "Driver uses legacy bus pm ops - %s\n", info);
+
+	if (dev->driver && (dev->driver->suspend || dev->driver->resume))
+		dev_warn(dev, "Driver uses legacy pm ops - %s\n", info);
+}
+
+/**
  * device_pm_add - Add a device to the PM core's list of active devices.
  * @dev: Device to add to the list.
  */
@@ -123,6 +140,7 @@ void device_pm_add(struct device *dev)
 	if (dev->parent && dev->parent->power.is_prepared)
 		dev_warn(dev, "parent %s should not be sleeping\n",
 			dev_name(dev->parent));
+	device_legacy_pm_ops_check(dev);
 	list_add_tail(&dev->power.entry, &dpm_list);
 	mutex_unlock(&dpm_list_mtx);
 }
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] power: Add legacy pm ops usage warning
  2013-11-01 15:07 [PATCH] power: Add legacy pm ops usage warning Shuah Khan
@ 2013-11-01 23:04 ` Rafael J. Wysocki
  2013-11-05 18:41   ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2013-11-01 23:04 UTC (permalink / raw)
  To: Shuah Khan; +Cc: pavel, len.brown, gregkh, linux-pm, linux-kernel, shuahkhan

On Friday, November 01, 2013 09:07:04 AM Shuah Khan wrote:
> Add legacy pm_ops usage checks to device_pm_add() when a device gets added
> to PM core's list of active devices. If legacy pm_ops usage is found at its
> class, bus, driver level, print warning message to indicate the driver code
> needs updating to use dev pm ops interfaces. This will help serve as a way
> to track drivers that still use legacy pm ops and fix them.

I think it would be much better to do these checks during bus type, class or
driver registration, because if you register a bus type with legacy PM, for
example, the check in device_pm_add() will trigger for all devices with that
bus type.

Thanks!

> Signed-off-by: Shuah Khan <shuah.kh@samsung.com>
> ---
>  drivers/base/power/main.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index 9f098a8..4dc26dc 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -112,6 +112,23 @@ void device_pm_unlock(void)
>  }
>  
>  /**
> + * check for lgeacy pm_ops usage and warn
> + */
> +static void device_legacy_pm_ops_check(struct device *dev)
> +{
> +	char *info = "Please update driver to use dev pm_ops";
> +
> +	if (dev->class && (dev->class->suspend || dev->class->resume))
> +		dev_warn(dev, "Driver uses legacy class pm ops - %s\n", info);
> +
> +	if (dev->bus && (dev->bus->suspend || dev->bus->resume))
> +		dev_warn(dev, "Driver uses legacy bus pm ops - %s\n", info);
> +
> +	if (dev->driver && (dev->driver->suspend || dev->driver->resume))
> +		dev_warn(dev, "Driver uses legacy pm ops - %s\n", info);
> +}
> +
> +/**
>   * device_pm_add - Add a device to the PM core's list of active devices.
>   * @dev: Device to add to the list.
>   */
> @@ -123,6 +140,7 @@ void device_pm_add(struct device *dev)
>  	if (dev->parent && dev->parent->power.is_prepared)
>  		dev_warn(dev, "parent %s should not be sleeping\n",
>  			dev_name(dev->parent));
> +	device_legacy_pm_ops_check(dev);
>  	list_add_tail(&dev->power.entry, &dpm_list);
>  	mutex_unlock(&dpm_list_mtx);
>  }
> 
-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] power: Add legacy pm ops usage warning
  2013-11-01 23:04 ` Rafael J. Wysocki
@ 2013-11-05 18:41   ` Shuah Khan
  0 siblings, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2013-11-05 18:41 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: pavel, len.brown, gregkh, linux-pm, linux-kernel, shuahkhan, Shuah Khan

On 11/01/2013 05:04 PM, Rafael J. Wysocki wrote:
> On Friday, November 01, 2013 09:07:04 AM Shuah Khan wrote:
>> Add legacy pm_ops usage checks to device_pm_add() when a device gets added
>> to PM core's list of active devices. If legacy pm_ops usage is found at its
>> class, bus, driver level, print warning message to indicate the driver code
>> needs updating to use dev pm ops interfaces. This will help serve as a way
>> to track drivers that still use legacy pm ops and fix them.
>
> I think it would be much better to do these checks during bus type, class or
> driver registration, because if you register a bus type with legacy PM, for
> example, the check in device_pm_add() will trigger for all devices with that
> bus type.
>
> Thanks!

Rafael,

Correct. device_pm_add() triggers for all devices that use the driver. 
On the other hand, the check is done only when the device gets added to 
the pm core. I do like that part.

I am testing with adding checks driver_register() to look for suspend at 
bus level. I am not seeing the same set of drivers I saw with the check 
in device_pm_add(), which is puzzling. I am working on testing still. 
Keep you posted.

-- Shuah

-- 
Shuah Khan
Senior Linux Kernel Developer - Open Source Group
Samsung Research America(Silicon Valley)
shuah.kh@samsung.com | (970) 672-0658

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-05 18:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-01 15:07 [PATCH] power: Add legacy pm ops usage warning Shuah Khan
2013-11-01 23:04 ` Rafael J. Wysocki
2013-11-05 18:41   ` Shuah Khan

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).