#include #include #include #include #include "main.h" #include "platform.h" struct class* class; static int mod_init(void) { int err; // create /sys/class/lork class = class_create("lork"); if (IS_ERR_OR_NULL(class)) { err = PTR_ERR(class); printk(KERN_ERR "class_create error %d\n", err); goto free_class; } // create platform driver err = platform_driver_register(&lork_driver); if (err) goto return_err; // create attribute under /sys/bus/platform/drivers/gpio-extern err = driver_create_file(&lork_driver.driver, &attr); if (err) goto return_err; printk("%s() OK\n", __PRETTY_FUNCTION__); return 0; return_err: free_class: class_destroy(class); printk("%s() -> %d\n", __PRETTY_FUNCTION__, err); return err; } static void mod_exit(void) { driver_remove_file(&lork_driver.driver, &attr); platform_driver_unregister(&lork_driver); class_destroy(class); printk("%s()\n", __PRETTY_FUNCTION__); } module_init(mod_init); module_exit(mod_exit); MODULE_LICENSE("Dual MIT/GPL");