Commit graph

134 commits

Author SHA1 Message Date
Al Viro 6131ffaa1f more file_inode() open-coded instances
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-02-27 16:59:05 -05:00
Ian Abbott b12da2e433 staging: comedi: correct error message in comedi_alloc_subdevice_minor()
`comedi_alloc_subdevice_minors()` currently prints a message about
running out of minor numbers board device files if it runs out of minor
device numbers.  Change it to complain about running out of minor device
numbers for subdevice files as these are in a different range, not
shared with those for board device files.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-02-07 17:17:17 -08:00
Ian Abbott da7185462e staging: comedi: don't return minor from comedi_alloc_subdevice_minor()
`comedi_alloc_subdevice_minor()` currently returns the allocated minor
device number on success.  This is not really of any interest to the
caller (in fact the return value is not even checked), so just return 0
on success.  If the caller really needs to know the allocated minor
device number it can look in `s->minor`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-02-07 17:17:16 -08:00
Ian Abbott cc400e185c staging: comedi: check s->async for poll(), read() and write()
Some low-level comedi drivers (incorrectly) point `dev->read_subdev` or
`dev->write_subdev` to a subdevice that does not support asynchronous
commands.  Comedi's poll(), read() and write() file operation handlers
assume these subdevices do support asynchronous commands.  In
particular, they assume `s->async` is valid (where `s` points to the
read or write subdevice), which it won't be if it has been set
incorrectly.  This can lead to a NULL pointer dereference.

Check `s->async` is non-NULL in `comedi_poll()`, `comedi_read()` and
`comedi_write()` to avoid the bug.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-02-05 11:23:32 -08:00
H Hartley Sweeten 4a79f73017 staging: comedi: remove 'comedi_autoconfig' module parameter
This module parameter is used to enable the auto config mechanism
in the comedi core. Most of the PCI, PCMCIA, and USB drivers have
been converted to use the auto config mechanism and will not attach
if it is disabled.

Since the 'comedi_autoconfig' parameter is defaulted to true, just
remove it so that the comedi drivers that use auto config will
always be able to attach.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-02-05 11:22:08 -08:00
Ian Abbott f65cc5447e staging: comedi: change comedi_alloc_subdevice_minor parameters
`comedi_alloc_subdevice_minor()` doesn't really need a parameter
pointing to a `struct comedi_device` as it can get this information from
the parameter pointing to a `struct comedi_subdevice`.  Just pass the
subdevice parameter.

Signed-by: Ian Abbott <abbotti@mev.co.uk>

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-02-03 17:43:28 -08:00
Ian Abbott 682b911938 staging: comedi: cleanup all board minors on module exit
The comedi core module optionally allocates some legacy board minor
devices on module load and cleans these up on module exit.  These are
used for manual configuration of comedi boards (for those low-level
comedi drivers that support manual configuration - mainly for ISA
boards).  Other board minor devices are created and destroyed
dynamically in response to bus device probe and remove requests.  The
ioctl used for manual configuration (attachment) and removal
(detachment) of devices is COMEDI_DEVCONFIG, but that works for any
board minor device, including those that were originally created
dynamically.

If the COMEDI_DEVCONFIG ioctl is used to manually detach an
automatically created and attached device, commit
7d3135af39 ("staging: comedi: prevent
auto-unconfig of manually configured devices") ensures that the board
minor will no longer be automatically detached and destroyed by a bus
device remove request.  From that point on the board minor behaves more
like one of the comedi "legacy" board minors.  (There would be some
justification for destroying the board minor instead, but I'd rather
leave that decision until removal of board minors has been
made safer than it currently is.)  Although the board minor behaves more
like a legacy board minor, it is not currently cleaned up on module
exit.  In fact, the module exit code will bug out because this board
minor has not been cleaned up.

Change comedi_cleanup_legacy_minors() (called from the module exit code,
and from the module init code on error) to clean up all board minors.
Rename the function to comedi_cleanup_board_minors() to reflect the
change in functionality.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-30 11:47:47 +01:00
Ian Abbott 754ab5c0e5 staging: comedi: disallow COMEDI_DEVCONFIG on non-board minors
Comedi has two sorts of minor devices:
(a) normal board minor devices in the range 0 to
COMEDI_NUM_BOARD_MINORS-1 inclusive; and
(b) special subdevice minor devices in the range COMEDI_NUM_BOARD_MINORS
upwards that are used to open the same underlying comedi device as the
normal board minor devices, but with non-default read and write
subdevices for asynchronous commands.

The special subdevice minor devices get created when a board supporting
asynchronous commands is attached to a normal board minor device, and
destroyed when the board is detached from the normal board minor device.
One way to attach or detach a board is by using the COMEDI_DEVCONFIG
ioctl.  This should only be used on normal board minors as the special
subdevice minors are too ephemeral.  In particular, the change
introduced in commit 7d3135af39 ("staging:
comedi: prevent auto-unconfig of manually configured devices") breaks
horribly for special subdevice minor devices.

Since there's no legitimate use for the COMEDI_DEVCONFIG ioctl on a
special subdevice minor device node, disallow it and return -ENOTTY.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-30 11:47:47 +01:00
Ian Abbott 104640606b staging: comedi: don't override read/write subdevice if not supported
For comedi devices that support asynchronous commands on some of their
subdevices, the comedi core creates extra device files for each of those
subdevices of the form "/dev/comedi%i_subd%i".  These use the same
comedi device as the corresponding "/dev/comedi%i" but override the
default "read" and "write" subdevice for the device.  Currently it
overrides both the read and write subdevice, but it only makes sense to
override the "read" subdevice if the subdevice supports "read" commands,
and to override the "write" subdevice if the subdevice supports "write"
commands.

In `comedi_alloc_subdevice_minor()`, only set `info->read_subdevice`
non-NULL if the subdevice has the `SDF_CMD_READ` flag set, and only set
`info->write_subdevice` non-NULL if the subdevice has the
`SDF_CMD_WRITE` flag set.  (`comedi_read_subdevice(info)` will use the
device's default read subdevice if `info->read_subdevice` is NULL.
`comedi_write_subdevice(info)` will use the device's default write
subdevice if `info->write_subdevice` is NULL.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-29 23:11:41 -05:00
H Hartley Sweeten 5b6cbd87d3 staging: comedi: comedi_fops: remove last forward declaration
There is still a forward declaration in this file for parse_insn().
Remove the need for it by moving do_insnlist_ioctl() down a bit.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-21 14:25:07 -08:00
Peter Huewe 24d8e51ef3 staging/comedi: Use bool initializations
Found with coccicheck.

The semantic patch that makes this output is available
in scripts/coccinelle/misc/boolinit.cocci.

More information about semantic patching is available at
http://coccinelle.lip6.fr/

Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-21 14:22:49 -08:00
H Hartley Sweeten 61c9fb0eb0 staging: comedi: comedi_buf: rename comedi_reset_async_buf()
For aesthetic reasons, rename this function to comedi_buf_reset(). This
makes all the asynchronous buffer functions have the same namespace.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:53:58 -08:00
H Hartley Sweeten d18431325b staging: comedi: deprecate loading firmware with comedi_config
All the comedi drivers have been converted to use the request_firmware()
hotplug interface. The COMEDI_DEVCONFIG ioctl support for passing the
firmware blob as 'aux_data' is no longer required.

Remove the feature and give the user a dev_warn message if it is
attempted.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:51:46 -08:00
Ian Abbott ba1bcf6f23 staging: comedi: (core): add comedi_dev_from_file_info()
Setting `info = comedi_file_info_from_minor(minor)` and `dev =
comedi_dev_from_minor(minor)` in the same function is a bit of a waste.
The latter function is just a call of the former followed by a
conditional return of an embedded pointer (`info->device`) or NULL.  The
former function uses a spin-lock which is where the wastfulness comes
in.

Move the "followed by a conditional return of an embedded pointer" part
into a new function `comedi_dev_from_file_info` and call this instead of
`comedi_dev_from_minor()` in the places where
`comedi_file_info_from_minor()` is also called.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-17 16:49:25 -08:00
Greg Kroah-Hartman 17cb3be61b Merge branch 'staging-linus' into staging-next
This is to get the comedi fixes, and resolve the issue in comdi_test.c
and comedi_fops.c that were caused by changes in both branches.

It also allows the fwserial driver changes to be applied, as they
required the fixes that are in staging-linus.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 15:17:52 -08:00
H Hartley Sweeten 90a35c15c5 staging: comedi: store the 'index' for each subdevice
Store the 'index' for each comedi_subdevice when they are initially
allocated by comedi_alloc_subdevice(). This allows removing the
pointer math in comedi_fops.c which is used to figure out the
index that user space uses to access the individual subdevices.

Fix the ni_mio_common driver so it also uses the 'index' instead
of doing the pointer math.

Also, remove a couple unused macros in the pcmda12, pcmmio, and
pcmuio drivers which also do the pointer math to figure out the
index.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:28:19 -08:00
H Hartley Sweeten 71cf6d3ee9 staging: comedi: comedi_fops: use kzalloc in comedi_alloc_subdevice_minor()
The hardware_device member of comedi_file_info is not set in this
function. Use kzalloc to make sure this pointer does not contain
invalid data.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:49 -08:00
H Hartley Sweeten a52840a98b staging: comedi: comedi_fops: cleanup comedi_mmap()
Use comedi_dev_from_minor() to simplify the return -ENODEV tests.

Change the (foo == NULL) tests to simply (!foo).

Use a local variable to hold a pointer to the async->buf_page_list[]
when doing the remap_pfn_range(). This cleans up the ugly line breaks
for the page_to_pfn(virt_to_page(...) operation.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:49 -08:00
H Hartley Sweeten 401d99de5c staging: comedi: comedi_fops: cleanup comedi_{read, write}_subdevice()
Flip the info->device tests so than the return NULL occurs last.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:49 -08:00
H Hartley Sweeten 9682e28c49 staging: comedi: comedi_fops: introduce comedi_is_subdevice_idle()
Introduce, and use, a helper to check the subdevice runflags to see if
it is not in error and not running.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:49 -08:00
H Hartley Sweeten c098c21a9d staging: comedi: comedi_fops: introduce comedi_is_subdevice_in_error()
Introduce, and use, a helper to check the subdevice runflags to see if
the SRF_ERROR flag is set.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:49 -08:00
H Hartley Sweeten ade1764ff5 staging: comedi: comedi_fops: don't export comedi_get_subdevice_runflags()
The subdevice runflags are protected with a spin_lock. Only the comedi
core should be accessing them directly.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:49 -08:00
H Hartley Sweeten f012463068 staging: comedi: use comedi_is_subdevice_running()
Use the helper function comedi_is_subdevice_running() instead of getting
the subdevice runflags and then masking the result.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:49 -08:00
H Hartley Sweeten e0dac318ee staging: comedi: comedi_fops: introduce comedi_is_subdevice_running()
Introduce a helper function that checks the subdevice runflags to
see if the subdevice is running a command.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:48 -08:00
H Hartley Sweeten 74120719a7 staging: comedi: comedi_fops: move comedi_get_subdevice_runflags()
For aesthetic reasons, move this function so its near
comedi_set_subdevice_runflags().

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:48 -08:00
H Hartley Sweeten bc252fd12c staging: comedi: comedi_fops: fix a number of sizeof(struct foo) forms
As mentioned in CodingStyle, the prefered form is:

	p = kmalloc(sizeof(*p), ...);

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:48 -08:00
H Hartley Sweeten 76cca89f4b staging: comedi: comedi_fops: move comedi_cleanup_legacy_minors()
This function is only called by the module_{init,exit} functions. For
aesthetic reasons, move it near them.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:48 -08:00
H Hartley Sweeten 91fa0b0c96 staging: comedi: comedi_fops: move the module_{init, exit} functions to EOF
For aesthetic reasons, move the module_{init,exit} functions to the end
of the file.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:48 -08:00
H Hartley Sweeten a5787824c0 staging: comedi: comedi_fops: move the MODULE_* information to EOF
For aesthetic reasons, move the MODULE_* information to the end of
the file.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:48 -08:00
H Hartley Sweeten 2714b019fd staging: comedi: comedi_fops: remove the goto's in comedi_write()
Use comedi_dev_from_minor() to simplify the return -ENODEV tests.

Cleanup the sanity checking a bit and remove the need for the goto's
when returning an initial error condition.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:48 -08:00
H Hartley Sweeten 5c87fef53c staging: comedi: comedi_fops: remove the goto's in comedi_read()
Use comedi_dev_from_minor() to simplify the return -ENODEV tests.

Cleanup the sanity checking a bit and remove the need for the goto's
when returning an initial error condition.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:47 -08:00
H Hartley Sweeten ca081b1d7e staging: comedi: comedi_fops: cleanup comedi_poll()
Consolidate the local variables 'read_subdev' and 'write_subdev' into a
single local variable 's'.

Use comedi_dev_from_minor() to simplify the return -ENODEV tests.

Use a goto in the !dev->attached test so that the mutex_unlock() call
is in a common place.

Cleanup the formating of the || in the read and write subdevice poll
code.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:47 -08:00
H Hartley Sweeten 0e700923bf staging: comedi: comedi_fops: cleanup do_devinfo_ioctl()
Consolidate the local variables 'read_subdev' and 'write_subdev' into a
single local variable 's'.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:47 -08:00
H Hartley Sweeten 7d8a25674f staging: comedi: comedi_fops: rename comedi_{read,write}_subdevice()
The 'get' usually implies increasing a reference count of an object.
These function return a pointer but do not do any reference counting.
For aesthetic reasons, rename the functions to better represent what
they do.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:47 -08:00
H Hartley Sweeten ed69335c72 staging: comedi: comedi_fops: rename comedi_get_device_file_info()
The 'get' usually implies increasing a reference count of an object.
This function returns a pointer but does not do any reference counting.
For aesthetic reasons, rename the function to better represent what
its doing.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:47 -08:00
H Hartley Sweeten cd6b7636e9 staging: comedi: comedi_fops: rename struct comedi_device_file_info
For aesthetic reasons, rename this struct to comedi_file_info. It's
a bit shorter and allows fixing some of the ugly line breaks used
to keep the lines < 80 chars.

Also, consistently use the local variable name 'info' instead of the
longer 'dev_file_info' to also fix some ugly line breaks.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:47 -08:00
H Hartley Sweeten e79c8d2100 staging: comedi: don't expose struct comedi_device_file_info
This structure is only used in comedi_fops.c as part of handling
the file operations and sysfs files. Remove it's defenition from
comedidev.h so it's not exposed to the comedi drivers.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:47 -08:00
H Hartley Sweeten 87b1ad7a80 staging: comedi: comedi_fops: don't export comedi_get_device_file_info()
This function is now only used in comedi_fops.c and does not need
to be exported.

Make it static and move it to avoid forward declarations.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:46 -08:00
H Hartley Sweeten 4da5fa9a43 staging: comedi: use comedi_dev_from_minor()
Remove the need to export comedi_get_device_file_info() by using the
new helper comedi_dev_from_minor(). This will also allow us to make
the comedi_device_file_info struct private.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:46 -08:00
H Hartley Sweeten 85104e9b40 staging: comedi: comedi_fops: introduce comedi_dev_from_minor()
A number of functions have to call comedi_get_device_file_info()
to get the comedi_device_file_info pointer for a given minor. That
pointer is only used to get the actual comedi_device pointer for
the minor.

Introduce a new helper function, comedi_dev_from_minor(), to simplify
this operation. This will also allow us to make the comedi_device_file_info
struct private.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:46 -08:00
H Hartley Sweeten 43bd33f224 staging: comedi: don't expose comedi_get_{read, write}_subdevice
These two inline helper function in comedidev.h are only used in
comedi_fops.c. They return information that should only be used
by the comedi core.

Move both functions to comedi_fops.c so they aren't exposed to
the comedi drivers. Also, remove the inline tag and let the
compiler figure it out.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:46 -08:00
H Hartley Sweeten 2aae0076c9 staging: comedi: comedi_fops: remove forward declarations
Move a couple of the functions to remove the need for the forward
declarations.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:25:46 -08:00
Ian Abbott 7d3135af39 staging: comedi: prevent auto-unconfig of manually configured devices
When a low-level comedi driver auto-configures a device, a `struct
comedi_dev_file_info` is allocated (as well as a `struct
comedi_device`) by `comedi_alloc_board_minor()`.  A pointer to the
hardware `struct device` is stored as a cookie in the `struct
comedi_dev_file_info`.  When the low-level comedi driver
auto-unconfigures the device, `comedi_auto_unconfig()` uses the cookie
to find the `struct comedi_dev_file_info` so it can detach the comedi
device from the driver, clean it up and free it.

A problem arises if the user manually unconfigures and reconfigures the
comedi device using the `COMEDI_DEVCONFIG` ioctl so that is no longer
associated with the original hardware device.  The problem is that the
cookie is not cleared, so that a call to `comedi_auto_unconfig()` from
the low-level driver will still find it, detach it, clean it up and free
it.

Stop this problem occurring by always clearing the `hardware_device`
cookie in the `struct comedi_dev_file_info` whenever the
`COMEDI_DEVCONFIG` ioctl call is successful.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-07 14:22:37 -08:00
H Hartley Sweeten 1b6c710e2a staging: comedi: remove unnecessary '#define __NO_VERSION__'
This define is no longer required for multi-file modules.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-27 09:16:38 -08:00
Ian Abbott b0a2b6d8ac staging: comedi: check data length for INSN_CONFIG_DIGITAL_TRIG
The newly defined format for the `INSN_CONFIG_DIGITAL_TRIG`
configuration instruction expects 6 data values.  Check the length in
`check_insn_config_length()` before calling the comedi subdevice's
`insn_config` handler.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-14 16:25:08 -08:00
Ian Abbott c8cad4c89e staging: comedi: fix memory leak for saved channel list
When `do_cmd_ioctl()` allocates memory for the kernel copy of a channel
list, it frees any previously allocated channel list in
`async->cmd.chanlist` and replaces it with the new one.  However, if the
device is ever removed (or "detached") the cleanup code in
`cleanup_device()` in "drivers.c" does not free this memory so it is
lost.

A sensible place to free the kernel copy of the channel list is in
`do_become_nonbusy()` as at that point the comedi asynchronous command
associated with the channel list is no longer valid.  Free the channel
list in `do_become_nonbusy()` instead of `do_cmd_ioctl()` and clear the
pointer to prevent it being freed more than once.

Note that `cleanup_device()` could be called at an inappropriate time
while the comedi device is open, but that's a separate bug not related
to this this patch.

Cc: stable@vger.kernel.org
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-09-21 09:29:53 -07:00
Ian Abbott 5d06e3df28 staging: comedi: don't dereference user memory for INSN_INTTRIG
`parse_insn()` is dereferencing the user-space pointer `insn->data`
directly when handling the `INSN_INTTRIG` comedi instruction.  It
shouldn't be using `insn->data` at all; it should be using the separate
`data` pointer passed to the function.  Fix it.

Cc: stable <stable@vger.kernel.org>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-09-19 11:26:13 +01:00
Ian Abbott dc881f294e staging: comedi: fix sparse warning in do_devconfig_ioctl()
For the COMEDI_DEVCONFIG ioctl, the user application may embed a pointer
to firmware data within a designated element (or two elements for 64-bit
pointers) of the `options[]` array in the `struct comedi_devconfig`.
`do_devconfig_ioctl()` calls `comedi_aux_data()` to extract the pointer
value.  It needs to be treated as a `__user` pointer so the firmware
data can be copied into kernel memory, so cast the result of
`comedi_aux_data()` to avoid a "sparse" warning.  This is not ideal but
`comedi_aux_data()` is called elsewhere in a wholly kernel memory
context so we can't just change its return type to include the `__user`
tag.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-09-19 11:26:12 +01:00
H Hartley Sweeten 95bc359f98 staging: comedi: comedi_fops: cast the cmd->chanlist to the correct address space
Rename 'chanlist_saver' to 'user_chanlist' to avoid confusion that
it's actually a __user *.

The chanlist pointer in comedi_cmd is still a user space pointer when
the comedi_cmd is copied with copy_from_user() in do_cmd_ioctl() and
do_cmdtest_ioctl(). This pointer needs to be cast when it is saved in
user_chanlist in order to preserve its address space.

The copy_from_user() call to copy the chanlist to the kernel space
comedi_command requires the second parameter to be a __user pointer.
Use the correctly cast user_chanlist instead of cmd->chanlist.

Before the comedi_cmd is copied back to user space, the saved
user_chanlist pointer is restored. Cast the user_chanlist again so
that the address space matches the comedi_cmd.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Acked-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-09-19 09:36:45 +01:00
H Hartley Sweeten f8348677b1 staging: comedi: comedi_fops: rename user_cmd in do_cmdtest_ioctl
This local variable is used to hold the comedi_cmd that is passed
to the kernel as the argument to the COMEDI_CMDTEST ioctl. Its filled
in with a copy_from_user() call. The name 'user_cmd' is a bit
confusing since it's actually kernel data.

Rename the local variable to 'cmd' to avoid the confusion.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Acked-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-09-19 09:36:45 +01:00