move some checks for length of data[] in configuration insn to core
authorFrank Mori Hess <fmhess@speakeasy.net>
Sun, 6 Mar 2005 17:30:40 +0000 (17:30 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Sun, 6 Mar 2005 17:30:40 +0000 (17:30 +0000)
comedi/comedi_fops.c

index a49361a38048f7be288c79d5c9c4fba2ddb33a85..5fd9de13f9d4e0afd315889f080f2c7a6ef62795 100644 (file)
@@ -619,6 +619,27 @@ error:
        return i;
 }
 
+static int check_insn_config_length(comedi_insn *insn, lsampl_t *data)
+{
+       switch(data[0])
+       {
+       case INSN_CONFIG_DIO_OUTPUT:
+       case INSN_CONFIG_DIO_INPUT:
+               if(insn->n == 1) return 0;
+               break;
+       case INSN_CONFIG_DIO_QUERY:
+               if(insn->n == 2) return 0;
+               break;
+       case INSN_CONFIG_BLOCK_SIZE:
+               if( insn->n == 2 ) return 0;
+       //by default we allow the insn since we don't have checks for all possible cases yet 
+       default:
+               return 0;
+               break;
+       }
+       return -EINVAL;
+}
+
 static int parse_insn(comedi_device *dev,comedi_insn *insn,lsampl_t *data,void *file)
 {
        comedi_subdevice *s;
@@ -727,6 +748,8 @@ static int parse_insn(comedi_device *dev,comedi_insn *insn,lsampl_t *data,void *
                                ret=s->insn_bits(dev,s,insn,data);
                                break;
                        case INSN_CONFIG:
+                               ret=check_insn_config_length(insn);
+                               if(ret) break;
                                ret=s->insn_config(dev,s,insn,data);
                                break;
                        default: