]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/staging/comedi/drivers/cb_pcidda.c
Staging: comedi: fix read past end of array in cb_pcidda_attach()
[net-next-2.6.git] / drivers / staging / comedi / drivers / cb_pcidda.c
index 782357732eed8a85a3a93a8824d923c80e38f7a3..c374bee250687597a8c196e8a8823b44f2ea3aaa 100644 (file)
@@ -52,7 +52,6 @@ Please report success/failure with other different cards to
 #include "8255.h"
 
 #define PCI_VENDOR_ID_CB       0x1307  /*  PCI vendor number of ComputerBoards */
-#define N_BOARDS       10      /*  Number of boards in cb_pcidda_boards */
 #define EEPROM_SIZE    128     /*  number of entries in eeprom */
 #define MAX_AO_CHANNELS 8      /*  maximum number of ao channels for supported boards */
 
@@ -307,7 +306,7 @@ static int cb_pcidda_attach(struct comedi_device *dev,
                                        continue;
                                }
                        }
-                       for (index = 0; index < N_BOARDS; index++) {
+                       for (index = 0; index < ARRAY_SIZE(cb_pcidda_boards); index++) {
                                if (cb_pcidda_boards[index].device_id ==
                                    pcidev->device) {
                                        goto found;
@@ -410,9 +409,8 @@ static int cb_pcidda_detach(struct comedi_device *dev)
  */
        if (devpriv) {
                if (devpriv->pci_dev) {
-                       if (devpriv->dac) {
+                       if (devpriv->dac)
                                comedi_pci_disable(devpriv->pci_dev);
-                       }
                        pci_dev_put(devpriv->pci_dev);
                }
        }
@@ -677,9 +675,8 @@ static unsigned int cb_pcidda_serial_in(struct comedi_device *dev)
 
        for (i = 1; i <= value_width; i++) {
                /*  read bits most significant bit first */
-               if (inw_p(devpriv->dac + DACALIBRATION1) & SERIAL_OUT_BIT) {
+               if (inw_p(devpriv->dac + DACALIBRATION1) & SERIAL_OUT_BIT)
                        value |= 1 << (value_width - i);
-               }
        }
 
        return value;
@@ -716,9 +713,8 @@ static unsigned int cb_pcidda_read_eeprom(struct comedi_device *dev,
        /*  send serial output stream to eeprom */
        cal2_bits = SELECT_EEPROM_BIT | DESELECT_REF_DAC_BIT | DUMMY_BIT;
        /*  deactivate caldacs (one caldac for every two channels) */
-       for (i = 0; i < max_num_caldacs; i++) {
+       for (i = 0; i < max_num_caldacs; i++)
                cal2_bits |= DESELECT_CALDAC_BIT(i);
-       }
        outw_p(cal2_bits, devpriv->dac + DACALIBRATION2);
 
        /*  tell eeprom we want to read */
@@ -756,9 +752,8 @@ static void cb_pcidda_write_caldac(struct comedi_device *dev,
 */
        cal2_bits = DESELECT_REF_DAC_BIT | DUMMY_BIT;
        /*  deactivate caldacs (one caldac for every two channels) */
-       for (i = 0; i < max_num_caldacs; i++) {
+       for (i = 0; i < max_num_caldacs; i++)
                cal2_bits |= DESELECT_CALDAC_BIT(i);
-       }
        /*  activate the caldac we want */
        cal2_bits &= ~DESELECT_CALDAC_BIT(caldac);
        outw_p(cal2_bits, devpriv->dac + DACALIBRATION2);