-#ifdef DEBUG_MEM
- DEBUGMSG("can_checked_malloc: allocated %d bytes at %p, mem_head=%p\n",
- (int)size, address_p, mem_head);
-#endif
-
- mem_new=(struct mem_addr *)kmalloc(sizeof(struct mem_addr),GFP_KERNEL);
- if (mem_new == NULL) {
- CANMSG("can_checked_malloc: memory list allocation error.\n");
- kfree(address_p);
- return NULL;
- }
- mem_new->next=mem_head;
- mem_new->address=address_p;
- mem_new->size=size;
- mem_head=mem_new;
-
- return address_p;
-}
-
-/**
- * can_checked_free - free memory allocated by can_checked_malloc()
- * @address_p: pointer to the memory block
- */
-int can_checked_free(void *address_p)
-{
- struct mem_addr **mem_pptr;
- struct mem_addr *mem_del=NULL;
-
-#ifdef DEBUG_MEM
- DEBUGMSG("can_checked_free %p, mem_head=%p\n", address_p, mem_head);
-#endif
-
- for(mem_pptr = &mem_head; (mem_del = *mem_pptr); mem_pptr = &mem_del->next) {
- if (mem_del->address != address_p)
- continue;
- *mem_pptr=mem_del->next;
- kfree(mem_del);
- kfree(address_p);
- return 0;
- }
-
- CANMSG("can_checked_free: address %p not found on the mem list\n", address_p);
-
- kfree(address_p);
- return -1;
-}
-
-
-/**
- * can_del_mem_list - check for stale memory allocations at driver finalization
- *
- * Checks, if there are still some memory blocks allocated and releases memory
- * occupied by such blocks back to the system
- */
-int can_del_mem_list(void)
-{
- struct mem_addr *mem;
-
-#ifdef DEBUG_MEM
- DEBUGMSG("can_del_mem_list, mem_head=%p\n", mem_head);
-#endif
- if(mem_head == NULL) {
- CANMSG("can_del_mem_list: no entries on the list - OK\n");
- return 0;
- }
-
- while((mem=mem_head) != NULL) {
- mem_head=mem->next;
- CANMSG("can_del_mem_list: deleting %p with size %d\n",
- mem->address, (int)mem->size);
- kfree(mem->address);
- kfree(mem);
- }
-
- return 0;
-}
-
-/**
- * can_request_io_region - request IO space region
- * @start: the first IO port address
- * @n: number of the consecutive IO port addresses
- * @name: name/label for the requested region
- *
- * The function hides system specific implementation of the feature.
- *
- * Return Value: returns positive value (1) in the case, that region could
- * be reserved for the driver. Returns zero (0) if there is collision with
- * other driver or region cannot be taken for some other reason.
- */
-int can_request_io_region(unsigned long start, unsigned long n, const char *name)
-{
- #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
- if(check_region(start,n)) return 0;
- request_region(start,n,name);
- return 1;
- #else
- return (request_region(start,n,name))?1:0;
- #endif
-}
-
-/**
- * can_release_io_region - release IO space region
- * @start: the first IO port address
- * @n: number of the consecutive IO port addresses
- */
-void can_release_io_region(unsigned long start, unsigned long n)
-{
- release_region(start,n);
-}
-
-/**
- * can_request_mem_region - request memory space region
- * @start: the first memory port physical address
- * @n: number of the consecutive memory port addresses
- * @name: name/label for the requested region
- *
- * The function hides system specific implementation of the feature.
- *
- * Return Value: returns positive value (1) in the case, that region could
- * be reserved for the driver. Returns zero (0) if there is collision with
- * other driver or region cannot be taken for some other reason.
- */
-int can_request_mem_region(unsigned long start, unsigned long n, const char *name)
-{
- #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
- return 1;
- #else
- return (request_mem_region(start,n,name))?1:0;
- #endif
-}
-
-/**
- * can_release_mem_region - release memory space region
- * @start: the first memory port physical address
- * @n: number of the consecutive memory port addresses
- */
-void can_release_mem_region(unsigned long start, unsigned long n)
-{
- #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
- return;
- #else
- release_mem_region(start,n);
- #endif
-}