OSDN Git Service

iio:light:bh1780: Switch from CONFIG_PM guards to pm_ptr() etc
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 30 Jan 2022 19:31:43 +0000 (19:31 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 21 Feb 2022 19:33:04 +0000 (19:33 +0000)
Letting the compiler remove these functions when the kernel is built
without CONFIG_PM support is simpler and less error prone than the
use of #ifdef based config guards.

Use the new DEFINE_RUNTIME_DEV_PM_OPS to reduce boilerplate.

Removing instances of this approach from IIO also stops them being
copied into new drivers.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20220130193147.279148-47-jic23@kernel.org
drivers/iio/light/bh1780.c

index abbf2e6..790d3d6 100644 (file)
@@ -221,7 +221,6 @@ static int bh1780_remove(struct i2c_client *client)
        return 0;
 }
 
-#ifdef CONFIG_PM
 static int bh1780_runtime_suspend(struct device *dev)
 {
        struct i2c_client *client = to_i2c_client(dev);
@@ -256,14 +255,9 @@ static int bh1780_runtime_resume(struct device *dev)
 
        return 0;
 }
-#endif /* CONFIG_PM */
 
-static const struct dev_pm_ops bh1780_dev_pm_ops = {
-       SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
-                               pm_runtime_force_resume)
-       SET_RUNTIME_PM_OPS(bh1780_runtime_suspend,
-                          bh1780_runtime_resume, NULL)
-};
+static DEFINE_RUNTIME_DEV_PM_OPS(bh1780_dev_pm_ops, bh1780_runtime_suspend,
+                               bh1780_runtime_resume, NULL);
 
 static const struct i2c_device_id bh1780_id[] = {
        { "bh1780", 0 },
@@ -284,7 +278,7 @@ static struct i2c_driver bh1780_driver = {
        .id_table       = bh1780_id,
        .driver = {
                .name = "bh1780",
-               .pm = &bh1780_dev_pm_ops,
+               .pm = pm_ptr(&bh1780_dev_pm_ops),
                .of_match_table = of_bh1780_match,
        },
 };