Skip to content

Commit b317268

Browse files
joehattorirafaeljw
authored andcommitted
PM: wakeup: implement devm_device_init_wakeup() helper
Some drivers that enable device wakeup fail to properly disable it during their cleanup, which results in a memory leak. To address this, introduce devm_device_init_wakeup(), a managed variant of device_init_wakeup(dev, true). With this managed helper, wakeup functionality will be automatically disabled when the device is released, ensuring a more reliable cleanup process. This need for this addition arose during a previous discussion [1]. Link: https://lore.kernel.org/linux-rtc/20241212100403.3799667-1-joe@pf.is.s.u-tokyo.ac.jp/ [1] Suggested-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> Link: https://patch.msgid.link/20241218040935.1921416-1-joe@pf.is.s.u-tokyo.ac.jp Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent cb75952 commit b317268

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

include/linux/pm_wakeup.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,21 @@ static inline int device_init_wakeup(struct device *dev, bool enable)
240240
return 0;
241241
}
242242

243+
static void device_disable_wakeup(void *dev)
244+
{
245+
device_init_wakeup(dev, false);
246+
}
247+
248+
/**
249+
* devm_device_init_wakeup - Resource managed device wakeup initialization.
250+
* @dev: Device to handle.
251+
*
252+
* This function is the devm managed version of device_init_wakeup(dev, true).
253+
*/
254+
static inline int devm_device_init_wakeup(struct device *dev)
255+
{
256+
device_init_wakeup(dev, true);
257+
return devm_add_action_or_reset(dev, device_disable_wakeup, dev);
258+
}
259+
243260
#endif /* _LINUX_PM_WAKEUP_H */

0 commit comments

Comments
 (0)