From 34e6673a742d7ed10784ac115635b3a39a386f7d Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 15 Dec 2011 20:42:01 +0000 Subject: [PATCH] adl_pci8164: don't access *data when insn->n == 0 Due to recent change to do_insnlist_ioctl() and do_insn_ioctl(), the 'data' pointer will be NULL when insn->n == 0. Do not access *data in this case. Also fixed instructions that printed the value of data[1] and returned 2 even though they only used data[0]. Signed-off-by: Ian Abbott --- comedi/drivers/adl_pci8164.c | 77 ++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/comedi/drivers/adl_pci8164.c b/comedi/drivers/adl_pci8164.c index dd84f3ab..946db2f1 100644 --- a/comedi/drivers/adl_pci8164.c +++ b/comedi/drivers/adl_pci8164.c @@ -214,6 +214,9 @@ static int adl_pci8164_insn_read_msts(comedi_device * dev, comedi_subdevice * s, int axis, axis_reg; char *axisname; + if (insn->n == 0) + return 0; + axis = CR_CHAN(insn->chanspec); switch (axis) { @@ -239,10 +242,10 @@ static int adl_pci8164_insn_read_msts(comedi_device * dev, comedi_subdevice * s, } data[0] = inw(dev->iobase + axis_reg + PCI8164_MSTS); - printk("comedi: pci8164 MSTS read -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); + printk("comedi: pci8164 MSTS read -> %04X on axis %s\n", data[0], + axisname); - return 2; + return 1; } static int adl_pci8164_insn_read_ssts(comedi_device * dev, comedi_subdevice * s, @@ -251,6 +254,9 @@ static int adl_pci8164_insn_read_ssts(comedi_device * dev, comedi_subdevice * s, int axis, axis_reg; char *axisname; + if (insn->n == 0) + return 0; + axis = CR_CHAN(insn->chanspec); switch (axis) { @@ -276,10 +282,10 @@ static int adl_pci8164_insn_read_ssts(comedi_device * dev, comedi_subdevice * s, } data[0] = inw(dev->iobase + axis_reg + PCI8164_SSTS); - printk("comedi: pci8164 SSTS read -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); + printk("comedi: pci8164 SSTS read -> %04X on axis %s\n", data[0], + axisname); - return 2; + return 1; } static int adl_pci8164_insn_read_buf0(comedi_device * dev, comedi_subdevice * s, @@ -288,6 +294,9 @@ static int adl_pci8164_insn_read_buf0(comedi_device * dev, comedi_subdevice * s, int axis, axis_reg; char *axisname; + if (insn->n == 0) + return 0; + axis = CR_CHAN(insn->chanspec); switch (axis) { @@ -313,19 +322,21 @@ static int adl_pci8164_insn_read_buf0(comedi_device * dev, comedi_subdevice * s, } data[0] = inw(dev->iobase + axis_reg + PCI8164_BUF0); - printk("comedi: pci8164 BUF0 read -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); + printk("comedi: pci8164 BUF0 read -> %04X on axis %s\n", data[0], + axisname); - return 2; + return 1; } static int adl_pci8164_insn_read_buf1(comedi_device * dev, comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { int axis, axis_reg; - char *axisname; + if (insn->n == 0) + return 0; + axis = CR_CHAN(insn->chanspec); switch (axis) { @@ -351,19 +362,21 @@ static int adl_pci8164_insn_read_buf1(comedi_device * dev, comedi_subdevice * s, } data[0] = inw(dev->iobase + axis_reg + PCI8164_BUF1); - printk("comedi: pci8164 BUF1 read -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); + printk("comedi: pci8164 BUF1 read -> %04X on axis %s\n", data[0], + axisname); - return 2; + return 1; } static int adl_pci8164_insn_write_cmd(comedi_device * dev, comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { unsigned int axis, axis_reg; - char *axisname; + if (insn->n == 0) + return 0; + axis = CR_CHAN(insn->chanspec); switch (axis) { @@ -389,19 +402,21 @@ static int adl_pci8164_insn_write_cmd(comedi_device * dev, comedi_subdevice * s, } outw(data[0], dev->iobase + axis_reg + PCI8164_CMD); - printk("comedi: pci8164 CMD write -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); + printk("comedi: pci8164 CMD write -> %04X on axis %s\n", data[0], + axisname); - return 2; + return 1; } static int adl_pci8164_insn_write_otp(comedi_device * dev, comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { int axis, axis_reg; - char *axisname; + if (insn->n == 0) + return 0; + axis = CR_CHAN(insn->chanspec); switch (axis) { @@ -427,19 +442,21 @@ static int adl_pci8164_insn_write_otp(comedi_device * dev, comedi_subdevice * s, } outw(data[0], dev->iobase + axis_reg + PCI8164_OTP); - printk("comedi: pci8164 OTP write -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); + printk("comedi: pci8164 OTP write -> %04X on axis %s\n", data[0], + axisname); - return 2; + return 1; } static int adl_pci8164_insn_write_buf0(comedi_device * dev, comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { int axis, axis_reg; - char *axisname; + if (insn->n == 0) + return 0; + axis = CR_CHAN(insn->chanspec); switch (axis) { @@ -465,19 +482,21 @@ static int adl_pci8164_insn_write_buf0(comedi_device * dev, } outw(data[0], dev->iobase + axis_reg + PCI8164_BUF0); - printk("comedi: pci8164 BUF0 write -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); + printk("comedi: pci8164 BUF0 write -> %04X on axis %s\n", data[0], + axisname); - return 2; + return 1; } static int adl_pci8164_insn_write_buf1(comedi_device * dev, comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { int axis, axis_reg; - char *axisname; + if (insn->n == 0) + return 0; + axis = CR_CHAN(insn->chanspec); switch (axis) { @@ -503,10 +522,10 @@ static int adl_pci8164_insn_write_buf1(comedi_device * dev, } outw(data[0], dev->iobase + axis_reg + PCI8164_BUF1); - printk("comedi: pci8164 BUF1 write -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); + printk("comedi: pci8164 BUF1 write -> %04X on axis %s\n", data[0], + axisname); - return 2; + return 1; } COMEDI_PCI_INITCLEANUP(driver_adl_pci8164, adl_pci8164_pci_table); -- 2.26.2