mmc: core: Fix possbile memory leak

Fix possible memory leak detected by kmemleak:

unreferenced object 0xc0f80f00 (size 64):
  comm "swapper/0", pid 1, jiffies 4294937508 (age 82.980s)
  hex dump (first 32 bytes):
    6d 6d 63 30 5f 64 65 74 65 63 74 00 72 79 2e 68  mmc0_detect.ry.h
    00 07 00 00 68 77 63 61 70 2e 68 00 02 00 00 70  ....hwcap.h....p
  backtrace:
    [<c010a1fc>] __kmalloc+0x164/0x220
    [<c01e1630>] kvasprintf+0x38/0x58
    [<c01e1668>] kasprintf+0x18/0x24
    [<c02fcf60>] mmc_alloc_host+0x114/0x1b4
    [<c0311c84>] msmsdcc_probe+0xc14/0x1fd8
    [<c022b40c>] platform_drv_probe+0x14/0x18
    [<c022a144>] driver_probe_device+0x144/0x334
    [<c022a394>] __driver_attach+0x60/0x84
    [<c022884c>] bus_for_each_dev+0x4c/0x78
    [<c0229720>] bus_add_driver+0xd0/0x250
    [<c022a884>] driver_register+0x9c/0x128
    [<c00086bc>] do_one_initcall+0x90/0x160
    [<c06d1904>] kernel_init+0xe8/0x1a4
    [<c000ee4c>] kernel_thread_exit+0x0/0x8
    [<ffffffff>] 0xffffffff

Change-Id: I3b29d71463af849a072cabbe56637adf6db6d0da
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
net: usbnet: Undo double reservation

This reserves twice if we're not in raw IP mode. Drop it.

Change-Id: I7d4ce53c938e809e4e63d08188cb2e9d03f93dfa
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
USB: ci13xxx_udc: Don't flush and disable all endpoints during disconnect

Flushing and disabling all endpoints during disconnect in controller
driver is simply wasteful and unnecessary.  Flushing endpoints before
notifying disconnect to composite driver will have side effects too.
The active endpoints will be disabled by function drivers when they
notified about disconnect.

The current code use 100 msec timeout for flush operation.  If controller
driver flush and disable all endpoints, the worst case timeout will be
added up to several seconds.  This is leading to watch dog timeout.

CRs-Fixed: 431623
Change-Id: If6a2e87006cda367c2eb4def616e9672e13eadf5
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
USB: ci13xxx_udc: Fix possible NULL pointer dereference

Don't access dev->platform_data before checking dev against NULL.

CRs-fixed: 440043
Change-Id: Ia891720b926d26a46a044e688b64ac4e3cda73e2
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
USB: ci13xxx_udc: Add support for larger ( > 16K) length USB requests

The maximum recommended transfer size of a device transfer descriptor(dTD)
is 16K bytes.  The current code limits the USB request length to 16K bytes.
Add support for larger length USB requests by spanning them into multiple
dTD.  Remove the special handling of zero length packet termination and use
multi dTD logic to achieve the same.

The "QUEUE" and "DEBUG" event messages are slightly modified to accommodate
request pointer, actual length and original length.  Update sysfs file
implementation to print all dTD for any given USB request.

CRs-Fixed: 429212
Change-Id: If3fbb986c84ac9d138429c624a4c73ecee943ce5
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
USB: ci13xxx_udc: Add module param to enable streaming mode

The streaming mode is disabled by default for ci13xxx_msm.  Add
a module param to enable streaming.  This module param overrides
flag.

This allows user space to enable streaming mode for selected USB
compositions.

CRs-Fixed: 429212
Change-Id: I9ee76841d7de9797452090e29d00d09385024ae5
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
USB: ci13xxx_udc: Avoid flushing endpoint twice during disable

The ep_disable() function nukes all pending requests before
disabling the endpoint in hardware.  The endpoint is flushed
during nuking.  Don't flush the endpoint again.

CRs-Fixed: 445916
Change-Id: Ib330c67b360b448ec524e6ef0e8c040f04fdf0b8
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
USB: ci13xxx_udc: Don't flush inactive endpoints

The endpoint must be flushed prior to retiring pending requests.
This is done during disabling an endpoint.  Don't flush an endpoint
if there are no pending requests.  According databook flushing
endpoint may take large amount of time.  This optimization will
make USB disconnect/reset processing a little bit faster.

CRs-Fixed: 445916
Change-Id: I035b624dbac4529bbe33a67f9e7e1916d4772d6f
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
USB: ci13xxx_udc: Skip flushing endpoints upon failure

Flushing an endpoint involve polling ENDPTFLUSH and ENDPTSTAT
registers.  The worst case timeout is 100 msec for each endpoint.
The reason for failure is unknown.  When flushing an endpoint
fails, successive flushing of remaining endpoints are also failing.
Hence skip flushing remaining endpoints.  Reset this condition
upon USB bus reset.

CRs-Fixed: 445916
Change-Id: I9feeeb434dc180f1df859275ef1364c7dd829d78
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
USB: f_rndis: Check if cdev is NULL before accessing

RNDIS control path completion handlers are getting called after setting
cdev to NULL during disconnect as part of composition switch and this
is leading to a crash. Avoid this crash, by checking, if cdev is NULL
before accessing. Also don't queue request's to DCD, if composition switch
is in progress.

CRs-Fixed: 433534
Change-Id: Ic0790415ec3eaf866af2895370249e45adcbba5d
Signed-off-by: Chiranjeevi Velempati <cvelempa@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
Revert "USB: ci13xxx_udc: Add support for larger ( > 16K) length USB requests"

This reverts commit d2a03614a4ead5146860a550f8ee778e5297e260.

The original patch spans larger requests into multiple dTDs.  This
implementation is having problems with short packets.  When host
terminates the transfer with short packet, the controller will
advance to the next dTD of the current request. If host sends more
data, it will be received unintentionally.

CRs-Fixed: 449733
Change-Id: I06c88b93305ff2becd8096a1f6a8d82d6df7e638
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
USB: ci13xxx_udc: Add support for large requests

Spanning large request into multiple dTDs will fail with short
packets.  Instead queue one dTD at a time.  This patch has
the following limitations.

1. Large requests are supported only on Bulk OUT endpoints. This
feature is mainly required for MTP driver to achieve better write
throughputs. The VFS performs well with larger buffers.

2. To keep it simple, don't allow queuing while processing large
request. Don't allow larger request queuing while the queue is
busy.

CRs-Fixed: 449733
Change-Id: I262a62af3316d673a97f11842290609092c6e7df
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
gadget: ci13xxx_udc: Fix duplicate kmalloc and plug leak

A bad merge duplicated this kmalloc and leaks the previous
allocation. Remove the duplicate kmalloc.

Change-Id: I27dccdebaa30786cd302f58614401955bc4eba61
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
kthread_worker: reorganize to prepare for flush_kthread_work() reimplementation

Make the following two non-functional changes.

* Separate out insert_kthread_work() from queue_kthread_work().

* Relocate struct kthread_flush_work and kthread_flush_work_fn()
  definitions above flush_kthread_work().

v2: Added lockdep_assert_held() in insert_kthread_work() as suggested
    by Andy Walls.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Andy Walls <awalls@md.metrocast.net>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
kthread_worker: reimplement flush_kthread_work() to allow freeing the work item being executed

kthread_worker provides minimalistic workqueue-like interface for
users which need a dedicated worker thread (e.g. for realtime
priority).  It has basic queue, flush_work, flush_worker operations
which mostly match the workqueue counterparts; however, due to the way
flush_work() is implemented, it has a noticeable difference of not
allowing work items to be freed while being executed.

While the current users of kthread_worker are okay with the current
behavior, the restriction does impede some valid use cases.  Also,
removing this difference isn't difficult and actually makes the code
easier to understand.

This patch reimplements flush_kthread_work() such that it uses a
flush_work item instead of queue/done sequence numbers.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
kthread: Implement park/unpark facility

To avoid the full teardown/setup of per cpu kthreads in the case of
cpu hot(un)plug, provide a facility which allows to put the kthread
into a park position and unpark it when the cpu comes online again.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Reviewed-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/20120716103948.236618824@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
msm: kgsl: Initialize only required IOMMU context

Enforce initialization of user and private contexts only.
Only these contexts are used for both IOMMU v1 and v2.
Ignore additional contexts that may be defined for graphics
in the board or dts file.

Change-Id: Ib2a903f851421c4ac2c17b5aa9d822108ec6813b
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
msm: kgsl: pwrscale functions should be run while GPU is ACTIVE

Base the decision to call power scaling functions on the current
state, not the requested state.  The GPU may not transition to the
requested state; call through based on current GPU state instead.

Change-Id: I1524bc92c908dc50a60b5815f2221ae3feef59be
CRs-Fixed: 441847
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
msm: hotplug: Change the pen variable in one place

Other WFI based hotplug implementations set the pen variable to
-1 in C code and do the appropriate flushing operations in one
location. They also don't try to invalidate the cache on a
spurious wakeup and report how many spurious wakeups there were.
Let's do the same in our code so that we can remove our
dependence on the dmac_{inv,flush}_range() functions (which are
no longer upstream) and easily report spurious wakeups to the
kernel logs.

This does delay the time we set the pen back to its default
value, but that doesn't actually matter because generic ARM
hotplug code already waits for a completion before continuing.

Change-Id: Ic36fbf744fe8abeda20ad9859a207b5e37c5e63c
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
usb: ehci-msm: Prevent USB resume during system suspend

MSM USB host controller drivers release wakelocks only after
USB bus gets suspended. This means that at the time of system
suspend, USB devices and controller are already in suspend
state. As there are no additional power savings by disabling
wakeup capability during LPM, hence, mark HCD bus's skip_resume
flag so that USB core doesn't try to resume devices during suspend
to change remote-wakeup flags. This also avoids unnecessarily
resuming USB BUS when coming out of suspend even if there is no
wakeup USB event.

Change-Id: Icf0aa8001cde6bfc5cc5b148a34e344a3015ac58
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>