ALSA: asihpi - Clarify adapter index validity check
authorEliot Blennerhassett <eblennerhassett@audioscience.com>
Mon, 1 Aug 2011 21:44:24 +0000 (09:44 +1200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 2 Aug 2011 07:26:31 +0000 (09:26 +0200)
Avoids assigning possibly invalid address to pa, even if it
is never dereferenced.
Correct error response to reflect request object/function ids.

Signed-off-by: Eliot Blennerhassett <eblennerhassett@audioscience.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/asihpi/hpioctl.c

index 9683f84ecdc835ea964932e358b4a66bcbc6a628..a32502e796de937946b1e1b2c9b9d3318441049f 100644 (file)
@@ -177,16 +177,21 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        } else {
                u16 __user *ptr = NULL;
                u32 size = 0;
-
+               u32 adapter_present;
                /* -1=no data 0=read from user mem, 1=write to user mem */
                int wrflag = -1;
-               u32 adapter = hm->h.adapter_index;
-               struct hpi_adapter *pa = &adapters[adapter];
+               struct hpi_adapter *pa;
+
+               if (hm->h.adapter_index < HPI_MAX_ADAPTERS) {
+                       pa = &adapters[hm->h.adapter_index];
+                       adapter_present = pa->type;
+               } else {
+                       adapter_present = 0;
+               }
 
-               if ((adapter >= HPI_MAX_ADAPTERS) || (!pa->type)) {
-                       hpi_init_response(&hr->r0, HPI_OBJ_ADAPTER,
-                               HPI_ADAPTER_OPEN,
-                               HPI_ERROR_BAD_ADAPTER_NUMBER);
+               if (!adapter_present) {
+                       hpi_init_response(&hr->r0, hm->h.object,
+                               hm->h.function, HPI_ERROR_BAD_ADAPTER_NUMBER);
 
                        uncopied_bytes =
                                copy_to_user(puhr, hr, sizeof(hr->h));