drm/i915: Avoid NULL dereference with component_only tv_modes
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / comedi / kcomedilib / get.c
blob6d84187152538ca3e12fd5a359d6b58d02d37d07
1 /*
2 kcomedilib/get.c
3 a comedlib interface for kernel modules
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define __NO_VERSION__
25 #include "../comedi.h"
26 #include "../comedilib.h"
27 #include "../comedidev.h"
29 int comedi_get_n_subdevices(void *d)
31 struct comedi_device *dev = (struct comedi_device *)d;
33 return dev->n_subdevices;
36 int comedi_get_version_code(void *d)
38 return COMEDI_VERSION_CODE;
41 const char *comedi_get_driver_name(void *d)
43 struct comedi_device *dev = (struct comedi_device *)d;
45 return dev->driver->driver_name;
48 const char *comedi_get_board_name(void *d)
50 struct comedi_device *dev = (struct comedi_device *)d;
52 return dev->board_name;
55 int comedi_get_subdevice_type(void *d, unsigned int subdevice)
57 struct comedi_device *dev = (struct comedi_device *)d;
58 struct comedi_subdevice *s = dev->subdevices + subdevice;
60 return s->type;
63 unsigned int comedi_get_subdevice_flags(void *d, unsigned int subdevice)
65 struct comedi_device *dev = (struct comedi_device *)d;
66 struct comedi_subdevice *s = dev->subdevices + subdevice;
68 return s->subdev_flags;
71 int comedi_find_subdevice_by_type(void *d, int type, unsigned int subd)
73 struct comedi_device *dev = (struct comedi_device *)d;
75 if (subd > dev->n_subdevices)
76 return -ENODEV;
78 for (; subd < dev->n_subdevices; subd++) {
79 if (dev->subdevices[subd].type == type)
80 return subd;
82 return -1;
85 int comedi_get_n_channels(void *d, unsigned int subdevice)
87 struct comedi_device *dev = (struct comedi_device *)d;
88 struct comedi_subdevice *s = dev->subdevices + subdevice;
90 return s->n_chan;
93 int comedi_get_len_chanlist(void *d, unsigned int subdevice)
95 struct comedi_device *dev = (struct comedi_device *)d;
96 struct comedi_subdevice *s = dev->subdevices + subdevice;
98 return s->len_chanlist;
101 unsigned int comedi_get_maxdata(void *d, unsigned int subdevice,
102 unsigned int chan)
104 struct comedi_device *dev = (struct comedi_device *)d;
105 struct comedi_subdevice *s = dev->subdevices + subdevice;
107 if (s->maxdata_list)
108 return s->maxdata_list[chan];
110 return s->maxdata;
113 #ifdef KCOMEDILIB_DEPRECATED
114 int comedi_get_rangetype(void *d, unsigned int subdevice, unsigned int chan)
116 struct comedi_device *dev = (struct comedi_device *)d;
117 struct comedi_subdevice *s = dev->subdevices + subdevice;
118 int ret;
120 if (s->range_table_list) {
121 ret = s->range_table_list[chan]->length;
122 } else {
123 ret = s->range_table->length;
126 ret = ret | (dev->minor << 28) | (subdevice << 24) | (chan << 16);
128 return ret;
130 #endif
132 int comedi_get_n_ranges(void *d, unsigned int subdevice, unsigned int chan)
134 struct comedi_device *dev = (struct comedi_device *)d;
135 struct comedi_subdevice *s = dev->subdevices + subdevice;
136 int ret;
138 if (s->range_table_list) {
139 ret = s->range_table_list[chan]->length;
140 } else {
141 ret = s->range_table->length;
144 return ret;
148 * ALPHA (non-portable)
150 int comedi_get_krange(void *d, unsigned int subdevice, unsigned int chan,
151 unsigned int range, struct comedi_krange *krange)
153 struct comedi_device *dev = (struct comedi_device *)d;
154 struct comedi_subdevice *s = dev->subdevices + subdevice;
155 const struct comedi_lrange *lr;
157 if (s->range_table_list) {
158 lr = s->range_table_list[chan];
159 } else {
160 lr = s->range_table;
162 if (range >= lr->length)
163 return -EINVAL;
165 memcpy(krange, lr->range + range, sizeof(struct comedi_krange));
167 return 0;
171 * ALPHA (may be renamed)
173 unsigned int comedi_get_buf_head_pos(void *d, unsigned int subdevice)
175 struct comedi_device *dev = (struct comedi_device *)d;
176 struct comedi_subdevice *s = dev->subdevices + subdevice;
177 struct comedi_async *async;
179 async = s->async;
180 if (async == NULL)
181 return 0;
183 return async->buf_write_count;
186 int comedi_get_buffer_contents(void *d, unsigned int subdevice)
188 struct comedi_device *dev = (struct comedi_device *)d;
189 struct comedi_subdevice *s = dev->subdevices + subdevice;
190 struct comedi_async *async;
191 unsigned int num_bytes;
193 if (subdevice >= dev->n_subdevices)
194 return -1;
195 async = s->async;
196 if (async == NULL)
197 return 0;
198 num_bytes = comedi_buf_read_n_available(s->async);
199 return num_bytes;
203 * ALPHA
205 int comedi_set_user_int_count(void *d, unsigned int subdevice,
206 unsigned int buf_user_count)
208 struct comedi_device *dev = (struct comedi_device *)d;
209 struct comedi_subdevice *s = dev->subdevices + subdevice;
210 struct comedi_async *async;
211 int num_bytes;
213 async = s->async;
214 if (async == NULL)
215 return -1;
217 num_bytes = buf_user_count - async->buf_read_count;
218 if (num_bytes < 0)
219 return -1;
220 comedi_buf_read_alloc(async, num_bytes);
221 comedi_buf_read_free(async, num_bytes);
223 return 0;
226 int comedi_mark_buffer_read(void *d, unsigned int subdevice,
227 unsigned int num_bytes)
229 struct comedi_device *dev = (struct comedi_device *)d;
230 struct comedi_subdevice *s = dev->subdevices + subdevice;
231 struct comedi_async *async;
233 if (subdevice >= dev->n_subdevices)
234 return -1;
235 async = s->async;
236 if (async == NULL)
237 return -1;
239 comedi_buf_read_alloc(async, num_bytes);
240 comedi_buf_read_free(async, num_bytes);
242 return 0;
245 int comedi_mark_buffer_written(void *d, unsigned int subdevice,
246 unsigned int num_bytes)
248 struct comedi_device *dev = (struct comedi_device *)d;
249 struct comedi_subdevice *s = dev->subdevices + subdevice;
250 struct comedi_async *async;
251 int bytes_written;
253 if (subdevice >= dev->n_subdevices)
254 return -1;
255 async = s->async;
256 if (async == NULL)
257 return -1;
258 bytes_written = comedi_buf_write_alloc(async, num_bytes);
259 comedi_buf_write_free(async, bytes_written);
260 if (bytes_written != num_bytes)
261 return -1;
262 return 0;
265 int comedi_get_buffer_size(void *d, unsigned int subdev)
267 struct comedi_device *dev = (struct comedi_device *)d;
268 struct comedi_subdevice *s = dev->subdevices + subdev;
269 struct comedi_async *async;
271 if (subdev >= dev->n_subdevices)
272 return -1;
273 async = s->async;
274 if (async == NULL)
275 return 0;
277 return async->prealloc_bufsz;
280 int comedi_get_buffer_offset(void *d, unsigned int subdevice)
282 struct comedi_device *dev = (struct comedi_device *)d;
283 struct comedi_subdevice *s = dev->subdevices + subdevice;
284 struct comedi_async *async;
286 if (subdevice >= dev->n_subdevices)
287 return -1;
288 async = s->async;
289 if (async == NULL)
290 return 0;
292 return async->buf_read_ptr;