]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/main.c
Ensure free of checked alloc memory in the case that module_init fails
[lincan.git] / lincan / src / main.c
index 02a8ef9f7880dcf0701a770c28ee2b8eb7393439..60eb6e6799c429a652dc0dcf73df9ea1167ed681 100644 (file)
@@ -4,10 +4,12 @@
  * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
  * email:pisa@cmp.felk.cvut.cz
  * This software is released under the GPL-License.
- * Version lincan-0.2  9 Jul 2003
+ * Version lincan-0.3  17 Jun 2004
  */
 
+#ifndef EXPORT_SYMTAB
 #define EXPORT_SYMTAB
+#endif
 
 #include <linux/autoconf.h>
 
@@ -61,8 +63,6 @@
 #include "../include/can_iortl.h"
 #endif /*CAN_WITH_RTL*/
 
-#define EXPORT_SYMTAB
-
 can_spinlock_t canuser_manipulation_lock;
 
 /* Module parameters, some must be supplied at module loading time */
@@ -128,7 +128,7 @@ MODULE_AUTHOR("Pavel Pisa <pisa@cmp.felk.cvut.cz>, Arnaud Westenberg");
 /* Global structures, used to describe the installed hardware. */
 struct canhardware_t canhardware;
 struct canhardware_t *hardware_p=&canhardware;
-struct chip_t *chips_p[MAX_TOT_CHIPS];
+struct canchip_t *chips_p[MAX_TOT_CHIPS];
 struct msgobj_t *objects_p[MAX_TOT_MSGOBJS];
 #ifdef CONFIG_DEVFS_FS
 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,60))
@@ -177,7 +177,7 @@ int init_module(void)
 {
        int res=0,i=0, j;
        struct candevice_t *candev;
-       struct chip_t *chip;
+       struct canchip_t *chip;
 
        if (parse_mod_parms())
                return -EINVAL;
@@ -195,7 +195,7 @@ int init_module(void)
        res=register_chrdev(major,DEVICE_NAME, &can_fops);
        if (res<0) {
                CANMSG("Error registering driver.\n");
-               return -ENODEV;
+               goto register_error;
        }
 
        #ifdef CAN_WITH_RTL
@@ -211,7 +211,7 @@ int init_module(void)
        for (i=0; i<hardware_p->nr_boards; i++) {
                candev=hardware_p->candevice[i];
                if (candev->hwspecops->request_io(candev)) 
-                       goto memory_error;
+                       goto request_io_error;
                candev->flags|=CANDEV_IO_RESERVED;
        }
 
@@ -247,7 +247,9 @@ int init_module(void)
 
 #ifdef CONFIG_DEVFS_FS
         {
+           #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,50))
                char dev_name[32];
+           #endif
                int dev_minor;
                for(i=0;i<MAX_TOT_MSGOBJS;i++) {
                        if(!objects_p[i]) continue;
@@ -277,6 +279,11 @@ int init_module(void)
                goto memory_error;
 
        reset_error: ;
+               CANMSG("Error resetting device.\n");
+               goto memory_error;
+
+       request_io_error: ;
+               CANMSG("Error to request IO resources for device.\n");
                goto memory_error;
 
        memory_error: ;
@@ -293,8 +300,12 @@ int init_module(void)
                        CANMSG("Error unloading CAN driver, error: %d\n",res);
                else
                        CANMSG("No CAN devices or driver setup error.\n");
-               return -ENODEV;
 
+       register_error:
+               if ( can_del_mem_list() ) 
+                       CANMSG("Error deallocating memory\n");
+
+               return -ENODEV;
 }
 
 void cleanup_module(void)