~ubuntu-branches/ubuntu/oneiric/oss4/oneiric-proposed

« back to all changes in this revision

Viewing changes to kernel/framework/osscore/oss_memblk.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2011-06-16 20:37:48 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110616203748-jbrxik6ql33z54co
Tags: 4.2-build2004-1ubuntu1
* Merge from Debian unstable.
  - Supports our current kernel (LP: #746048)
  Remaining changes:
  - debian/oss4-dkms.dkms.in: s/source/build/ in Kernel headers paths.
* ld-as-needed.patch: Re-order CC arguments to enable building with ld
  --as-needed (LP: #770972)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Purpose: OSS memory block allocation and management routines.
 
3
 */
 
4
/*
 
5
 *
 
6
 * This file is part of Open Sound System.
 
7
 *
 
8
 * Copyright (C) 4Front Technologies 1996-2008.
 
9
 *
 
10
 * This this source file is released under GPL v2 license (no other versions).
 
11
 * See the COPYING file included in the main directory of this source
 
12
 * distribution for the license terms and conditions.
 
13
 *
 
14
 */
 
15
 
 
16
#include <oss_config.h>
 
17
 
 
18
struct _oss_memblk_t
 
19
{
 
20
        oss_memblk_t *next;
 
21
        void *addr;
 
22
};
 
23
 
 
24
oss_memblk_t *oss_global_memblk=NULL;
 
25
 
 
26
void
 
27
*oss_memblk_malloc(oss_memblk_t **blk, int size)
 
28
{
 
29
        oss_memblk_t *newblk;
 
30
 
 
31
        newblk = KERNEL_MALLOC (sizeof(oss_memblk_t) + size);
 
32
 
 
33
        newblk->addr = newblk +1;
 
34
        newblk->next = NULL;
 
35
 
 
36
        if (*blk == NULL)
 
37
           {
 
38
                /*
 
39
                 * No earlier memory blocks in the chain.
 
40
                 */
 
41
                *blk = newblk;
 
42
                return newblk->addr;
 
43
           }
 
44
 
 
45
/*
 
46
 * Add this block to the chain.
 
47
 */
 
48
        newblk->next = *blk;
 
49
        *blk = newblk;
 
50
 
 
51
        return newblk->addr;
 
52
}
 
53
 
 
54
void
 
55
oss_memblk_free(oss_memblk_t **blk, void *addr)
 
56
{
 
57
        oss_memblk_t *this_one = *blk, *prev = NULL;
 
58
 
 
59
        while (this_one != NULL)
 
60
        {
 
61
                if (this_one->addr == addr)
 
62
                   {
 
63
                           if (prev == NULL) /* First one in the chain */
 
64
                              {
 
65
                                      *blk = this_one->next;
 
66
                                      KERNEL_FREE (this_one);
 
67
                              }
 
68
                           else
 
69
                              {
 
70
                                      prev->next = this_one->next;
 
71
                                      KERNEL_FREE (this_one);
 
72
                              }
 
73
 
 
74
                           return;
 
75
                   }
 
76
 
 
77
                this_one = this_one->next;
 
78
        }
 
79
}
 
80
 
 
81
void
 
82
oss_memblk_unalloc(oss_memblk_t **blk)
 
83
{
 
84
/*
 
85
 * Free all memory allocations on the chain.
 
86
 */
 
87
        oss_memblk_t *this_one = *blk;
 
88
 
 
89
   while (this_one != NULL)
 
90
   {
 
91
           oss_memblk_t *next_one;
 
92
 
 
93
           next_one = this_one->next;
 
94
 
 
95
           KERNEL_FREE(this_one);
 
96
           this_one = next_one;
 
97
   }
 
98
 
 
99
   *blk = NULL;
 
100
}