// #include #include #include #include #include #include "main.h" #include "platform.h" // struct cdev *cdev; struct device *dev; struct class *class; dev_t node = 0; // do not register /dev/lork 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); goto free_class; } // create device (required for device attributes under /sys/class) dev = device_create(class, NULL, node, NULL, "lork"); if (IS_ERR_OR_NULL(dev)) { err = PTR_ERR(dev); goto free_device; } // create platform driver err = platform_driver_register(&lork_driver); if (err) goto free_platform_driver; // create driver attribute under /sys/bus/platform/drivers/gpio-extern err = driver_create_file(&lork_driver.driver, &drv_attr_int); if (err) goto free_drv_attr_int; // create device attributes under /sys/class err = device_create_file(dev, &dev_attr_int); if (err) goto free_dev_attr_int; err = device_create_file(dev, &dev_attr_str); if (err) goto free_dev_attr_str; printk("%s() OK\n", __PRETTY_FUNCTION__); return 0; free_dev_attr_str: device_remove_file(dev, &dev_attr_str); free_dev_attr_int: device_remove_file(dev, &dev_attr_int); free_drv_attr_int: driver_remove_file(&lork_driver.driver, &drv_attr_int); free_platform_driver: platform_driver_unregister(&lork_driver); free_device: device_destroy(class, node); free_class: class_destroy(class); printk("%s() -> %d\n", __PRETTY_FUNCTION__, err); return err; } static void mod_exit(void) { device_remove_file(dev, &dev_attr_str); device_remove_file(dev, &dev_attr_int); driver_remove_file(&lork_driver.driver, &drv_attr_int); platform_driver_unregister(&lork_driver); device_destroy(class, node); class_destroy(class); printk("%s()\n", __PRETTY_FUNCTION__); } module_init(mod_init); module_exit(mod_exit); MODULE_LICENSE("Dual MIT/GPL");