summaryrefslogtreecommitdiff
path: root/drivers/staging/comedi
AgeCommit message (Collapse)Author
2019-04-17staging: comedi: ni_usb6501: Fix possible double-free of ->usb_rx_bufIan Abbott
`ni6501_alloc_usb_buffers()` is called from `ni6501_auto_attach()` to allocate RX and TX buffers for USB transfers. It allocates `devpriv->usb_rx_buf` followed by `devpriv->usb_tx_buf`. If the allocation of `devpriv->usb_tx_buf` fails, it frees `devpriv->usb_rx_buf`, leaving the pointer set dangling, and returns an error. Later, `ni6501_detach()` will be called from the core comedi module code to clean up. `ni6501_detach()` also frees both `devpriv->usb_rx_buf` and `devpriv->usb_tx_buf`, but `devpriv->usb_rx_buf` may have already beed freed, leading to a double-free error. Fix it bu removing the call to `kfree(devpriv->usb_rx_buf)` from `ni6501_alloc_usb_buffers()`, relying on `ni6501_detach()` to free the memory. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-17staging: comedi: ni_usb6501: Fix use of uninitialized mutexIan Abbott
If `ni6501_auto_attach()` returns an error, the core comedi module code will call `ni6501_detach()` to clean up. If `ni6501_auto_attach()` successfully allocated the comedi device private data, `ni6501_detach()` assumes that a `struct mutex mut` contained in the private data has been initialized and uses it. Unfortunately, there are a couple of places where `ni6501_auto_attach()` can return an error after allocating the device private data but before initializing the mutex, so this assumption is invalid. Fix it by initializing the mutex just after allocating the private data in `ni6501_auto_attach()` before any other errors can be retturned. Also move the call to `usb_set_intfdata()` just to keep the code a bit neater (either position for the call is fine). I believe this was the cause of the following syzbot crash report <https://syzkaller.appspot.com/bug?extid=cf4f2b6c24aff0a3edf6>: usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0 usb 1-1: config 0 descriptor?? usb 1-1: string descriptor 0 read error: -71 comedi comedi0: Wrong number of endpoints ni6501 1-1:0.233: driver 'ni6501' failed to auto-configure device. INFO: trying to register non-static key. the code is fine but needs lockdep annotation. turning off the locking correctness validator. CPU: 0 PID: 585 Comm: kworker/0:3 Not tainted 5.1.0-rc4-319354-g9a33b36 #3 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: usb_hub_wq hub_event Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xe8/0x16e lib/dump_stack.c:113 assign_lock_key kernel/locking/lockdep.c:786 [inline] register_lock_class+0x11b8/0x1250 kernel/locking/lockdep.c:1095 __lock_acquire+0xfb/0x37c0 kernel/locking/lockdep.c:3582 lock_acquire+0x10d/0x2f0 kernel/locking/lockdep.c:4211 __mutex_lock_common kernel/locking/mutex.c:925 [inline] __mutex_lock+0xfe/0x12b0 kernel/locking/mutex.c:1072 ni6501_detach+0x5b/0x110 drivers/staging/comedi/drivers/ni_usb6501.c:567 comedi_device_detach+0xed/0x800 drivers/staging/comedi/drivers.c:204 comedi_device_cleanup.part.0+0x68/0x140 drivers/staging/comedi/comedi_fops.c:156 comedi_device_cleanup drivers/staging/comedi/comedi_fops.c:187 [inline] comedi_free_board_dev.part.0+0x16/0x90 drivers/staging/comedi/comedi_fops.c:190 comedi_free_board_dev drivers/staging/comedi/comedi_fops.c:189 [inline] comedi_release_hardware_device+0x111/0x140 drivers/staging/comedi/comedi_fops.c:2880 comedi_auto_config.cold+0x124/0x1b0 drivers/staging/comedi/drivers.c:1068 usb_probe_interface+0x31d/0x820 drivers/usb/core/driver.c:361 really_probe+0x2da/0xb10 drivers/base/dd.c:509 driver_probe_device+0x21d/0x350 drivers/base/dd.c:671 __device_attach_driver+0x1d8/0x290 drivers/base/dd.c:778 bus_for_each_drv+0x163/0x1e0 drivers/base/bus.c:454 __device_attach+0x223/0x3a0 drivers/base/dd.c:844 bus_probe_device+0x1f1/0x2a0 drivers/base/bus.c:514 device_add+0xad2/0x16e0 drivers/base/core.c:2106 usb_set_configuration+0xdf7/0x1740 drivers/usb/core/message.c:2021 generic_probe+0xa2/0xda drivers/usb/core/generic.c:210 usb_probe_device+0xc0/0x150 drivers/usb/core/driver.c:266 really_probe+0x2da/0xb10 drivers/base/dd.c:509 driver_probe_device+0x21d/0x350 drivers/base/dd.c:671 __device_attach_driver+0x1d8/0x290 drivers/base/dd.c:778 bus_for_each_drv+0x163/0x1e0 drivers/base/bus.c:454 __device_attach+0x223/0x3a0 drivers/base/dd.c:844 bus_probe_device+0x1f1/0x2a0 drivers/base/bus.c:514 device_add+0xad2/0x16e0 drivers/base/core.c:2106 usb_new_device.cold+0x537/0xccf drivers/usb/core/hub.c:2534 hub_port_connect drivers/usb/core/hub.c:5089 [inline] hub_port_connect_change drivers/usb/core/hub.c:5204 [inline] port_event drivers/usb/core/hub.c:5350 [inline] hub_event+0x138e/0x3b00 drivers/usb/core/hub.c:5432 process_one_work+0x90f/0x1580 kernel/workqueue.c:2269 worker_thread+0x9b/0xe20 kernel/workqueue.c:2415 kthread+0x313/0x420 kernel/kthread.c:253 ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352 Reported-by: syzbot+cf4f2b6c24aff0a3edf6@syzkaller.appspotmail.com Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-16staging: comedi: vmk80xx: Fix possible double-free of ->usb_rx_bufIan Abbott
`vmk80xx_alloc_usb_buffers()` is called from `vmk80xx_auto_attach()` to allocate RX and TX buffers for USB transfers. It allocates `devpriv->usb_rx_buf` followed by `devpriv->usb_tx_buf`. If the allocation of `devpriv->usb_tx_buf` fails, it frees `devpriv->usb_rx_buf`, leaving the pointer set dangling, and returns an error. Later, `vmk80xx_detach()` will be called from the core comedi module code to clean up. `vmk80xx_detach()` also frees both `devpriv->usb_rx_buf` and `devpriv->usb_tx_buf`, but `devpriv->usb_rx_buf` may have already been freed, leading to a double-free error. Fix it by removing the call to `kfree(devpriv->usb_rx_buf)` from `vmk80xx_alloc_usb_buffers()`, relying on `vmk80xx_detach()` to free the memory. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-16staging: comedi: vmk80xx: Fix use of uninitialized semaphoreIan Abbott
If `vmk80xx_auto_attach()` returns an error, the core comedi module code will call `vmk80xx_detach()` to clean up. If `vmk80xx_auto_attach()` successfully allocated the comedi device private data, `vmk80xx_detach()` assumes that a `struct semaphore limit_sem` contained in the private data has been initialized and uses it. Unfortunately, there are a couple of places where `vmk80xx_auto_attach()` can return an error after allocating the device private data but before initializing the semaphore, so this assumption is invalid. Fix it by initializing the semaphore just after allocating the private data in `vmk80xx_auto_attach()` before any other errors can be returned. I believe this was the cause of the following syzbot crash report <https://syzkaller.appspot.com/bug?extid=54c2f58f15fe6876b6ad>: usb 1-1: config 0 has no interface number 0 usb 1-1: New USB device found, idVendor=10cf, idProduct=8068, bcdDevice=e6.8d usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0 usb 1-1: config 0 descriptor?? vmk80xx 1-1:0.117: driver 'vmk80xx' failed to auto-configure device. INFO: trying to register non-static key. the code is fine but needs lockdep annotation. turning off the locking correctness validator. CPU: 0 PID: 12 Comm: kworker/0:1 Not tainted 5.1.0-rc4-319354-g9a33b36 #3 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: usb_hub_wq hub_event Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xe8/0x16e lib/dump_stack.c:113 assign_lock_key kernel/locking/lockdep.c:786 [inline] register_lock_class+0x11b8/0x1250 kernel/locking/lockdep.c:1095 __lock_acquire+0xfb/0x37c0 kernel/locking/lockdep.c:3582 lock_acquire+0x10d/0x2f0 kernel/locking/lockdep.c:4211 __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline] _raw_spin_lock_irqsave+0x44/0x60 kernel/locking/spinlock.c:152 down+0x12/0x80 kernel/locking/semaphore.c:58 vmk80xx_detach+0x59/0x100 drivers/staging/comedi/drivers/vmk80xx.c:829 comedi_device_detach+0xed/0x800 drivers/staging/comedi/drivers.c:204 comedi_device_cleanup.part.0+0x68/0x140 drivers/staging/comedi/comedi_fops.c:156 comedi_device_cleanup drivers/staging/comedi/comedi_fops.c:187 [inline] comedi_free_board_dev.part.0+0x16/0x90 drivers/staging/comedi/comedi_fops.c:190 comedi_free_board_dev drivers/staging/comedi/comedi_fops.c:189 [inline] comedi_release_hardware_device+0x111/0x140 drivers/staging/comedi/comedi_fops.c:2880 comedi_auto_config.cold+0x124/0x1b0 drivers/staging/comedi/drivers.c:1068 usb_probe_interface+0x31d/0x820 drivers/usb/core/driver.c:361 really_probe+0x2da/0xb10 drivers/base/dd.c:509 driver_probe_device+0x21d/0x350 drivers/base/dd.c:671 __device_attach_driver+0x1d8/0x290 drivers/base/dd.c:778 bus_for_each_drv+0x163/0x1e0 drivers/base/bus.c:454 __device_attach+0x223/0x3a0 drivers/base/dd.c:844 bus_probe_device+0x1f1/0x2a0 drivers/base/bus.c:514 device_add+0xad2/0x16e0 drivers/base/core.c:2106 usb_set_configuration+0xdf7/0x1740 drivers/usb/core/message.c:2021 generic_probe+0xa2/0xda drivers/usb/core/generic.c:210 usb_probe_device+0xc0/0x150 drivers/usb/core/driver.c:266 really_probe+0x2da/0xb10 drivers/base/dd.c:509 driver_probe_device+0x21d/0x350 drivers/base/dd.c:671 __device_attach_driver+0x1d8/0x290 drivers/base/dd.c:778 bus_for_each_drv+0x163/0x1e0 drivers/base/bus.c:454 __device_attach+0x223/0x3a0 drivers/base/dd.c:844 bus_probe_device+0x1f1/0x2a0 drivers/base/bus.c:514 device_add+0xad2/0x16e0 drivers/base/core.c:2106 usb_new_device.cold+0x537/0xccf drivers/usb/core/hub.c:2534 hub_port_connect drivers/usb/core/hub.c:5089 [inline] hub_port_connect_change drivers/usb/core/hub.c:5204 [inline] port_event drivers/usb/core/hub.c:5350 [inline] hub_event+0x138e/0x3b00 drivers/usb/core/hub.c:5432 process_one_work+0x90f/0x1580 kernel/workqueue.c:2269 worker_thread+0x9b/0xe20 kernel/workqueue.c:2415 kthread+0x313/0x420 kernel/kthread.c:253 ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352 Reported-by: syzbot+54c2f58f15fe6876b6ad@syzkaller.appspotmail.com Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-18staging: comedi: ni_mio_common: Fix divide-by-zero for DIO cmdtestIan Abbott
`ni_cdio_cmdtest()` validates Comedi asynchronous commands for the DIO subdevice (subdevice 2) of supported National Instruments M-series cards. It is called when handling the `COMEDI_CMD` and `COMEDI_CMDTEST` ioctls for this subdevice. There are two causes for a possible divide-by-zero error when validating that the `stop_arg` member of the passed-in command is not too large. The first cause for the divide-by-zero is that calls to `comedi_bytes_per_scan()` are only valid once the command has been copied to `s->async->cmd`, but that copy is only done for the `COMEDI_CMD` ioctl. For the `COMEDI_CMDTEST` ioctl, it will use whatever was left there by the previous `COMEDI_CMD` ioctl, if any. (This is very likely, as it is usual for the application to use `COMEDI_CMDTEST` before `COMEDI_CMD`.) If there has been no previous, valid `COMEDI_CMD` for this subdevice, then `comedi_bytes_per_scan()` will return 0, so the subsequent division in `ni_cdio_cmdtest()` of `s->async->prealloc_bufsz / comedi_bytes_per_scan(s)` will be a divide-by-zero error. To fix this error, call a new function `comedi_bytes_per_scan_cmd(s, cmd)`, based on the existing `comedi_bytes_per_scan(s)` but using a specified `struct comedi_cmd` for its calculations. (Also refactor `comedi_bytes_per_scan()` to call the new function.) Once the first cause for the divide-by-zero has been fixed, the second cause is that `comedi_bytes_per_scan_cmd()` can legitimately return 0 if the `scan_end_arg` member of the `struct comedi_cmd` being tested is 0. Fix it by only performing the division (and validating that `stop_arg` is no more than the maximum value) if `comedi_bytes_per_scan_cmd()` returns a non-zero value. The problem was reported on the COMEDI mailing list here: https://groups.google.com/forum/#!topic/comedi_list/4t9WlHzMhKM Reported-by: Ivan Vasilyev <grabesstimme@gmail.com> Tested-by: Ivan Vasilyev <grabesstimme@gmail.com> Fixes: f164cbf98fa8 ("staging: comedi: ni_mio_common: add finite regeneration to dio output") Cc: <stable@vger.kernel.org> # 4.6+ Cc: Spencer E. Olson <olsonse@umich.edu> Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-26staging: comedi: ni_tio: Allocate shadow regs for each counter chipIan Abbott
The "ni_tio" module contains code to allocate, destroy and operate on a `struct ni_gpct_device`, which represents a number of counters spread over one or more blocks (or "chips"). `struct ni_gpct_device` includes an array member `regs` holding shadow copies of register values. Unfortunately, this is currently shared by each block of counters so they interfere with each other. This is a problem for the "ni_660x" module, which has 8 counters spread over 2 blocks. The `regs` storage needs to be two-dimensional, indexed by block (chip) number and register number. (It does not need to be three-dimensional because the registers for individual counters are intermingled within the block.) Change the `regs` member to an array pointer that can be indexed like a two-dimensional array to access the shadow storage for each register in each block. Allocate the storage in `ni_gpct_device_construct()` and free it in `ni_gpct_device_destroy()`. (`ni_gpct_device_construct()` can determine the number of blocks from the `num_counters` and `counters_per_chip` parameters.) Add new member `num_chips` to hold the number of chips. Use that to check that `chip_index` value is in range in the same places that check the register offset is in range. Remove the `counters_per_chip` member of `struct ni_gpct_device` as it is not needed anywhere and could be easily derived from the `num_counters` and `num_chips` members if required. Thanks to GitHub user "raabej" (real name unknown) for an initial implementation of this in the out-of-tree fork of the Comedi drivers. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-13staging: comedi: ni_660x: fix missing break in switch statementGustavo A. R. Silva
Add missing break statement in order to prevent the code from falling through to the default case and return -EINVAL every time. This bug was found thanks to the ongoing efforts to enable -Wimplicit-fallthrough. Fixes: aa94f2888825 ("staging: comedi: ni_660x: tidy up ni_660x_set_pfi_routing()") Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-04staging: comedi: comedi_fops.c: Remove redundant blank lineSandesh Kenjana Ashok
Removed redunant blank line. Issue found by checkpatch. Signed-off-by: Sandesh Kenjana Ashok <kas.sandesh@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-18staging: comedi: Removed not necessary braces for single blockJitendra Khasdev
This patch is used to remove not necessary braces for single if block. Signed-off-by: Jitendra Khasdev <jkhasdev@gmail.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-15staging: comedi: ni_pcidio: make defines uppercaseAlexander Schroth
According to the Linux coding guidelines, defines should be written in uppercase. This patch converts all define-statements in the ni_pcidio.c file to uppercase, thus matching the coding style of the kernel. Signed-off-by: Alexander Schroth <alexander.schroth@fau.de> Signed-off-by: Marco Ammon <marco.ammon@fau.de> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-07staging: comedi: fix typoMatteo Croce
Fix spelling mistake: "lenghth" -> "length" Signed-off-by: Matteo Croce <mcroce@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-07staging: comedi: cb_pcimdas.c: fixed an alignment coding style issueWilliam Mitchell Jr
Fixed a coding style issue. Signed-off-by: William Mitchell Jr <wdmjun@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-03Remove 'type' argument from access_ok() functionLinus Torvalds
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument of the user address range verification function since we got rid of the old racy i386-only code to walk page tables by hand. It existed because the original 80386 would not honor the write protect bit when in kernel mode, so you had to do COW by hand before doing any user access. But we haven't supported that in a long time, and these days the 'type' argument is a purely historical artifact. A discussion about extending 'user_access_begin()' to do the range checking resulted this patch, because there is no way we're going to move the old VERIFY_xyz interface to that model. And it's best done at the end of the merge window when I've done most of my merges, so let's just get this done once and for all. This patch was mostly done with a sed-script, with manual fix-ups for the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form. There were a couple of notable cases: - csky still had the old "verify_area()" name as an alias. - the iter_iov code had magical hardcoded knowledge of the actual values of VERIFY_{READ,WRITE} (not that they mattered, since nothing really used it) - microblaze used the type argument for a debug printout but other than those oddities this should be a total no-op patch. I tried to fix up all architectures, did fairly extensive grepping for access_ok() uses, and the changes are trivial, but I may have missed something. Any missed conversion should be trivially fixable, though. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-12-17Staging: comedi: cb_pcidas: fixed a spelling mistake coding style issueAmir Mahdi Ghorbanian
Fixed a coding style issue. Signed-off-by: Amir Mahdi Ghorbanian <indigoomega021@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-12-12staging: comedi: change do_insn*_ioctl to allow more samplesSpencer E. Olson
Changes do_insn*_ioctl functions to allow for data lengths for each comedi_insn of up to 2^16. This patch also changes these functions to only allocate as much memory as is necessary for each comedi_insn, rather than allocating a fixed-sized scratch space. In testing some user-space code for the new INSN_DEVICE_CONFIG_GET_ROUTES facility with some newer hardware, I discovered that do_insn_ioctl and do_insnlist_ioctl limited the amount of data that can be passed into the kernel for insn's to a length of 256. For some newer hardware, the number of routes can be greater than 1000. Working around the old limits (256) would complicate the user-space/kernel interaction. The new upper limit is reasonable with current memory available and does not otherwise impact the memory footprint for any current or otherwise typical configuration. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-12-05staging: comedi: drivers: Cleanup malformed licence identifierStephen Davies
This patch fixes multiple occurences of the checkpatch.pl warning: WARNING: Missing or malformed SPDX-License-Identifier tag in line 1 NB. This is an additional patch and does not overlap the patch sent yesterday for 8255.h. Should have sent them all together. Newb mistake. Cc: Ian Abbott <abbotti@mev.co.uk> Cc: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Stephen Davies <davo2002@tpg.com.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-12-05staging: comedi: fix spelling mistake "desination" -> "destination"Colin Ian King
There is a spelling mistake in message text in the call to unittest, fix this. Signed-off-by: Colin Ian King <colin.king@canonical.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-12-05staging: comedi: drivers: Cleanup malformed license identifierStephen Davies
This patch fixes the checkpatch.pl warning: WARNING: Missing or malformed SPDX-License-Identifier tag in line 1 Cc: Ian Abbott <abbotti@mev.co.uk> Cc: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Stephen Davies <davo2002@tpg.com.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-12-03Merge 4.20-rc5 into staging-nextGreg Kroah-Hartman
We need the staging fixes in here as well. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-07staging: comedi: clarify/unify macros for NI macro-defined terminalsSpencer E. Olson
Uses a single macro to define multiple macros that represent a series of terminals for NI devices. This patch also redefines NI_MAX_COUNTERS as the maximum number of counters possible on NI devices (instead of the maximum index of the counters). This was a little confusing and caused a bug in commit 347e244884c3b ("staging: comedi: tio: implement global tio/ctr routing") when setting/reading registers for counter terminals. Fixes: 347e244884c3b ("staging: comedi: tio: implement global tio/ctr routing") Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-07staging: comedi: ni_mio_common: scale ao INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTSSpencer E. Olson
Fixes implementation of INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS for ni_mio devices. The previous patch should have used the channel information passed in to scale the result by the number of channels being used. Fixes: 51fd36738383 ("staging: comedi: ni_mio_common: implement INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS") Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-07staging: comedi: ni_labpc_common: Use insn->n in AO insn_write handlerIan Abbott
The `insn_write` handler for the AO subdevice (`labpc_ao_insn_write()`) currently ignores `insn->n` (the number of samples to write) and assumes a single sample is to be written. But `insn->n` could be 0, meaning no samples should be written, in which case `data[0]` is invalid. Follow the usual Comedi guidelines and change `labpc_ao_insn_write()` to write the specified number of samples. This fixes the assumption that `data[0]` is valid. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-07staging: comedi: cb_pcidda: Use insn->n in AO insn_write handlerIan Abbott
The `insn_write` handler for the AO subdevice (`cb_pcidda_ao_insn_write()`) currently ignores `insn->n` (the number of samples to write) and assumes a single sample is to be written. But `insn->n` could be 0, meaning no samples should be written, in which case `data[0]` is invalid. Follow the usual Comedi guidelines and change `cb_pcidda_ao_insn_write()` to write the specified number of samples. This fixes the assumption that `data[0]` is valid. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-07staging: comedi: addi_apci_3501: Use insn->n in EEPROM insn_read handlerIan Abbott
The `insn_read` handler for the EEPROM subdevice (`apci3501_eeprom_insn_read()`) currently ignores `insn->n` (the number of samples to be read) and assumes a single sample is to be read. But `insn->n` could be 0, meaning no samples should be read, in which case `data[0]` ought not to be written. (The comedi core at least ensures that `data[0]` exists, but we should not rely on that.) Following the usual Comedi guidelines and interpret `insn->n` as the number of samples to be read, but only read the EEPROM location once and make `insn->n` copies, as we don't expect the contents of the EEPROM location to change between readings. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-07staging: comedi: Check length of INSN_CONFIG_TIMER_1 instructionIan Abbott
The contents of the Comedi configuration instruction `INSN_CONFIG_TIMER_1` instruction are not very well defined, but the one driver that uses it (the "cb_pcidas64" driver for the PCI-DAS4020/12 card) assumes its `insn->n` is 5. Add a check in `check_insn_config_length()` to verify that `insn->n` is correct for this configuration instruction. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-07staging: comedi: cb_pcidas64: Use insn->n in EEPROM insn_read handlerIan Abbott
The `insn_read` handler for the EEPROM subdevice (`eeprom_insn_read()`) currently ignores `insn->n` (the number of samples to be read) and assumes a single sample is to be read. But `insn->n` could be 0, meaning no samples should be read, in which case `data[0]` ought not to be written. (The comedi core at least ensures that `data[0]` exists, but we should not rely on that.) Follow the usual Comedi guidelines and interpret `insn->n` as the number of samples to be read, but only read the EEPROM location once and make `insn->n` copies, as we don't expect the contents of the EEPROM location to change between readings. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-07staging: comedi: cb_pcidas64: Use insn->n in AO insn_write handlerIan Abbott
The `insn_write` handler for the AO subdevice (`ao_winsn()` currently ignores `insn->n` (the number of samples to write) and assumes a single sample is to be written. But `insn->n` could be 0, meaning no samples should be written, in which case `data[0]` is invalid. Follow the usual Comedi guidelines and change `ao_winsn()` to write the specified number of samples. This fixes the assumption that `data[0]` is valid. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-05Staging: comedi: dt9812: fixed a typo in comment.Marco Wang
Fixed a typo in comment. Signed-off-by: Marco Wang <m.aesophor@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-14staging: comedi: tio: fix multiple missing break in switch bugsGustavo A. R. Silva
Currently, there are multiple missing break statements in two switch code blocks. This makes the execution path to fall all the way down through to the default cases, which makes the function ni_tio_set_gate_src() to always return -EINVAL. Fix this by adding the missing break statements. Also, notice that due to the absence of the break statements, the following pieces of code are unreachable: 1078 if (ret) 1079 return ret; 1080 /* 3. reenable & set mode to starts things back up */ 1081 ni_tio_set_gate_mode(counter, src); 1098 if (ret) 1099 return ret; 1100 /* 3. reenable & set mode to starts things back up */ 1101 ni_tio_set_gate2_mode(counter, src); So, by adding the missing breaks, this patch also fixes the problem above. Addresses-Coverity-ID: 1474165 ("Missing break in switch") Addresses-Coverity-ID: 1474162 ("Structurally dead code") Fixes: 347e244884c3 ("staging: comedi: tio: implement global tio/ctr routing") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_660x: add device-global routingSpencer E. Olson
Provides the device-global routing interface for ni_660x devices. Using the device-global names in comedi_cmd structures for commands was already supported through the ni_tio module. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_660x: clean up pfi routingSpencer E. Olson
Cleans up the pfi routing code to make it easier to follow, read, and also to prepare to use this cleaned up code for enabling the device-global routing interface for ni_660x devices. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_660x: Add NI PCI-6608 to list of supported devicesSpencer E. Olson
Previously, only the PXI version of the NI-6608 board was supported. This change adds support for the PCI version as well. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_mio_common: create device-global access to tioSpencer E. Olson
Adds tio sub-devices of ni_mio_common supported hardware to the implementation of test_route, connect_route, disconnect_route. This change delegates the actual functionality to the ni_tio module. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: tio: implement global tio/ctr routingSpencer E. Olson
Adds ability to use device-global names in command args, in particular cmd->start_arg (for NI_CtrArmStartTrigger), and cmd->scan_begin_arg or cmd->convert_arg (either is used to specify NI_CtrGate, with preference given to cmd->scan_begin_arg, if it is set). The actual arguments of cmd->start_arg are not fully checked against known register values for the particular devices because these are not documented or currently known. This follows the precedence of prior versions of the tio driver. Should these become known, they should be annotated in the route_values tables and the set of lines in ni_tio_cmdtest should be uncommented to allow the tests to be made. This patch also adds interface functions that allow routes for particular counter route destinations to be made/queried/unmade. This allows overseer modules to implement test_route, connect_route, and disconnect_route. As a part of these changes, various functions were cleaned up and clarified. These new interface functions allow direct writing/reading of register values. This is an example of exactly what the new device-global access was intended to solve: the old interface was not consistent with other portions of the ni_* drivers--it did not allow full register values to be given for various MUXes. Instead, the old interface _did_ abstract away some of the actual hardware from the underlying devices, but it was not consistent with any other NI hardware. Allowing the device-global identifiers to be used, the new patch provides for consistency across all ni_* drivers. One final note: these changes provide for backwards compatibility by allowing the older values to still be used in through the pre-existing kernel interfaces--though not in the new device-global test/dis/connect/route interfaces. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_mio_common: implement output selection of GPFO_{0, 1}Spencer E. Olson
Implement the ability to route various signals to NI_CtrOut(x) pin. This pin is also known as GPFO_{0,1} in the DAQ STC. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_mio_common: implement global pfi, rtsi routingSpencer E. Olson
Implement device-global config interface for ni_mio devices. In particular, this patch implements: INSN_DEVICE_CONFIG_TEST_ROUTE, INSN_DEVICE_CONFIG_CONNECT_ROUTE, INSN_DEVICE_CONFIG_DISCONNECT_ROUTE, INSN_DEVICE_CONFIG_GET_ROUTES for the ni mio devices. This means that the new abstracted signal/terminal names can be used to define signal routing with regards to the PFI terminals and RTSI trigger bus lines. This also adds ability to identify PFI and RTSI channels on the PFI and RTSI subdevices using the new device-global names. This does not change the values that are set for channel output selections using the subdevice interfaces--these still require direct register values. Annotates and updates tables of register values to reflect this new implementation status. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_mio_common: implement new routing for TRIG_EXTSpencer E. Olson
Use new signal routing capability for all comedi command *_src == TRIG_EXT options. This new interface allows the user specify signals and terminals as TRIG_EXT sources using a very consistent naming convention. Furthermore, the interface allows backwards compatibility to prior behavior of specifying register-level (or near register-level) values as *_arg options when *_src == TRIG_EXT. Annotates and updates tables of register values to reflect this new implementation status. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: add interface to ni routing table informationSpencer E. Olson
Adds interface and associated unittests for accessing/looking-up/validating the new ni routing table information. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_routing: Add NI signal routing infoSpencer E. Olson
See README for a thorough discussion of this content. Adds tables of all register values for routing various signals to various terminals on National Instruments hardware. This information is directly compared to and taken from register-level programming documentation and/or register-level programming examples as provided by National Instruments. Furthermore, this information was mostly compared (favorably) to the register values already used in the comedi drivers for NI hardware. Adds tables of valid routes for many devices. This information is not consistent from device to device, nor entirely consistent within device families. One additional major challenge is that this information does not seem to be obtainable in any programmatic fashion, neither through the proprietary NIDAQmx(-base) c-libraries, nor with register level programming, _nor_ through any documentation. In fact, the only consistent source of this information is through the proprietary NI-MAX software, which currently only runs on Windows platforms. A further challenge is that this information cannot be exported from NI-MAX, except by screenshot. The collection and maintenance of this information is somewhat tedious and requires frequent re-examination and comparison of NI-MAX and/or the NI-MHDDK documentation (register programming information) and NI-MHDDK examples. Tools are added with this patch to facilitate generating CSV files from the data tables. These CSV files can be used with a spreadsheet program to provide better visual comparision with screenshots gathered from NI-MAX. Tools are also added to regenerate the data tables from CSV content--this greatly enhances updating data tables with large changes (such as when adding devices). Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: add new device-global config interfaceSpencer E. Olson
Adds interface for configuring options that are global to all sub-devices. For now, only options to configure device-globally identified signal routes have been defined. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: add abstracted NI signal/terminal named constantsSpencer E. Olson
This change adds abstracted constants for National Instruments terminal/signal names. Some background: There have been significant confusions over the past many years for users when trying to understand how to connect to/from signals and terminals on NI hardware using comedi. The major reason for this is that the actual register values were exposed and required to be used by users. Several major reasons exist why this caused major confusion for users: 1) The register values are _NOT_ in user documentation, but rather in arcane locations, such as a few register programming manuals that are increasingly hard to find and the NI-MHDDK (comments in in example code). There is no one place to find the various valid values of the registers. 2) The register values are _NOT_ completely consistent. There is no way to gain any sense of intuition of which values, or even enums one should use for various registers. There was some attempt in prior use of comedi to name enums such that a user might know which enums should be used for varying purposes, but the end-user had to gain a knowledge of register values to correctly wield this approach. 3) The names for signals and registers found in the various register level programming manuals and vendor-provided documentation are _not_ even close to the same names that are in the end-user documentation. Similar confusion, albeit less, plagued NI's previous version of their own proprietary drivers. Earlier than 2003, NI greatly simplified the situation for users by releasing a new API that abstracted the names of signals/terminals to a common and intuitive set of names. In addition, this new API provided a much more common interface to use for most of NI hardware. The names added here mirror the names chosen and well documented by NI. These names are exposed to the user via the comedilib user library. By keeping the names in this format, in spite of the use of CamelScript, maintenance will be greatly eased and confusion for users _and_ comedi developers will be greatly reduced. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: tests: add unittest framework for comediSpencer E. Olson
Adds a framework for unittests for comedi drivers. It was certainly possible to write some unit tests before and test various aspects of a particular driver, but this framework makes this a bit easier and hopefully inspires more unittest modules to be written. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: comedi_test: implement INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTSSpencer E. Olson
Adds implementation of the new INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS instruction. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_pcidio: implement INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTSSpencer E. Olson
Adds implementation of the new INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS instruction. This patch also adds data for this implementation, based on spec sheets from NI. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_mio_common: implement INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTSSpencer E. Olson
Adds implementation of the new INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS instruction. This patch also adds data for digital subdevices that are streaming capable (within the ni_mio_* family). Mostly, only the m-series devices are capable of digital streaming. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: add facility to directly query subdevice timing constraintsSpencer E. Olson
Adds facility to directly query the hardware speed limits of subdevices, in particular for scan_begin and convert signals. This information can be critical for integrating comedi with other hardware modules, and also comedi modules together with software where software requires specific timing capabilities in order to properly coordinate multiple devices. Currently, comedi_command_test almost satisfies this need, but really only for when *_src == TRIG_TIMER. For *_src == TRIG_EXT, comedi_command_test does not help at all. For many subdevices, one might simply use *_src==TRIG_TIMER in command_test in order to determine these limits. For other subdevices, this tactic does not work since *_src == TRIG_TIMER might not be valid. There is also the possibility that the timing limits are different between the TRIG_TIMER and TRIG_EXT modes. Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-09staging: comedi: ni_mio_common: protect register write overflowSpencer E. Olson
Fixes two problems introduced as early as commit 03aef4b6dc12 ("Staging: comedi: add ni_mio_common code"): (1) Ensures that the last four bits of NISTC_RTSI_TRIGB_OUT_REG register is not unduly overwritten on e-series devices. On e-series devices, the first three of the last four bits are reserved. The last bit defines the output selection of the RGOUT0 pin, otherwise known as RTSI_Sub_Selection. For m-series devices, these last four bits are indeed used as the output selection of the RTSI7 pin (and the RTSI_Sub_Selection bit for the RGOUT0 pin is moved to the RTSI_Trig_Direction register. (2) Allows all 4 RTSI_BRD lines to be treated as valid sources for RTSI lines. This patch also cleans up the ni_get_rtsi_routing command for readability. Fixes: 03aef4b6dc12 ("Staging: comedi: add ni_mio_common code") Signed-off-by: Spencer E. Olson <olsonse@umich.edu> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-08-08staging: comedi: ni_mio_common: fix subdevice flags for PFI subdeviceIan Abbott
The PFI subdevice flags indicate that the subdevice is readable and writeable, but that is only true for the supported "M-series" boards, not the older "E-series" boards. Only set the SDF_READABLE and SDF_WRITABLE subdevice flags for the M-series boards. These two flags are mainly for informational purposes. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-08-01staging: comedi: drop serial2002 driverGreg Kroah-Hartman
There's not been any work on this driver since it was originally merged, and it really needs to be rewritten to use the serdev layer instead if people really need/want it. Reported-by: Christoph Hellwig <hch@lst.de> Cc: Ian Abbott <abbotti@mev.co.uk> Cc: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-16staging: comedi: comedi_fops: Shift assignment operator '=' to previous lineNishad Kamdar
Shift '=' assignment operator to the end of previous line to conform to preferred kernel style line wrapping. Issue reported by checkpatch CHECK. Signed-off-by: Nishad Kamdar <nishadkamdar@gmail.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>