PM / wakeup: Unify device_init_wakeup() for PM_SLEEP and !PM_SLEEP
Subsystems (5)
PATCH 1/1 PM / wakeup: Unify device_init_wakeup() for PM_SLEEP and !PM_SLEEP
From: Bjorn Helgaas <[email protected]>
Previously the CONFIG_PM_SLEEP and !CONFIG_PM_SLEEP device_init_wakeup() implementations differed in confusing ways:
- The PM_SLEEP version checked for a NULL device pointer and returned -EINVAL, while the !PM_SLEEP version did not and would simply dereference a NULL pointer.
- When called with "false", the !PM_SLEEP version cleared "capable" and "enable" in the opposite order of the PM_SLEEP version. That was harmless because for !PM_SLEEP they're simple assignments, but it's unnecessary confusion.
Use a simplified version of the PM_SLEEP implementation for both cases.
--- drivers/base/power/wakeup.c | 30 ------------------------------ include/linux/pm_wakeup.h | 31 +++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 38 deletions(-)
drivers/base/power/wakeup.c +0 -30
@@ -500,36 +500,6 @@ void device_set_wakeup_capable(struct device *dev, bool capable) }EXPORT_SYMBOL_GPL (device_set_wakeup_capable); -/** -* device_init_wakeup - Device wakeup initialization. -* @dev: Device to handle. -* @enable: Whether or not to enable @dev as a wakeup device. -* -* By default, most devices should leave wakeup disabled. The exceptions are -* devices that everyone expects to be wakeup sources: keyboards, power buttons, -* possibly network interfaces, etc. Also, devices that don't generate their -* own wakeup requests but merely forward requests from one bus to another -* (like PCI bridges) should have wakeup enabled by default. -*/ -int device_init_wakeup (struct device *dev,bool enable) -{ -int ret =0 ; - -if (!dev) -return -EINVAL ; - -if (enable) { -device_set_wakeup_capable (dev, true); - ret =device_wakeup_enable (dev); - }else { -device_wakeup_disable (dev); -device_set_wakeup_capable (dev, false); - } - -return ret; -} -EXPORT_SYMBOL_GPL (device_init_wakeup); -/** * device_set_wakeup_enable - Enable or disable a device to wake up the system. * @dev: Device to handle.
include/linux/pm_wakeup.h +23 -8
@@ -109,7 +109,6 @@ extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws);extern int device_wakeup_enable (struct device *dev);extern int device_wakeup_disable (struct device *dev);extern void device_set_wakeup_capable (struct device *dev,bool capable); -extern int device_init_wakeup (struct device *dev,bool val);extern int device_set_wakeup_enable (struct device *dev,bool enable);extern void __pm_stay_awake (struct wakeup_source *ws);extern void pm_stay_awake (struct device *dev);
@@ -167,13 +166,6 @@ static inline int device_set_wakeup_enable(struct device *dev, bool enable)return 0 ; } -static inline int device_init_wakeup (struct device *dev,bool val) -{ -device_set_wakeup_capable (dev, val); -device_set_wakeup_enable (dev, val); -return 0 ; -} -static inline bool device_may_wakeup (struct device *dev) {return dev->power.can_wakeup && dev->power.should_wakeup;
@@ -217,4 +209,27 @@ static inline void pm_wakeup_hard_event(struct device *dev) return pm_wakeup_dev_event(dev, 0, true); } +/** +* device_init_wakeup - Device wakeup initialization. +* @dev: Device to handle. +* @enable: Whether or not to enable @dev as a wakeup device. +* +* By default, most devices should leave wakeup disabled. The exceptions are +* devices that everyone expects to be wakeup sources: keyboards, power buttons, +* possibly network interfaces, etc. Also, devices that don't generate their +* own wakeup requests but merely forward requests from one bus to another +* (like PCI bridges) should have wakeup enabled by default. +*/ +static inline int device_init_wakeup (struct device *dev,bool enable) +{ +if (enable) { +device_set_wakeup_capable (dev, true); +return device_wakeup_enable (dev); + }else { +device_wakeup_disable (dev); +device_set_wakeup_capable (dev, false); +return 0 ; + } +} +#endif /* _LINUX_PM_WAKEUP_H */
Signature · 1 line
2.25.1
Greg Kroah-Hartman
maintainerQuoted 106 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Previously the
CONFIG_PM_SLEEPand !CONFIG_PM_SLEEPdevice_init_wakeup()implementations differed in confusing ways:- The
PM_SLEEPversion checked for a NULL device pointer and returned-EINVAL, while the !PM_SLEEP version did not and would simply dereference a NULL pointer.- When called with "false", the !PM_SLEEP version cleared "capable" and "enable" in the opposite order of the
PM_SLEEPversion. That was harmless because for !PM_SLEEP they're simple assignments, but it's unnecessary confusion.Use a simplified version of the
PM_SLEEPimplementation for both cases.Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/base/power/wakeup.c | 30 ------------------------------ include/linux/pm_wakeup.h | 31 +++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 38 deletions(-)drivers/base/power/wakeup.c +0
-30@@ -500,36 +500,6 @@ void device_set_wakeup_capable(struct device *dev, bool capable) }EXPORT_SYMBOL_GPL (device_set_wakeup_capable); -/** -* device_init_wakeup - Device wakeup initialization. -* @dev: Device to handle. -* @enable: Whether or not to enable @dev as a wakeup device. -* -* By default, most devices should leave wakeup disabled. The exceptions are -* devices that everyone expects to be wakeup sources: keyboards, power buttons, -* possibly network interfaces, etc. Also, devices that don't generate their -* own wakeup requests but merely forward requests from one bus to another -* (like PCI bridges) should have wakeup enabled by default. -*/ -int device_init_wakeup (struct device *dev,bool enable) -{ -int ret =0 ; - -if (!dev) -return -EINVAL ; - -if (enable) { -device_set_wakeup_capable (dev, true); - ret =device_wakeup_enable (dev); - }else { -device_wakeup_disable (dev); -device_set_wakeup_capable (dev, false); - } - -return ret; -} -EXPORT_SYMBOL_GPL (device_init_wakeup); -/** * device_set_wakeup_enable - Enable or disable a device to wake up the system. * @dev: Device to handle. include/linux/pm_wakeup.h +13
-8@@ -109,7 +109,6 @@ extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws);extern int device_wakeup_enable (struct device *dev);extern int device_wakeup_disable (struct device *dev);extern void device_set_wakeup_capable (struct device *dev,bool capable); -extern int device_init_wakeup (struct device *dev,bool val);extern int device_set_wakeup_enable (struct device *dev,bool enable);extern void __pm_stay_awake (struct wakeup_source *ws);extern void pm_stay_awake (struct device *dev);@@ -167,13 +166,6 @@ static inline int device_set_wakeup_enable(struct device *dev, bool enable)return 0 ; } -static inline int device_init_wakeup (struct device *dev,bool val) -{ -device_set_wakeup_capable (dev, val); -device_set_wakeup_enable (dev, val); -return 0 ; -} -static inline bool device_may_wakeup (struct device *dev) {return dev->power.can_wakeup && dev->power.should_wakeup;@@ -217,4 +209,27 @@ static inline void pm_wakeup_hard_event(struct device *dev)return pm_wakeup_dev_event (dev,0 , true); } +/** +* device_init_wakeup - Device wakeup initialization. +* @dev: Device to handle. +* @enable: Whether or not to enable @dev as a wakeup device. +* +* By default, most devices should leave wakeup disabled. The exceptions are +* devices that everyone expects to be wakeup sources: keyboards, power buttons, +* possibly network interfaces, etc. Also, devices that don't generate their +* own wakeup requests but merely forward requests from one bus to another +* (like PCI bridges) should have wakeup enabled by default. +*/ +static inline int device_init_wakeup (struct device *dev,bool enable) +{
include/linux/pm_wakeup.h static inline void pm_wakeup_hard_event(struct device *dev) · line 234
Quoted 10 lines
include/linux/pm_wakeup.h +10
-0+if (enable) { +device_set_wakeup_capable (dev, true); +return device_wakeup_enable (dev); + }else { +device_wakeup_disable (dev); +device_set_wakeup_capable (dev, false); +return 0 ; + } +} +
Why are you moving this to be inline? Why not just drop the "other" version and stick with the .c version?
thanks,
greg k-h
Quoted 112 lines · Greg Kroah-Hartman
Quoted 111 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Previously the
CONFIG_PM_SLEEPand !CONFIG_PM_SLEEPdevice_init_wakeup()implementations differed in confusing ways:- The
PM_SLEEPversion checked for a NULL device pointer and returned-EINVAL, while the !PM_SLEEP version did not and would simply dereference a NULL pointer.- When called with "false", the !PM_SLEEP version cleared "capable" and "enable" in the opposite order of the
PM_SLEEPversion. That was harmless because for !PM_SLEEP they're simple assignments, but it's unnecessary confusion.Use a simplified version of the
PM_SLEEPimplementation for both cases.Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/base/power/wakeup.c | 30 ------------------------------ include/linux/pm_wakeup.h | 31 +++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 38 deletions(-)drivers/base/power/wakeup.c +0
-30@@ -500,36 +500,6 @@ void device_set_wakeup_capable(struct device *dev, bool capable) }EXPORT_SYMBOL_GPL (device_set_wakeup_capable); -/** -* device_init_wakeup - Device wakeup initialization. -* @dev: Device to handle. -* @enable: Whether or not to enable @dev as a wakeup device. -* -* By default, most devices should leave wakeup disabled. The exceptions are -* devices that everyone expects to be wakeup sources: keyboards, power buttons, -* possibly network interfaces, etc. Also, devices that don't generate their -* own wakeup requests but merely forward requests from one bus to another -* (like PCI bridges) should have wakeup enabled by default. -*/ -int device_init_wakeup (struct device *dev,bool enable) -{ -int ret =0 ; - -if (!dev) -return -EINVAL ; - -if (enable) { -device_set_wakeup_capable (dev, true); - ret =device_wakeup_enable (dev); - }else { -device_wakeup_disable (dev); -device_set_wakeup_capable (dev, false); - } - -return ret; -} -EXPORT_SYMBOL_GPL (device_init_wakeup); -/** * device_set_wakeup_enable - Enable or disable a device to wake up the system. * @dev: Device to handle. include/linux/pm_wakeup.h +18
-8@@ -109,7 +109,6 @@ extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws);extern int device_wakeup_enable (struct device *dev);extern int device_wakeup_disable (struct device *dev);extern void device_set_wakeup_capable (struct device *dev,bool capable); -extern int device_init_wakeup (struct device *dev,bool val);extern int device_set_wakeup_enable (struct device *dev,bool enable);extern void __pm_stay_awake (struct wakeup_source *ws);extern void pm_stay_awake (struct device *dev);@@ -167,13 +166,6 @@ static inline int device_set_wakeup_enable(struct device *dev, bool enable)return 0 ; } -static inline int device_init_wakeup (struct device *dev,bool val) -{ -device_set_wakeup_capable (dev, val); -device_set_wakeup_enable (dev, val); -return 0 ; -} -static inline bool device_may_wakeup (struct device *dev) {return dev->power.can_wakeup && dev->power.should_wakeup;@@ -217,4 +209,27 @@ static inline void pm_wakeup_hard_event(struct device *dev)return pm_wakeup_dev_event (dev,0 , true); } +/** +* device_init_wakeup - Device wakeup initialization. +* @dev: Device to handle. +* @enable: Whether or not to enable @dev as a wakeup device. +* +* By default, most devices should leave wakeup disabled. The exceptions are +* devices that everyone expects to be wakeup sources: keyboards, power buttons, +* possibly network interfaces, etc. Also, devices that don't generate their +* own wakeup requests but merely forward requests from one bus to another +* (like PCI bridges) should have wakeup enabled by default. +*/ +static inline int device_init_wakeup (struct device *dev,bool enable) +{ +if (enable) { +device_set_wakeup_capable (dev, true); +return device_wakeup_enable (dev); + }else { +device_wakeup_disable (dev);
Quoted 8 lines
include/linux/pm_wakeup.h static inline void pm_wakeup_hard_event(struct device *dev) · line 234
Quoted 5 lines
include/linux/pm_wakeup.h +5
-0+device_set_wakeup_capable (dev, false); +return 0 ; + } +} +Why are you moving this to be inline? Why not just drop the "other" version and stick with the .c version?
That would definitely be simpler but drivers/base/power/wakeup.c is only built when CONFIG_PM_SLEEP=y, so a .c version there by itself isn't sufficient. I should have mentioned that in the commit log.
Bjorn
Greg Kroah-Hartman
maintainerQuoted 122 lines · Bjorn Helgaas
Quoted 112 lines · Greg Kroah-Hartman
Quoted 111 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Previously the
CONFIG_PM_SLEEPand !CONFIG_PM_SLEEPdevice_init_wakeup()implementations differed in confusing ways:- The
PM_SLEEPversion checked for a NULL device pointer and returned-EINVAL, while the !PM_SLEEP version did not and would simply dereference a NULL pointer.- When called with "false", the !PM_SLEEP version cleared "capable" and "enable" in the opposite order of the
PM_SLEEPversion. That was harmless because for !PM_SLEEP they're simple assignments, but it's unnecessary confusion.Use a simplified version of the
PM_SLEEPimplementation for both cases.Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/base/power/wakeup.c | 30 ------------------------------ include/linux/pm_wakeup.h | 31 +++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 38 deletions(-)drivers/base/power/wakeup.c +0
-30@@ -500,36 +500,6 @@ void device_set_wakeup_capable(struct device *dev, bool capable) }EXPORT_SYMBOL_GPL (device_set_wakeup_capable); -/** -* device_init_wakeup - Device wakeup initialization. -* @dev: Device to handle. -* @enable: Whether or not to enable @dev as a wakeup device. -* -* By default, most devices should leave wakeup disabled. The exceptions are -* devices that everyone expects to be wakeup sources: keyboards, power buttons, -* possibly network interfaces, etc. Also, devices that don't generate their -* own wakeup requests but merely forward requests from one bus to another -* (like PCI bridges) should have wakeup enabled by default. -*/ -int device_init_wakeup (struct device *dev,bool enable) -{ -int ret =0 ; - -if (!dev) -return -EINVAL ; - -if (enable) { -device_set_wakeup_capable (dev, true); - ret =device_wakeup_enable (dev); - }else { -device_wakeup_disable (dev); -device_set_wakeup_capable (dev, false); - } - -return ret; -} -EXPORT_SYMBOL_GPL (device_init_wakeup); -/** * device_set_wakeup_enable - Enable or disable a device to wake up the system. * @dev: Device to handle. include/linux/pm_wakeup.h +18
-8@@ -109,7 +109,6 @@ extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws);extern int device_wakeup_enable (struct device *dev);extern int device_wakeup_disable (struct device *dev);extern void device_set_wakeup_capable (struct device *dev,bool capable); -extern int device_init_wakeup (struct device *dev,bool val);extern int device_set_wakeup_enable (struct device *dev,bool enable);extern void __pm_stay_awake (struct wakeup_source *ws);extern void pm_stay_awake (struct device *dev);@@ -167,13 +166,6 @@ static inline int device_set_wakeup_enable(struct device *dev, bool enable)return 0 ; } -static inline int device_init_wakeup (struct device *dev,bool val) -{ -device_set_wakeup_capable (dev, val); -device_set_wakeup_enable (dev, val); -return 0 ; -} -static inline bool device_may_wakeup (struct device *dev) {return dev->power.can_wakeup && dev->power.should_wakeup;@@ -217,4 +209,27 @@ static inline void pm_wakeup_hard_event(struct device *dev)return pm_wakeup_dev_event (dev,0 , true); } +/** +* device_init_wakeup - Device wakeup initialization. +* @dev: Device to handle. +* @enable: Whether or not to enable @dev as a wakeup device. +* +* By default, most devices should leave wakeup disabled. The exceptions are +* devices that everyone expects to be wakeup sources: keyboards, power buttons, +* possibly network interfaces, etc. Also, devices that don't generate their +* own wakeup requests but merely forward requests from one bus to another +* (like PCI bridges) should have wakeup enabled by default. +*/ +static inline int device_init_wakeup (struct device *dev,bool enable) +{ +if (enable) { +device_set_wakeup_capable (dev, true); +return device_wakeup_enable (dev); + }else { +device_wakeup_disable (dev);Quoted 8 lines
include/linux/pm_wakeup.h static inline void pm_wakeup_hard_event(struct device *dev) · line 234
Quoted 5 lines
include/linux/pm_wakeup.h +5
-0+device_set_wakeup_capable (dev, false); +return 0 ; + } +} +Why are you moving this to be inline? Why not just drop the "other" version and stick with the .c version?
Quoted 3 lines
That would definitely be simpler but
drivers/base/power/wakeup.cis only built whenCONFIG_PM_SLEEP=y, so a .c version there by itself isn't sufficient. I should have mentioned that in the commit log.
Ah, missed that, sorry, nevermind :)
Quoted 109 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Previously the
CONFIG_PM_SLEEPand !CONFIG_PM_SLEEPdevice_init_wakeup()implementations differed in confusing ways:- The
PM_SLEEPversion checked for a NULL device pointer and returned-EINVAL, while the !PM_SLEEP version did not and would simply dereference a NULL pointer.- When called with "false", the !PM_SLEEP version cleared "capable" and "enable" in the opposite order of the
PM_SLEEPversion. That was harmless because for !PM_SLEEP they're simple assignments, but it's unnecessary confusion.Use a simplified version of the
PM_SLEEPimplementation for both cases.Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/base/power/wakeup.c | 30 ------------------------------ include/linux/pm_wakeup.h | 31 +++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 38 deletions(-)drivers/base/power/wakeup.c +0
-30@@ -500,36 +500,6 @@ void device_set_wakeup_capable(struct device *dev, bool capable) }EXPORT_SYMBOL_GPL (device_set_wakeup_capable); -/** -* device_init_wakeup - Device wakeup initialization. -* @dev: Device to handle. -* @enable: Whether or not to enable @dev as a wakeup device. -* -* By default, most devices should leave wakeup disabled. The exceptions are -* devices that everyone expects to be wakeup sources: keyboards, power buttons, -* possibly network interfaces, etc. Also, devices that don't generate their -* own wakeup requests but merely forward requests from one bus to another -* (like PCI bridges) should have wakeup enabled by default. -*/ -int device_init_wakeup (struct device *dev,bool enable) -{ -int ret =0 ; - -if (!dev) -return -EINVAL ; - -if (enable) { -device_set_wakeup_capable (dev, true); - ret =device_wakeup_enable (dev); - }else { -device_wakeup_disable (dev); -device_set_wakeup_capable (dev, false); - } - -return ret; -} -EXPORT_SYMBOL_GPL (device_init_wakeup); -/** * device_set_wakeup_enable - Enable or disable a device to wake up the system. * @dev: Device to handle. include/linux/pm_wakeup.h +15
-8@@ -109,7 +109,6 @@ extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws);extern int device_wakeup_enable (struct device *dev);extern int device_wakeup_disable (struct device *dev);extern void device_set_wakeup_capable (struct device *dev,bool capable); -extern int device_init_wakeup (struct device *dev,bool val);extern int device_set_wakeup_enable (struct device *dev,bool enable);extern void __pm_stay_awake (struct wakeup_source *ws);extern void pm_stay_awake (struct device *dev);@@ -167,13 +166,6 @@ static inline int device_set_wakeup_enable(struct device *dev, bool enable)return 0 ; } -static inline int device_init_wakeup (struct device *dev,bool val) -{ -device_set_wakeup_capable (dev, val); -device_set_wakeup_enable (dev, val); -return 0 ; -} -static inline bool device_may_wakeup (struct device *dev) {return dev->power.can_wakeup && dev->power.should_wakeup;@@ -217,4 +209,27 @@ static inline void pm_wakeup_hard_event(struct device *dev)return pm_wakeup_dev_event (dev,0 , true); } +/** +* device_init_wakeup - Device wakeup initialization. +* @dev: Device to handle. +* @enable: Whether or not to enable @dev as a wakeup device. +* +* By default, most devices should leave wakeup disabled. The exceptions are +* devices that everyone expects to be wakeup sources: keyboards, power buttons, +* possibly network interfaces, etc. Also, devices that don't generate their +* own wakeup requests but merely forward requests from one bus to another +* (like PCI bridges) should have wakeup enabled by default. +*/ +static inline int device_init_wakeup (struct device *dev,bool enable) +{ +if (enable) { +device_set_wakeup_capable (dev, true);
include/linux/pm_wakeup.h static inline void pm_wakeup_hard_event(struct device *dev)
Quoted 10 lines
include/linux/pm_wakeup.h +8
-1+ return device_wakeup_enable(dev); + }else { +device_wakeup_disable (dev); +device_set_wakeup_capable (dev, false); +return 0 ; + } +} +#endif /* _LINUX_PM_WAKEUP_H */ --
Applied as 5.20 material, sorry for the delay.
Thanks!