mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	kernel/reboot.c: add devm_register_reboot_notifier()
Add devm_* wrapper around register_reboot_notifier to simplify device specific reboot notifier registration/unregistration. [akpm@linux-foundation.org: move `struct device' forward decl to top-of-file] Link: http://lkml.kernel.org/r/20170320171753.1705-1-andrew.smirnov@gmail.com Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									c512ac01d8
								
							
						
					
					
						commit
						2d8364bae4
					
				
					 2 changed files with 31 additions and 0 deletions
				
			
		| 
						 | 
					@ -6,6 +6,8 @@
 | 
				
			||||||
#include <linux/notifier.h>
 | 
					#include <linux/notifier.h>
 | 
				
			||||||
#include <uapi/linux/reboot.h>
 | 
					#include <uapi/linux/reboot.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct device;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SYS_DOWN	0x0001	/* Notify of system down */
 | 
					#define SYS_DOWN	0x0001	/* Notify of system down */
 | 
				
			||||||
#define SYS_RESTART	SYS_DOWN
 | 
					#define SYS_RESTART	SYS_DOWN
 | 
				
			||||||
#define SYS_HALT	0x0002	/* Notify of system halt */
 | 
					#define SYS_HALT	0x0002	/* Notify of system halt */
 | 
				
			||||||
| 
						 | 
					@ -39,6 +41,8 @@ extern int reboot_force;
 | 
				
			||||||
extern int register_reboot_notifier(struct notifier_block *);
 | 
					extern int register_reboot_notifier(struct notifier_block *);
 | 
				
			||||||
extern int unregister_reboot_notifier(struct notifier_block *);
 | 
					extern int unregister_reboot_notifier(struct notifier_block *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int devm_register_reboot_notifier(struct device *, struct notifier_block *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern int register_restart_handler(struct notifier_block *);
 | 
					extern int register_restart_handler(struct notifier_block *);
 | 
				
			||||||
extern int unregister_restart_handler(struct notifier_block *);
 | 
					extern int unregister_restart_handler(struct notifier_block *);
 | 
				
			||||||
extern void do_kernel_restart(char *cmd);
 | 
					extern void do_kernel_restart(char *cmd);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -104,6 +104,33 @@ int unregister_reboot_notifier(struct notifier_block *nb)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL(unregister_reboot_notifier);
 | 
					EXPORT_SYMBOL(unregister_reboot_notifier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void devm_unregister_reboot_notifier(struct device *dev, void *res)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						WARN_ON(unregister_reboot_notifier(*(struct notifier_block **)res));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int devm_register_reboot_notifier(struct device *dev, struct notifier_block *nb)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct notifier_block **rcnb;
 | 
				
			||||||
 | 
						int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rcnb = devres_alloc(devm_unregister_reboot_notifier,
 | 
				
			||||||
 | 
								    sizeof(*rcnb), GFP_KERNEL);
 | 
				
			||||||
 | 
						if (!rcnb)
 | 
				
			||||||
 | 
							return -ENOMEM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = register_reboot_notifier(nb);
 | 
				
			||||||
 | 
						if (!ret) {
 | 
				
			||||||
 | 
							*rcnb = nb;
 | 
				
			||||||
 | 
							devres_add(dev, rcnb);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							devres_free(rcnb);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL(devm_register_reboot_notifier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 *	Notifier list for kernel code which wants to be called
 | 
					 *	Notifier list for kernel code which wants to be called
 | 
				
			||||||
 *	to restart the system.
 | 
					 *	to restart the system.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue