aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/asihpi/hpioctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/asihpi/hpioctl.c')
-rw-r--r--sound/pci/asihpi/hpioctl.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c
index d8e7047512f..a32502e796d 100644
--- a/sound/pci/asihpi/hpioctl.c
+++ b/sound/pci/asihpi/hpioctl.c
@@ -1,7 +1,7 @@
1/******************************************************************************* 1/*******************************************************************************
2 2
3 AudioScience HPI driver 3 AudioScience HPI driver
4 Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com> 4 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as 7 it under the terms of version 2 of the GNU General Public License as
@@ -107,7 +107,6 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
107 union hpi_response_buffer_v1 *hr; 107 union hpi_response_buffer_v1 *hr;
108 u16 res_max_size; 108 u16 res_max_size;
109 u32 uncopied_bytes; 109 u32 uncopied_bytes;
110 struct hpi_adapter *pa = NULL;
111 int err = 0; 110 int err = 0;
112 111
113 if (cmd != HPI_IOCTL_LINUX) 112 if (cmd != HPI_IOCTL_LINUX)
@@ -157,11 +156,6 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
157 goto out; 156 goto out;
158 } 157 }
159 158
160 if (hm->h.adapter_index >= HPI_MAX_ADAPTERS) {
161 err = -EINVAL;
162 goto out;
163 }
164
165 switch (hm->h.function) { 159 switch (hm->h.function) {
166 case HPI_SUBSYS_CREATE_ADAPTER: 160 case HPI_SUBSYS_CREATE_ADAPTER:
167 case HPI_ADAPTER_DELETE: 161 case HPI_ADAPTER_DELETE:
@@ -183,16 +177,21 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
183 } else { 177 } else {
184 u16 __user *ptr = NULL; 178 u16 __user *ptr = NULL;
185 u32 size = 0; 179 u32 size = 0;
186 180 u32 adapter_present;
187 /* -1=no data 0=read from user mem, 1=write to user mem */ 181 /* -1=no data 0=read from user mem, 1=write to user mem */
188 int wrflag = -1; 182 int wrflag = -1;
189 u32 adapter = hm->h.adapter_index; 183 struct hpi_adapter *pa;
190 pa = &adapters[adapter]; 184
185 if (hm->h.adapter_index < HPI_MAX_ADAPTERS) {
186 pa = &adapters[hm->h.adapter_index];
187 adapter_present = pa->type;
188 } else {
189 adapter_present = 0;
190 }
191 191
192 if ((adapter > HPI_MAX_ADAPTERS) || (!pa->type)) { 192 if (!adapter_present) {
193 hpi_init_response(&hr->r0, HPI_OBJ_ADAPTER, 193 hpi_init_response(&hr->r0, hm->h.object,
194 HPI_ADAPTER_OPEN, 194 hm->h.function, HPI_ERROR_BAD_ADAPTER_NUMBER);
195 HPI_ERROR_BAD_ADAPTER_NUMBER);
196 195
197 uncopied_bytes = 196 uncopied_bytes =
198 copy_to_user(puhr, hr, sizeof(hr->h)); 197 copy_to_user(puhr, hr, sizeof(hr->h));
@@ -203,7 +202,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
203 goto out; 202 goto out;
204 } 203 }
205 204
206 if (mutex_lock_interruptible(&adapters[adapter].mutex)) { 205 if (mutex_lock_interruptible(&pa->mutex)) {
207 err = -EINTR; 206 err = -EINTR;
208 goto out; 207 goto out;
209 } 208 }
@@ -239,8 +238,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
239 "stream buffer size %d\n", 238 "stream buffer size %d\n",
240 size); 239 size);
241 240
242 mutex_unlock(&adapters 241 mutex_unlock(&pa->mutex);
243 [adapter].mutex);
244 err = -EINVAL; 242 err = -EINVAL;
245 goto out; 243 goto out;
246 } 244 }
@@ -281,7 +279,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
281 uncopied_bytes, size); 279 uncopied_bytes, size);
282 } 280 }
283 281
284 mutex_unlock(&adapters[adapter].mutex); 282 mutex_unlock(&pa->mutex);
285 } 283 }
286 284
287 /* on return response size must be set */ 285 /* on return response size must be set */