Commit Graph

414604 Commits

Author SHA1 Message Date
Gokulnath Avanashilingam 8b80448d47 staging: bcm: fixed warning about no and prohibited space in InterfaceIdleMode.c.
This patch fixes all the warning related to spacing issues
found by checkpatch.pl script in InterfaceIdleMode.c

Signed-off-by: Gokulnath Avanashilingam <Gokulnath.Avanashilingam@in.bosch.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 11:47:42 -08:00
Gokulnath Avanashilingam e42ff08dd9 staging: bcm: using time_after and time_before in InterfaceIdleMode.c
Used the time_after and time_before insted of comparing
the jiffies directly.This will fix the warnings and errors
found by the checkpatch.pl script.

Signed-off-by: Gokulnath Avanashilingam <Gokulnath.Avanashilingam@in.bosch.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 11:47:42 -08:00
Gokulnath Avanashilingam 786bdddc36 staging: bcm: line over 80 characters in InterfaceIdleMode.c
Fixed all the line over 80 characters warning found by
checkpatch.pl script.

Signed-off-by: Gokulnath Avanashilingam <Gokulnath.Avanashilingam@in.bosch.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 11:47:42 -08:00
Gokulnath Avanashilingam d52dd37e19 staging: bcm: Remove Developer Debug prints in InterfaceIdleMode.c
Removed the developer debug prints BCM_DEBUG_PRINT()
as per the TODO list, also removed braces for the
if-statement to match coding style

Signed-off-by: Gokulnath Avanashilingam <Gokulnath.Avanashilingam@in.bosch.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 11:47:42 -08:00
Wei Yongjun a7c7eb03fd staging: sep: add missing destroy_workqueue() in sep_crypto.c
Add the missing destroy_workqueue() before return from
sep_crypto_setup() and sep_crypto_takedown().

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 11:45:09 -08:00
Wei Yongjun b751bc77be staging: lustre: fix return value check in capa_hmac()
In case of error, the function crypto_alloc_hash() returns ERR_PTR()
and never returns NULL. The NULL test in the return value check
should be replaced with IS_ERR().

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 11:45:09 -08:00
Andreas Frembs a3c383c5c3 rlt8192e: Removing unused defines in rltlib_endianfree.h
Checkpatch mentioned that these macros should be defined with a 'do {...} while(0)' statement.
So we used grep to find all files using these macros and we found out that these macros were only used
in rtl819x_Qos.h, in the defines we removed before.
Since the macros are not used anywhere else we decided to remove them from the driver.

Signed-off-by: Andreas Frembs <andreas.frembs@studium.uni-erlangen.de>
Signed-off-by: Matthias Schoepe <matthias.schoepe@studium.uni-erlangen.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 11:41:28 -08:00
Andreas Frembs a1ca601aa2 rtl8192e: Removing unused defines in rtl819x_Qos.h
In rtl819x_Qos.h there were several macros defined but never used.
So we removed this macros.

Signed-off-by: Andreas Frembs <andreas.frembs@studium.uni-erlangen.de>
Signed-off-by: Matthias Schoepe <matthias.schoepe@studium.uni-erlangen.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 11:41:28 -08:00
Andreas Frembs 6e925e1991 rtl8192e: Fixing checkpatch errors
This patch fixes the following checkpatch errors from rtllib_endianfree.h:
 - ERROR: Macros with complex values should be enclosed in parenthesis

Signed-off-by: Andreas Frembs <andreas.frembs@studium.uni-erlangen.de>
Signed-off-by: Matthias Schoepe <matthias.schoepe@studium.uni-erlangen.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 11:41:28 -08:00
Michael Hoefler 382d277b38 silicom: remaining checkpatch issues in bypass.c
In this patch we fix some "logical" errors in bypass.c of the silicom bypass
driver (in staging).

Checkpatch complains about the following errors:
 - unnecessary forward declarations in a source file
 - assignment in if condition

In addition to that the __init and __exit macros were missing at the init and
cleanup function.

There are still two warnings left for this file related to too many leadingtabs
at nested blocks. I did not touch this issue becasue the code needs really some
refactoring. And since i do not have the appropriate hardware to test the code,
i do not change the functionality in any way.

Signed-off-by: Michael Hoefler <michael.hoefler@studium.uni-erlangen.de>
Signed-off-by: Christoph Kohl <christoph.kohl@t-online.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 09:04:49 -08:00
Michael Hoefler 6618b75069 silicom: fix coding style issues in bypass.c
This patch improves bypass.c (in staging) in terms of coding style. This
includes different issues some of them mentioned by checkpatch:

 - a c++ one line comment
 - parenthesis at return statementes
 - multiple definitions in one line
 - missing braces according to the style guide

Signed-off-by: Michael Hoefler <michael.hoefler@studium.uni-erlangen.de>
Signed-off-by: Christoph Kohl <christoph.kohl@t-online.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 09:04:49 -08:00
Michael Hoefler 74552f1b2f silicom: fix whitespace issues in bypass.c
This patch addresses several problems in bypass.c found by checkpatch.
Furthermore it removes/adds some empty lines to make the code more readable.

The following problems are fixed:
 - line over 80 characters
 - space after logical operator !
 - spaces instead of tabs
 - missing empty line after local declarations
 - empty line after {

The empty line issues were not discovered by checkpatch but in my opinion these
changes make perfect sense in terms of readability.

Signed-off-by: Michael Hoefler <michael.hoefler@studium.uni-erlangen.de>
Signed-off-by: Christoph Kohl <christoph.kohl@t-online.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 09:04:49 -08:00
Larry Finger a322b495fa staging: r8188eu: Replace wrappers ODM_StallExecution, ODM_delay_us, and rtw_udelay_os
Each instance may bre replaced by udelay

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Larry Finger 4063642bd4 staging: r8188eu: Replace wrappers ODM_delay_ms() and rtw_mdelay_os() with a simple mdelay
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Larry Finger 0da46e6bb1 staging: r8188eu: Replace wrappers ODM_sleep_ms() and rtw_msleep_os() with a simple msleep
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Larry Finger c01fb49636 staging: r8188eu: Replace rtw_get_current_time() with jiffies
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Larry Finger 03f4a957e6 staging: r8188eu: Remove calls to _rtw_spinlock_free
This wrapper does nothing on Linux. When calls to it were removed, a number of
routines became empty and could also be removed.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Larry Finger f214e521d9 staging: r8188eu: Remove wrapper around spin_lock_init
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Larry Finger 597794f53e staging: r8188eu: Remove wrappers around spin_unlock_irqrestore
Again there are two - _exit_critical() and _exit_critical_ex().

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Larry Finger f937886ba9 staging: r8188eu: Remove wrappers for spin_lock_irqsave
There are two such wrappers - _enter_critical() and _enter_critical_ex().

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Larry Finger e02bcf6126 staging: r8188eu: Remove wrapper around spin_unlock_bh
With this change, a number of variables for storing flags are no longer used.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Larry Finger 7057dcb3af staging: r8188eu: Remove wrapper around spin_lock_bh
Some comment lines that mentioned spin_lock_bh() are also removed.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Larry Finger dfa5e81e59 staging: r8188eu: Remove pointless thread_exit macro
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:57:45 -08:00
Lidza Louina 0c5b5632d2 staging: dgap: uses kzalloc for allocating memory
Originally, this driver created it's own allocating
function. This patch removes that function and calls
kzalloc directly.

This patch affects:
 - driver.c
 - driver.h
 - fep5.c
 - tty.c

Signed-off-by: Lidza Louina <lidza.louina@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:54:46 -08:00
stalinsrinivasan.s f0dcc9fa42 staging: dgnc: fix checkpatch.pl usage of comparison with jiffies
This is a patch to the dgnc_cls.c file that fixes up comparison with
jiffies usage warning found by the checkpatch.pl tool

Signed-off-by: S. Stalin Srinivasan <stalinsrinivasan.s@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:54:46 -08:00
stalinsrinivasan.s 9979ef7d73 staging: dgnc: fix checkpatch.pl usage of volatile.
This is a patch to the dgnc_cls.c file that fixes up volatile usage
warning found by the checkpatch.pl tool

Signed-off-by: S. Stalin Srinivasan <stalinsrinivasan.s@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:54:46 -08:00
stalinsrinivasan.s cb3714a6b0 staging: dgnc: fix 80 characters per line limitation and code indent warnings.
This is a patch to the dgnc_cls.c file that
fixes up 80 characters per line and code indent
warnings found by the checkpatch.pl tool.

Signed-off-by: S. Stalin Srinivasan <stalinsrinivasan.s@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-20 08:54:46 -08:00
John Stultz 07300f43d6 ion_test: Add compat_ioctl support (v2)
Prior to subitting this, Colin reworked the compat_ioctl support
for the ion_test driver, moving the structure to be the same size
on both 32 and 64 bit architectures.

Two small things were left out. The compat_ioctl ptr assignment,
and the fact that despite having uniform sized types in the
structure, the structure pads out to different sizes on different
arches.

This patch resolves this issue by adding a padding entry after
the write flag, and adding the compat_ioctl ptr.

Changes in v2:
- Add a padding int rather then making write a u64

Acked-by: Colin Cross <ccross@android.com>
Cc: Android Kernel Team <kernel-team@android.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-19 16:10:25 -08:00
Masanari Iida 364014fda8 staging: dgap: Fix trailing whitespace in dgap_trace.c
This patch fixed trailing whitespace found by
checkpatch.pl within dgap_trace.c

Signed-off-by: Masanari Iida <standby24x7@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-19 10:27:13 -08:00
Gokulnath A b3a53885b2 staging: bcm: line over 80 characters in InterfaceDld.c
Fixed all the line over 80 characters warning found by
checkpatch.pl script.

Signed-off-by: Gokulnath A <Gokulnath.Avanashilingam@in.bosch.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-18 16:24:17 -08:00
Gokulnath A 8f5157bf37 staging:bcm: Removed developer debug prints in InterfaceDld.c
Removed the developer debug prints BCM_DEBUG_PRINT()
as per the TODO list, also removed braces for the
if-statement to match coding style

Signed-off-by: Gokulnath A <Gokulnath.Avanashilingam@in.bosch.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-18 16:24:17 -08:00
Gary Rookard 2d3fd5cabb Staging: bcm: DDRInit: fixed up some commenting issues.
I have deleated some unintelligible comments, and made a
few minor white space corrections.

Signed-off-by: Gary Alan Rookard
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-18 16:22:11 -08:00
Masanari Iida 258726b350 staging: dgap: Fix trailing whitespace in dgap_tty.c
This patch fixed "ERROR:trailing whitespace
found by checkpatch.pl within dgap_tty.c

Signed-off-by: Masanari Iida <standby24x7@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-18 16:21:13 -08:00
Masanari Iida ebca68f69d staging: dgap: Fix trailing whitespace in downld.c
This patch fix "ERROR: trailing whitespace found by
checkpatch.pl, whithin downld.c

Signed-off-by: Masanari Iida <standby24x7@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-18 16:20:37 -08:00
Aaron Sierra 7e4290c6db vme_user: Use __u64 and __u32 in userspace structs
Signed-off-by: Aaron Sierra <asierra@xes-inc.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-18 16:20:13 -08:00
Aaron Sierra 89b1cc2dcb vme_user: Enable compat_ioctl for mixed environment
Now that the VME userspace API structures compile to a consistent size
in mixed environments (32-bit userspace and 64-bit kernel), enable the
.compat_ioctl to allow ioctls to execute in this environment.

Signed-off-by: Aaron Sierra <asierra@xes-inc.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-18 16:20:12 -08:00
Gary Rookard c891d80318 Staging: bcm: DDRInit: fixed issues w/ commenting.
removed C99 comments to follow the linux kernel coding style
thus fixing checkpatch errors respectfully.

Signed-off-by: Gary Alan Rookard <garyrookard@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 17:17:57 -08:00
John Stultz 6a72a700f4 staging: ion: Avoid using rt_mutexes directly
RT_MUTEXES can be configured out of the kernel, causing compile
problems with ION.

To quote Colin:
"rt_mutexes were added with the deferred freeing feature.  Heaps need
to return zeroed memory to userspace, but zeroing the memory on every
allocation was causing performance issues.  We added a SCHED_IDLE
thread to zero memory in the background after freeing, but locking the
heap from the SCHED_IDLE thread might block a high priority allocation
thread for a long time.

The lock is only used to protect the heap's free_list and
free_list_size members, and is not held for any long or sleeping
operations.  Converting to a spinlock should prevent priority
inversion without using the rt_mutex.  I'd also rename it to free_lock
to so it doesn't get used as a general heap lock."

Thus this patch converts the rt_mutex usage to a spinlock and
renames the lock free_lock to be more clear as to its use.

I also had to change a bit of logic in ion_heap_freelist_drain()
to safely avoid list corruption.

Acked-by: Colin Cross <ccross@android.com>
Cc: Android Kernel Team <kernel-team@android.com>
Reported-by: Jim Davis <jim.epost@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 17:16:51 -08:00
Matthias Wirth 7dcfee65a1 rtl8188eu: remove unused code
These two macros needed reformatting but as they are not used anywhere we
just removed them.

Signed-off-by: Matthias Wirth <matthias.wirth@gmail.com>
Signed-off-by: Lukas Senger <lukas@fridolin.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 17:16:51 -08:00
Matthias Wirth 282956c606 rtl8188eu: fix coding style
Signed-off-by: Matthias Wirth <matthias.wirth@gmail.com>
Signed-off-by: Lukas Senger <lukas@fridolin.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 17:16:51 -08:00
Matthias Wirth f8d8f6f268 rtl8188eu: fix whitespace and indentation
Signed-off-by: Matthias Wirth <matthias.wirth@gmail.com>
Signed-off-by: Lukas Senger <lukas@fridolin.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 17:16:51 -08:00
Eli Billauer 9340e9dc9d staging: xillybus: Return -EIO if *_iomap fails, instead of 0
This patch replicates the correction made by Wei Yongjun on a second
occurrence of the same bug.

The first correction was in commit 8eec455551.

Bug fixed: The error code was not set, so the error condition wasn't reflected
in the return value.

Reported-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Eli Billauer <eli.billauer@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 17:07:13 -08:00
Alan 2d32927127 usbip: Fix sscanf handling
Scan only to the length permitted by the buffer

One of a set of sscanf problems noted by Jackie Chang

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 17:07:13 -08:00
Aaron Sierra 66a01f1158 vme_user: Update API to work in mixed environments
This patch updates the vme_master and vme_slave structures to use
types with well defined size and to prevent the compiler from
inserting padding (between enable and vme_addr for one).

The original vme_master and vme_slave structs would be different
sizes and have different layouts depending on whether they were built
for a 32-bit or 64-bit system.

On x86 it is possible to have a 32-bit userspace and a 64-bit kernel.
In this type of environment, the userspace and kernel vme_user APIs
would disagree and prevent ioctls from executing (based on ioctl
signatures from _IOR and _IOW).

Signed-off-by: Aaron Sierra <asierra@xes-inc.com>
Acked-by: Martyn Welch <martyn.welch@ge.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 17:06:19 -08:00
Aaron Sierra c326cc023e vme: Convert VME core to register as a subsystem
Previously, VME bridge support was treated as any other driver (using
module_init() macro), but if VME bridge and vme_user (staging) drivers
were compiled into the kernel, then vme_user would attempt to register
itself before the VME core support had been loaded. This would result
in a kernel panic.

The load order of these built-in drivers is based on the order in which
drivers/staging/vme and driver/vme are compiled.

This patch changes the VME core driver to use the subsys_initcall()
macro which ensures that it is loaded before all other VME drivers
regardless of the order in which they are compiled.

Tested-by: Aaron Sierra <asierra@xes-inc.com>
Signed-off-by: Martyn Welch <martyn.welch@ge.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 17:06:19 -08:00
Bernd Porr e56b140105 staging: comedi: fix result of memdup_user for user chanlist
If the channel list is not set in userspace we get an error at
PTR_ERR(async->cmd.chanlist). However, do_become_nonbusy(dev, s) cleans
up this pointer which causes a kernel ooops. Setting the channel list in
async to NULL and checking this in do_become_nonbusy prevents the oops.

[Ian Abbott] Also do the same for the chanlist allocated in
do_cmdtest_ioctl().

Signed-off-by: Bernd Porr <mail@berndporr.me.uk>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 13:10:40 -08:00
Masanari Iida b163970fa5 staging: keucr: Fix typo in keucr driver
Correct spelling typo in comment and printk.

Signed-off-by: Masanari Iida <standby24x7@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 13:10:40 -08:00
Malcolm Priestley 7387f438e5 staging: vt6656: clean up CARDbSetMediaChannel.
White space and commented out code.

Camel case clean up.
pDevice -> priv
uConnectionChannel -> connection_channel

Signed-off-by: Malcolm Priestley <tvboxspy@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 13:10:40 -08:00
Ian Abbott 1363e4fb4f staging/comedi: bug fix for module usage count on device removal
When a dynamically created comedi device is being automatically removed
by a call to `comedi_auto_unconfig()` from the lower level driver,
`comedi_device_cleanup()` is called to perform the detachment from the
lower level driver.  If the comedi device is open at the time,
`dev->use_count` will be the the number of outstanding opens.  The
function currently decrements the the module counts of the "comedi"
module and the low-level driver module by this amount and reduces
`dev->use_count` to zero.  There are various problems with this as the
`release` file operation handler `comedi_close()` also decrements
`dev->use_count` and decrements the module usage counts.  This means
that `dev->use_count` and the module counts can end up negative.

Also, the assumed one-to-one relationship between the file open count
and the low-level module usage count is invalid and can get screwed up.
We only want to stop the low-level module being unloaded while a comedi
device using the module has an open file object.

Also, there is no need to manipulate the module count of the core
"comedi" module at all since the comedi module is the owner of the file
operations structure and the system will not unload the module while
there are open file objects using it.

Correct the bugs and simplify as follows:

1. Get rid of the module count manipulations of the core "comedi" module
(`THIS_MODULE`) altogether.

2. Don't alter `dev->use_count` in `comedi_device_cleanup()` as it
should only be altered by the `open` and `release` file operation
handlers `comedi_open()` and `comedi_close()`.

3. Increment the low-level module count for the following reasons:

  a) In `comedi_open()` if the open count was zero and the comedi device
     is attached to the low-level driver.
  b) When the `COMEDI_DEVCONFIG` ioctl is used to manually attach an
     unattached comedi device to a low-level driver.  The open count
     will be greater than zero at this time.  The actual increment of
     the low-level module count is already done by
     `comedi_device_attach()`.

4. Decrement the low-level module count for the following reasons:

  a) In `comedi_close()` if the open count was 1 and the comedi device
     is attached to the low-level driver.
  b) In `comedi_device_cleanup()` (called via `comedi_auto_unconfig()`
     --> `comedi_release_hardware_device()` -->
     `comedi_free_board_dev()` when the comedi device is automatically
     unconfigured due to action by the low-level driver) if the device
     was attached (which it should be) and open count was non-zero
     (greater than zero).
  c) When the `COMEDI_DEVCONFIG` ioctl is used to manually detach the
     comedi device from the low-level driver.  The open count will be
     greater than zero at this time.

The open count should never go negative.  Parts 3 and 4 ensure that the
low-level module usage count is incremented on entering the state where
the comedi device is attached to the low-level driver AND the open count
is greater than zero, and is decremented on leaving that state.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 13:09:43 -08:00
Ian Abbott 8f988d8784 staging/comedi: keep reference to class device after destroyed
When a dynamically allocated `struct comedi_device` gets automatically
unconfigured by a call to `comedi_auto_unconfig()` from a lower-level
driver's bus removal function (e.g. when a USB device is disconnected),
the class device in `dev->class_dev` (where `dev` points to the `struct
comedi_device`) is destroyed by a call to `device_destroy()` that
matches a previous call to `device_create()`.

However, if the `struct comedi_device` is still associated with an open
file object, the now invalid `dev->class_dev` pointer may still be
passed to `dev_printk()` (via `dev_dbg()` etc.), producing bogus output
or worse.

To fix this, call `get_device()` on the class device if
`device_create()` was successful.  Add a matching call to `put_device()`
in `comedi_dev_kref_release()` when the `struct comedi_device` is freed.
The calls to `dev_dbg()` etc. after the call to `device_destroy()` will
still produce valid output, although the device will have been
unregistered in sysfs.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-12-17 13:09:43 -08:00