1 | #ifndef __SOUND_SNDMAGIC_H
|
---|
2 | #define __SOUND_SNDMAGIC_H
|
---|
3 |
|
---|
4 | /*
|
---|
5 | * Magic allocation, deallocation, check
|
---|
6 | * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * This program is free software; you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation; either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * This program is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with this program; if not, write to the Free Software
|
---|
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
22 | *
|
---|
23 | */
|
---|
24 |
|
---|
25 |
|
---|
26 | #ifdef CONFIG_SND_DEBUG_MEMORY
|
---|
27 |
|
---|
28 | void *_snd_magic_kcalloc(unsigned long magic, size_t size, int flags);
|
---|
29 | void *_snd_magic_kmalloc(unsigned long magic, size_t size, int flags);
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * snd_magic_kmalloc - allocate a record with a magic-prefix
|
---|
33 | * @type: the type to allocate a record (like xxx_t)
|
---|
34 | * @extra: the extra size to allocate in bytes
|
---|
35 | * @flags: the allocation condition (GFP_XXX)
|
---|
36 | *
|
---|
37 | * Allocates a record of the given type with the extra space and
|
---|
38 | * returns its pointer. The allocated record has a secret magic-key
|
---|
39 | * to be checked via snd_magic_cast() for safe casts.
|
---|
40 | *
|
---|
41 | * The allocated pointer must be released via snd_magic_kfree().
|
---|
42 | *
|
---|
43 | * The "struct xxx" style cannot be used as the type argument
|
---|
44 | * because the magic-key constant is generated from the type-name
|
---|
45 | * string.
|
---|
46 | */
|
---|
47 | #define snd_magic_kmalloc(type, extra, flags) \
|
---|
48 | (type *) _snd_magic_kmalloc(type##_magic, sizeof(type) + extra, flags)
|
---|
49 | /**
|
---|
50 | * snd_magic_kcalloc - allocate a record with a magic-prefix and initialize
|
---|
51 | * @type: the type to allocate a record (like xxx_t)
|
---|
52 | * @extra: the extra size to allocate in bytes
|
---|
53 | * @flags: the allocation condition (GFP_XXX)
|
---|
54 | *
|
---|
55 | * Works like snd_magic_kmalloc() but this clears the area with zero
|
---|
56 | * automatically.
|
---|
57 | */
|
---|
58 | #define snd_magic_kcalloc(type, extra, flags) \
|
---|
59 | (type *) _snd_magic_kcalloc(type##_magic, sizeof(type) + extra, flags)
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * snd_magic_kfree - release the allocated area
|
---|
63 | * @ptr: the pointer allocated via snd_magic_kmalloc() or snd_magic_kcalloc()
|
---|
64 | *
|
---|
65 | * Releases the memory area allocated via snd_magic_kmalloc() or
|
---|
66 | * snd_magic_kcalloc() function.
|
---|
67 | */
|
---|
68 | void snd_magic_kfree(void *ptr);
|
---|
69 |
|
---|
70 | static inline unsigned long _snd_magic_value(void *obj)
|
---|
71 | {
|
---|
72 | return obj == NULL ? (unsigned long)-1 : *(((unsigned long *)obj) - 1);
|
---|
73 | }
|
---|
74 |
|
---|
75 | static inline int _snd_magic_bad(void *obj, unsigned long magic)
|
---|
76 | {
|
---|
77 | return _snd_magic_value(obj) != magic;
|
---|
78 | }
|
---|
79 |
|
---|
80 | #define snd_magic_cast1(t, expr, cmd) snd_magic_cast(t, expr, cmd)
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * snd_magic_cast - check and cast the magic-allocated pointer
|
---|
84 | * @type: the type of record to cast
|
---|
85 | * @ptr: the magic-allocated pointer
|
---|
86 | * @action...: the action to do if failed
|
---|
87 | *
|
---|
88 | * This macro provides a safe cast for the given type, which was
|
---|
89 | * allocated via snd_magic_kmalloc() or snd_magic_kcallc().
|
---|
90 | * If the pointer is invalid, i.e. the cast-type doesn't match,
|
---|
91 | * the action arguments are called with a debug message.
|
---|
92 | */
|
---|
93 | #define snd_magic_cast(type, ptr, action...) \
|
---|
94 | (type *) ({\
|
---|
95 | void *__ptr = ptr;\
|
---|
96 | unsigned long __magic = _snd_magic_value(__ptr);\
|
---|
97 | if (__magic != type##_magic) {\
|
---|
98 | snd_printk("bad MAGIC (0x%lx)\n", __magic);\
|
---|
99 | action;\
|
---|
100 | }\
|
---|
101 | __ptr;\
|
---|
102 | })
|
---|
103 |
|
---|
104 | #define snd_device_t_magic 0xa15a00ff
|
---|
105 | #define snd_pcm_t_magic 0xa15a0101
|
---|
106 | #define snd_pcm_file_t_magic 0xa15a0102
|
---|
107 | #define snd_pcm_substream_t_magic 0xa15a0103
|
---|
108 | #define snd_pcm_proc_private_t_magic 0xa15a0104
|
---|
109 | #define snd_pcm_oss_file_t_magic 0xa15a0105
|
---|
110 | #define snd_mixer_oss_t_magic 0xa15a0106
|
---|
111 | // #define snd_pcm_sgbuf_t_magic 0xa15a0107
|
---|
112 |
|
---|
113 | #define snd_info_private_data_t_magic 0xa15a0201
|
---|
114 | #define snd_info_entry_t_magic 0xa15a0202
|
---|
115 | #define snd_ctl_file_t_magic 0xa15a0301
|
---|
116 | #define snd_kcontrol_t_magic 0xa15a0302
|
---|
117 | #define snd_rawmidi_t_magic 0xa15a0401
|
---|
118 | #define snd_rawmidi_file_t_magic 0xa15a0402
|
---|
119 | #define snd_virmidi_t_magic 0xa15a0403
|
---|
120 | #define snd_virmidi_dev_t_magic 0xa15a0404
|
---|
121 | #define snd_timer_t_magic 0xa15a0501
|
---|
122 | #define snd_timer_user_t_magic 0xa15a0502
|
---|
123 | #define snd_hwdep_t_magic 0xa15a0601
|
---|
124 | #define snd_seq_device_t_magic 0xa15a0701
|
---|
125 |
|
---|
126 | #define es18xx_t_magic 0xa15a1101
|
---|
127 | #define trident_t_magic 0xa15a1201
|
---|
128 | #define es1938_t_magic 0xa15a1301
|
---|
129 | #define cs46xx_t_magic 0xa15a1401
|
---|
130 | #define cs46xx_pcm_t_magic 0xa15a1402
|
---|
131 | #define ensoniq_t_magic 0xa15a1501
|
---|
132 | #define sonicvibes_t_magic 0xa15a1601
|
---|
133 | #define mpu401_t_magic 0xa15a1701
|
---|
134 | #define fm801_t_magic 0xa15a1801
|
---|
135 | #define ac97_t_magic 0xa15a1901
|
---|
136 | #define ac97_bus_t_magic 0xa15a1902
|
---|
137 | #define ak4531_t_magic 0xa15a1a01
|
---|
138 | #define snd_uart16550_t_magic 0xa15a1b01
|
---|
139 | #define emu10k1_t_magic 0xa15a1c01
|
---|
140 | #define emu10k1_pcm_t_magic 0xa15a1c02
|
---|
141 | #define emu10k1_midi_t_magic 0xa15a1c03
|
---|
142 | #define snd_gus_card_t_magic 0xa15a1d01
|
---|
143 | #define gus_pcm_private_t_magic 0xa15a1d02
|
---|
144 | #define gus_proc_private_t_magic 0xa15a1d03
|
---|
145 | #define tea6330t_t_magic 0xa15a1e01
|
---|
146 | #define ad1848_t_magic 0xa15a1f01
|
---|
147 | #define cs4231_t_magic 0xa15a2001
|
---|
148 | #define es1688_t_magic 0xa15a2101
|
---|
149 | #define opti93x_t_magic 0xa15a2201
|
---|
150 | #define emu8000_t_magic 0xa15a2301
|
---|
151 | #define emu8000_proc_private_t_magic 0xa15a2302
|
---|
152 | #define snd_emux_t_magic 0xa15a2303
|
---|
153 | #define snd_emux_port_t_magic 0xa15a2304
|
---|
154 | #define sb_t_magic 0xa15a2401
|
---|
155 | #define snd_sb_csp_t_magic 0xa15a2402
|
---|
156 | #define snd_card_dummy_t_magic 0xa15a2501
|
---|
157 | #define snd_card_dummy_pcm_t_magic 0xa15a2502
|
---|
158 | #define opl3_t_magic 0xa15a2601
|
---|
159 | #define opl4_t_magic 0xa15a2602
|
---|
160 | #define snd_seq_dummy_port_t_magic 0xa15a2701
|
---|
161 | #define ice1712_t_magic 0xa15a2801
|
---|
162 | #define ad1816a_t_magic 0xa15a2901
|
---|
163 | #define intel8x0_t_magic 0xa15a2a01
|
---|
164 | #define es1968_t_magic 0xa15a2b01
|
---|
165 | #define esschan_t_magic 0xa15a2b02
|
---|
166 | #define via82xx_t_magic 0xa15a2c01
|
---|
167 | #define pdplus_t_magic 0xa15a2d01
|
---|
168 | #define cmipci_t_magic 0xa15a2e01
|
---|
169 | #define ymfpci_t_magic 0xa15a2f01
|
---|
170 | #define ymfpci_pcm_t_magic 0xa15a2f02
|
---|
171 | #define cs4281_t_magic 0xa15a3001
|
---|
172 | #define snd_i2c_bus_t_magic 0xa15a3101
|
---|
173 | #define snd_i2c_device_t_magic 0xa15a3102
|
---|
174 | #define cs8427_t_magic 0xa15a3111
|
---|
175 | #define m3_t_magic 0xa15a3201
|
---|
176 | #define m3_dma_t_magic 0xa15a3202
|
---|
177 | #define nm256_t_magic 0xa15a3301
|
---|
178 | #define nm256_dma_t_magic 0xa15a3302
|
---|
179 | #define sam9407_t_magic 0xa15a3401
|
---|
180 | #define pmac_t_magic 0xa15a3501
|
---|
181 | #define ali_t_magic 0xa15a3601
|
---|
182 | #define mtpav_t_magic 0xa15a3701
|
---|
183 | #define mtpav_port_t_magic 0xa15a3702
|
---|
184 | #define korg1212_t_magic 0xa15a3800
|
---|
185 | #define opl3sa2_t_magic 0xa15a3900
|
---|
186 | #define serialmidi_t_magic 0xa15a3a00
|
---|
187 | #define sa11xx_uda1341_t_magic 0xa15a3b00
|
---|
188 | #define uda1341_t_magic 0xa15a3c00
|
---|
189 | #define l3_client_t_magic 0xa15a3d00
|
---|
190 | #define snd_usb_audio_t_magic 0xa15a3e01
|
---|
191 | #define usb_mixer_elem_info_t_magic 0xa15a3e02
|
---|
192 | #define snd_usb_stream_t_magic 0xa15a3e03
|
---|
193 | #define snd_usb_midi_t_magic 0xa15a3f01
|
---|
194 | #define snd_usb_midi_out_endpoint_t_magic 0xa15a3f02
|
---|
195 | #define snd_usb_midi_in_endpoint_t_magic 0xa15a3f03
|
---|
196 | #define ak4117_t_magic 0xa15a4000
|
---|
197 | #define psic_t_magic 0xa15a4100
|
---|
198 | #define vx_core_t_magic 0xa15a4110
|
---|
199 | #define vx_pipe_t_magic 0xa15a4112
|
---|
200 | #define azf3328_t_magic 0xa15a4200
|
---|
201 | #define bt87x_t_magic 0xa15a4400
|
---|
202 | #define pdacf_t_magic 0xa15a4500
|
---|
203 | #else
|
---|
204 |
|
---|
205 | #define snd_magic_kcalloc(type, extra, flags) (type *) snd_kcalloc(sizeof(type) + extra, flags)
|
---|
206 | #define snd_magic_kmalloc(type, extra, flags) (type *) kmalloc(sizeof(type) + extra, flags)
|
---|
207 | #define snd_magic_cast(type, ptr, retval) (type *) ptr
|
---|
208 | #define snd_magic_cast1(type, ptr, retval) snd_magic_cast(type, ptr, retval)
|
---|
209 | #define snd_magic_kfree kfree
|
---|
210 |
|
---|
211 | #endif
|
---|
212 |
|
---|
213 | #endif /* __SOUND_SNDMAGIC_H */
|
---|
214 |
|
---|