Fix insn_bits bitshift calculation for subdevice with non-zero base_port.
authorIan Abbott <abbotti@mev.co.uk>
Wed, 12 Aug 2009 15:56:14 +0000 (15:56 +0000)
committerIan Abbott <abbotti@mev.co.uk>
Wed, 12 Aug 2009 15:56:14 +0000 (15:56 +0000)
Thanks to Jérôme Carretero (cJ-comedi at zougloub dot eu) for spotting the
bug.

comedi/drivers/ni_65xx.c

index 86e8b4d5e791a0fbc40a798ce632b31be3d0156f..ebb45cfa5113425680139fa1d78698ed659e59e1 100644 (file)
@@ -399,7 +399,7 @@ static int ni_65xx_dio_insn_bits(comedi_device * dev, comedi_subdevice * s,
                return -EINVAL;
        base_bitfield_channel = CR_CHAN(insn->chanspec);
        for (j = 0; j < max_ports_per_bitfield; ++j) {
-               const unsigned port =
+               unsigned port =
                        sprivate(s)->base_port +
                        ni_65xx_port_by_channel(base_bitfield_channel) + j;
                unsigned base_port_channel;
@@ -407,7 +407,8 @@ static int ni_65xx_dio_insn_bits(comedi_device * dev, comedi_subdevice * s,
                int bitshift;
                if (port >= ni_65xx_total_num_ports(board(dev)))
                        break;
-               base_port_channel = port * ni_65xx_channels_per_port;
+               base_port_channel = (port - sprivate(s)->base_port) *
+                       ni_65xx_channels_per_port;
                port_mask = data[0];
                port_data = data[1];
                bitshift = base_port_channel - base_bitfield_channel;