[Xenomai-git] Alexis Berlemont : analogy: fix a bug in the user/ kernel copy of the instruction's data
Module: xenomai-head Branch: master Commit: 64dda2abf9650aea4a782ab5b932b60ea72a7470 URL: http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=64dda2abf9650aea4a782ab5b932b60ea72a7470 Author: Alexis Berlemont Date: Thu Dec 24 09:24:32 2009 +0100 analogy: fix a bug in the user/kernel copy of the instruction's data libanalogy allows the user application to find out the bit width of any channel; however, the instruction structure, which is the synchronous interface between user and kernel space, used by default "unsigned int" typed values to send data. This issue was fixed. --- include/analogy/instruction.h |6 +- ksrc/drivers/analogy/instruction.c | 20 +- ksrc/drivers/analogy/intel/8255.c | 24 +- ksrc/drivers/analogy/intel/parport.c | 36 ++- .../analogy/national_instruments/mio_common.c | 360 ksrc/drivers/analogy/national_instruments/pcimio.c |2 + .../analogy/national_instruments/tio_common.c | 74 +++-- ksrc/drivers/analogy/testing/fake.c| 19 +- ksrc/drivers/analogy/testing/loop.c| 18 +- 9 files changed, 322 insertions(+), 237 deletions(-) diff --git a/include/analogy/instruction.h b/include/analogy/instruction.h index b1564d7..fb902cb 100644 --- a/include/analogy/instruction.h +++ b/include/analogy/instruction.h @@ -175,7 +175,7 @@ struct a4l_instruction { /**< Channel descriptor */ unsigned int data_size; /**< Size of the intruction data */ - lsampl_t *data; + void *data; /**< Instruction data */ }; typedef struct a4l_instruction a4l_insn_t; @@ -202,8 +202,8 @@ struct a4l_kernel_instruction { unsigned int idx_subd; unsigned int chan_desc; unsigned int data_size; - lsampl_t *data; - lsampl_t *__udata; + void *data; + void *__udata; }; typedef struct a4l_kernel_instruction a4l_kinsn_t; diff --git a/ksrc/drivers/analogy/instruction.c b/ksrc/drivers/analogy/instruction.c index a2fb4ce..ed56367 100644 --- a/ksrc/drivers/analogy/instruction.c +++ b/ksrc/drivers/analogy/instruction.c @@ -38,10 +38,10 @@ int a4l_do_insn_gettime(a4l_kinsn_t * dsc) nanosecs_abs_t ns; uint32_t ns2; - uint32_t *data = (uint32_t *)dsc->data; + unsigned int *data = (unsigned int *)dsc->data; /* Basic checkings */ - if (dsc->data_size != 2 * sizeof(uint32_t)) { + if (dsc->data_size != 2 * sizeof(unsigned int)) { __a4l_err("a4l_do_insn_gettime: data size should be 2\n"); return -EINVAL; } @@ -51,8 +51,8 @@ int a4l_do_insn_gettime(a4l_kinsn_t * dsc) /* Perform the conversion */ ns2 = do_div(ns, 10); - data[0] = (uint32_t) ns; - data[1] = (uint32_t) ns2 / 1000; + data[0] = (unsigned int) ns; + data[1] = (unsigned int) ns2 / 1000; return 0; } @@ -60,21 +60,22 @@ int a4l_do_insn_gettime(a4l_kinsn_t * dsc) int a4l_do_insn_wait(a4l_kinsn_t * dsc) { unsigned int us; + unsigned int *data = (unsigned int *)dsc->data; /* Basic checkings */ - if (dsc->data_size != 1) { + if (dsc->data_size != sizeof(unsigned int)) { __a4l_err("a4l_do_insn_wait: data size should be 1\n"); return -EINVAL; } - if (dsc->data[0] > A4L_INSN_WAIT_MAX) { + if (data[0] > A4L_INSN_WAIT_MAX) { __a4l_err("a4l_do_insn_wait: wait duration is out of range\n"); return -EINVAL; } /* As we use (a4l_)udelay, we have to convert the delay into microseconds */ - us = dsc->data[0] / 1000; + us = data[0] / 1000; /* At least, the delay is rounded up to 1 microsecond */ if (us == 0) @@ -90,7 +91,8 @@ int a4l_do_insn_trig(a4l_cxt_t * cxt, a4l_kinsn_t * dsc) { a4l_subd_t *subd; a4l_dev_t *dev = a4l_get_dev(cxt); - lsampl_t trignum; + unsigned int trignum; + unsigned int *data = (unsigned int*)dsc->data; /* Basic checkings */ if (dsc->data_size > 1) { @@ -98,7 +100,7 @@ int a4l_do_insn_trig(a4l_cxt_t * cxt, a4l_kinsn_t * dsc) return -EINVAL; } - trignum = (dsc->data_size == 1) ? dsc->data[0] : 0; + trignum = (dsc->data_size == sizeof(unsigned int)) ? data[0] : 0; if (dsc->idx_subd >= dev->transfer.nb_subd) { __a4l_err("a4l_do_insn_trig: " diff --git a/ksrc/drivers/analogy/intel/8255.c b/ksrc/drivers/analogy/intel/8255.c index cf369bb..c43df78 100644 --- a/ksrc/drivers/analogy/intel/8255.c +++ b/ksrc/drivers/analogy/intel/8255.c @@ -132,28 +132,29 @@ int subd_8255_cancel(a4l_subd_t *subd) int subd_8255_insn_bits(a4l_subd_t *subd, a4l_kinsn_t *insn) { subd_8255_t *subd_8255 = (subd_8255_t *)subd->priv; +
[Xenomai-git] Alexis Berlemont : analogy: fix a bug in the user/ kernel copy of the instruction's data
Module: xenomai-abe Branch: analogy Commit: 64dda2abf9650aea4a782ab5b932b60ea72a7470 URL: http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=64dda2abf9650aea4a782ab5b932b60ea72a7470 Author: Alexis Berlemont Date: Thu Dec 24 09:24:32 2009 +0100 analogy: fix a bug in the user/kernel copy of the instruction's data libanalogy allows the user application to find out the bit width of any channel; however, the instruction structure, which is the synchronous interface between user and kernel space, used by default "unsigned int" typed values to send data. This issue was fixed. --- include/analogy/instruction.h |6 +- ksrc/drivers/analogy/instruction.c | 20 +- ksrc/drivers/analogy/intel/8255.c | 24 +- ksrc/drivers/analogy/intel/parport.c | 36 ++- .../analogy/national_instruments/mio_common.c | 360 ksrc/drivers/analogy/national_instruments/pcimio.c |2 + .../analogy/national_instruments/tio_common.c | 74 +++-- ksrc/drivers/analogy/testing/fake.c| 19 +- ksrc/drivers/analogy/testing/loop.c| 18 +- 9 files changed, 322 insertions(+), 237 deletions(-) diff --git a/include/analogy/instruction.h b/include/analogy/instruction.h index b1564d7..fb902cb 100644 --- a/include/analogy/instruction.h +++ b/include/analogy/instruction.h @@ -175,7 +175,7 @@ struct a4l_instruction { /**< Channel descriptor */ unsigned int data_size; /**< Size of the intruction data */ - lsampl_t *data; + void *data; /**< Instruction data */ }; typedef struct a4l_instruction a4l_insn_t; @@ -202,8 +202,8 @@ struct a4l_kernel_instruction { unsigned int idx_subd; unsigned int chan_desc; unsigned int data_size; - lsampl_t *data; - lsampl_t *__udata; + void *data; + void *__udata; }; typedef struct a4l_kernel_instruction a4l_kinsn_t; diff --git a/ksrc/drivers/analogy/instruction.c b/ksrc/drivers/analogy/instruction.c index a2fb4ce..ed56367 100644 --- a/ksrc/drivers/analogy/instruction.c +++ b/ksrc/drivers/analogy/instruction.c @@ -38,10 +38,10 @@ int a4l_do_insn_gettime(a4l_kinsn_t * dsc) nanosecs_abs_t ns; uint32_t ns2; - uint32_t *data = (uint32_t *)dsc->data; + unsigned int *data = (unsigned int *)dsc->data; /* Basic checkings */ - if (dsc->data_size != 2 * sizeof(uint32_t)) { + if (dsc->data_size != 2 * sizeof(unsigned int)) { __a4l_err("a4l_do_insn_gettime: data size should be 2\n"); return -EINVAL; } @@ -51,8 +51,8 @@ int a4l_do_insn_gettime(a4l_kinsn_t * dsc) /* Perform the conversion */ ns2 = do_div(ns, 10); - data[0] = (uint32_t) ns; - data[1] = (uint32_t) ns2 / 1000; + data[0] = (unsigned int) ns; + data[1] = (unsigned int) ns2 / 1000; return 0; } @@ -60,21 +60,22 @@ int a4l_do_insn_gettime(a4l_kinsn_t * dsc) int a4l_do_insn_wait(a4l_kinsn_t * dsc) { unsigned int us; + unsigned int *data = (unsigned int *)dsc->data; /* Basic checkings */ - if (dsc->data_size != 1) { + if (dsc->data_size != sizeof(unsigned int)) { __a4l_err("a4l_do_insn_wait: data size should be 1\n"); return -EINVAL; } - if (dsc->data[0] > A4L_INSN_WAIT_MAX) { + if (data[0] > A4L_INSN_WAIT_MAX) { __a4l_err("a4l_do_insn_wait: wait duration is out of range\n"); return -EINVAL; } /* As we use (a4l_)udelay, we have to convert the delay into microseconds */ - us = dsc->data[0] / 1000; + us = data[0] / 1000; /* At least, the delay is rounded up to 1 microsecond */ if (us == 0) @@ -90,7 +91,8 @@ int a4l_do_insn_trig(a4l_cxt_t * cxt, a4l_kinsn_t * dsc) { a4l_subd_t *subd; a4l_dev_t *dev = a4l_get_dev(cxt); - lsampl_t trignum; + unsigned int trignum; + unsigned int *data = (unsigned int*)dsc->data; /* Basic checkings */ if (dsc->data_size > 1) { @@ -98,7 +100,7 @@ int a4l_do_insn_trig(a4l_cxt_t * cxt, a4l_kinsn_t * dsc) return -EINVAL; } - trignum = (dsc->data_size == 1) ? dsc->data[0] : 0; + trignum = (dsc->data_size == sizeof(unsigned int)) ? data[0] : 0; if (dsc->idx_subd >= dev->transfer.nb_subd) { __a4l_err("a4l_do_insn_trig: " diff --git a/ksrc/drivers/analogy/intel/8255.c b/ksrc/drivers/analogy/intel/8255.c index cf369bb..c43df78 100644 --- a/ksrc/drivers/analogy/intel/8255.c +++ b/ksrc/drivers/analogy/intel/8255.c @@ -132,28 +132,29 @@ int subd_8255_cancel(a4l_subd_t *subd) int subd_8255_insn_bits(a4l_subd_t *subd, a4l_kinsn_t *insn) { subd_8255_t *subd_8255 = (subd_8255_t *)subd->priv; +