From: <mar...@us...> - 2008-05-30 19:56:19
|
Revision: 580 http://openamt.svn.sourceforge.net/openamt/?rev=580&view=rev Author: marcin_obara Date: 2008-05-30 12:56:26 -0700 (Fri, 30 May 2008) Log Message: ----------- simplify module initialization API Modified Paths: -------------- heci/trunk/src/heci_main.c heci/trunk/src/heci_version.h Modified: heci/trunk/src/heci_main.c =================================================================== --- heci/trunk/src/heci_main.c 2008-05-27 17:19:49 UTC (rev 579) +++ heci/trunk/src/heci_main.c 2008-05-30 19:56:26 UTC (rev 580) @@ -221,65 +221,60 @@ /** * heci_sysfs_create - creates a struct class to contain heci info - * @owner: pointer to the module that is to "own" heci sysfs class - * @name: pointer to a string for the name of this class * - * @return valid pointer to a struct class on success, false - * pointer on failure + * @return 0 on success, <0 on failure. */ -static struct class *heci_sysfs_create(struct module *owner, char *name) +static int heci_sysfs_create(void) { struct class *class; int err = 0; - class = class_create(owner, name); + class = class_create(THIS_MODULE, HECI_DRIVER_NAME); if (IS_ERR(class)) { err = PTR_ERR(class); - goto error; + printk(KERN_ERR "heci: Error creating heci class.\n"); + goto err_out; } err = class_create_file(class, &class_attr_version); - if (err) - goto destroy_class; + if (err) { + class_destroy(class); + printk(KERN_ERR "heci: Error creating heci class file.\n"); + goto err_out; + } - return class; - -destroy_class: - class_destroy(class); -error: - return ERR_PTR(err); + heci_class = class; +err_out: + return err; } /** * heci_sysfs_destroy - destroys a struct class of heci info - * - * @cs: pointer to the struct class that is to be destroyed */ -static void heci_sysfs_destroy(struct class *class) +static void heci_sysfs_destroy(void) { - if ((class == NULL) || (IS_ERR(class))) + if ((heci_class == NULL) || (IS_ERR(heci_class))) return; - class_remove_file(class, &class_attr_version); - class_destroy(class); + class_remove_file(heci_class, &class_attr_version); + class_destroy(heci_class); } /** - * heci_sysfs_device_create - adds two devices to sysfs for chararcter devices - * @cs: pointer to the struct class that the device to be registered on + * heci_sysfs_device_create - adds device to sysfs for character devices * * @return 0 on success, <0 on failure. */ -static int heci_sysfs_device_create(struct class *cs) +static int heci_sysfs_device_create(void) { int err = 0; - if ((cs == NULL) || (IS_ERR(cs))) { + if ((heci_class == NULL) || (IS_ERR(heci_class))) { err = -EINVAL; goto err_out; } - heci_class_dev = class_device_create(cs, NULL, + heci_class_dev = class_device_create(heci_class, NULL, heci_cdev.dev, NULL, HECI_DEV_NAME); @@ -291,7 +286,7 @@ } /** - * heci_sysfs_device_remove - unregisters the two device entries on sysfs + * heci_sysfs_device_remove - unregisters the device entry on sysfs */ static void heci_sysfs_device_remove(void) { @@ -318,29 +313,32 @@ /* init pci module */ ret = pci_register_driver(&heci_driver); - if (ret < 0) + if (ret < 0) { + printk(KERN_ERR "heci: Error registering driver.\n"); goto end; + } /* registration of char devices */ ret = alloc_chrdev_region(&dev, HECI_MINORS_BASE, HECI_MINORS_COUNT, HECI_DRIVER_NAME); + if (ret) { + printk(KERN_ERR "heci: Error allocating char device region.\n"); + goto unregister_pci; + } heci_major = MAJOR(dev); - /* rgisteration in sysfs interface */ - heci_class = heci_sysfs_create(THIS_MODULE, HECI_DRIVER_NAME); - if (IS_ERR(heci_class)) { - printk(KERN_ERR "heci: Error creating heci class.\n"); - ret = PTR_ERR(heci_class); + /* registration in sysfs interface */ + ret = heci_sysfs_create(); + if (ret) goto unregister; - } ret = heci_registration_cdev(&heci_cdev, HECI_MINOR_NUMBER, &heci_fops); if (ret) goto destroy_sysfs; - if (heci_sysfs_device_create(heci_class)) { + if (heci_sysfs_device_create()) { cdev_del(&heci_cdev); ret = -EAGAIN; goto destroy_sysfs; @@ -349,12 +347,12 @@ return ret; destroy_sysfs: - heci_sysfs_destroy(heci_class); - + heci_sysfs_destroy(); unregister: - pci_unregister_driver(&heci_driver); unregister_chrdev_region(MKDEV(heci_major, HECI_MINORS_BASE), HECI_MINORS_COUNT); +unregister_pci: + pci_unregister_driver(&heci_driver); end: return ret; } @@ -374,7 +372,7 @@ /* Now unregister cdev. */ cdev_del(&heci_cdev); heci_sysfs_device_remove(); - heci_sysfs_destroy(heci_class); + heci_sysfs_destroy(); unregister_chrdev_region(MKDEV(heci_major, HECI_MINORS_BASE), HECI_MINORS_COUNT); } Modified: heci/trunk/src/heci_version.h =================================================================== --- heci/trunk/src/heci_version.h 2008-05-27 17:19:49 UTC (rev 579) +++ heci/trunk/src/heci_version.h 2008-05-30 19:56:26 UTC (rev 580) @@ -44,7 +44,7 @@ #define MAJOR_VERSION 5 #define MINOR_VERSION 0 #define QUICK_FIX_NUMBER 0 -#define VER_BUILD 19 +#define VER_BUILD 23 #define HECI_DRV_VER1 __stringify(MAJOR_VERSION) "." __stringify(MINOR_VERSION) #define HECI_DRV_VER2 __stringify(QUICK_FIX_NUMBER) "." __stringify(VER_BUILD) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |