Driver core: show "initstate" of module

Show the initialization state(live, coming, going) of the module:
$ cat /sys/module/usbcore/initstate
live

Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by Kay Sievers and committed by Greg Kroah-Hartman 1f71740a aef6fba4

+25
+25
kernel/module.c
··· 824 824 } 825 825 #endif /* CONFIG_MODULE_UNLOAD */ 826 826 827 + static ssize_t show_initstate(struct module_attribute *mattr, 828 + struct module *mod, char *buffer) 829 + { 830 + const char *state = "unknown"; 831 + 832 + switch (mod->state) { 833 + case MODULE_STATE_LIVE: 834 + state = "live"; 835 + break; 836 + case MODULE_STATE_COMING: 837 + state = "coming"; 838 + break; 839 + case MODULE_STATE_GOING: 840 + state = "going"; 841 + break; 842 + } 843 + return sprintf(buffer, "%s\n", state); 844 + } 845 + 846 + static struct module_attribute initstate = { 847 + .attr = { .name = "initstate", .mode = 0444, .owner = THIS_MODULE }, 848 + .show = show_initstate, 849 + }; 850 + 827 851 static struct module_attribute *modinfo_attrs[] = { 828 852 &modinfo_version, 829 853 &modinfo_srcversion, 854 + &initstate, 830 855 #ifdef CONFIG_MODULE_UNLOAD 831 856 &refcnt, 832 857 #endif