crypto: msm: check potential integer overflow

According to the specification of AEAD, AEAD request crypt length is
not a fixed maximum and associated length is also same. This could
lead to potential integer overflow, thus allocating less memory. So
we need to check potential integer overflow on AEAD request length.

CRs-Fixed: 726872
Change-Id: Ie7708000bfd8c57e2fba8e02230a7ce9cdc9634c
Signed-off-by: William Clark <wclark@codeaurora.org>
cpufreq: interactive: don't skip waking up speedchange_task if target_freq > policy->cur

When __cpufreq_driver_target() in speedchange_task failed for some reason, the
policy->cur could be lower than the target_freq. The governor misses to change
the target_freq if the target_freq is equal to the next_freq at the next sample
time.

Added a check to prevent the CPU to stay at the speed that is lower than the
target_freq for long duration.

Change-Id: Ibfdcd193b8280390b8f8374a63218aa31267f310
Signed-off-by: Minsung Kim <ms925.kim@samsung.com>
power: Adds functionality to log the last suspend abort reason.

Extends the last_resume_reason to log suspend abort reason. The abort
reasons will have "Abort:" appended at the start to distinguish itself
from the resume reason.

Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
Change-Id: I3207f1844e3d87c706dfc298fb10e1c648814c5f
cpufreq: ondemand: update code to Linux v3.18
net: ipc_router: Fix the race condition during SSR

During subsystem restart, SMD XPRT state is checked after starting the
write operation on a SMD channel. The channel state is different from its
corresponding XPRT state. This causes a writer to start the write operation
and then abort it, since the channel is not in reset state and the XPRT is
in reset state. This in turn causes the channel to be busy.

Check the XPRT state first before performing the write operation on its
corresponding channel. Remove the XPRT from the XPRT list at the earliest
possible, so that any write operation on a reset XPRT is avoided.

Change-Id: Id97870d4d6dae2d778fe0b4f39fc5265ffcaa51b
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
ion: Remove custom compat framework

It was pointed out that there is no need for a custom compat ioctl
framework in Ion, that decision can all be handled in device
registration. Remove the custom compat framework and just handle
the decision regarding compat ioctls in msm_ion.c

Change-Id: I6a0791013ce8e1f2f679555a46afd33de8fd9ce6
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
ion: fix remaining instances of sg_dma_len

Recently, [ec6c8a8f443: "ion: convert sg_dma_len(sg) to sg->length"]
moved Ion away from using sg_dma_len. However, a few instances were left
over from MSM-specific code. Fix these instances so that we're using
sg->length everywhere.

Change-Id: I76b07f5589ba3867e1584b129a0ccd9f3ef00ad7
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

Conflicts:
	drivers/staging/android/ion/ion_heap.c
ion: WARN when the handle kmap_cnt is going to wrap around

There are certain client bugs (double unmap, for example) that can cause
the handle->kmap_cnt (an unsigned int) to wrap around from zero. This
causes problems when the handle is destroyed because we have:

        while (handle->kmap_cnt)
                ion_handle_kmap_put(handle);

which takes a long time to complete when kmap_cnt starts at ~0 and can
result in a watchdog timeout.

WARN and bail when kmap_cnt is about to wrap around from zero.

Change-Id: I01cb09ad09b81c1d0e02e82333a14af6a08a92e9
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: Clarify variable names and comments around heap ids v types

There is some confusion between when to use the heap type and when
the id.  This patch clarifies this by using clearer variable names
and describing the intention in the comments.  Also fixes the client
debug code to print heaps by id instead of type.

Change-Id: Ie8b3dadded52e18590fcb2ca94001f6ed46ef07d
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
Git-commit: dbb80960d2f720c9d06dcbe4726fc5a1e2c4e8e0
Git-repo: https://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: Had to skip most of this patch since already
had most of it. Also had to apply to both ion.h files due to the UAPI
split. Also reverting 0b017a376827fc which renamed heap_id_mask to
heap_mask.]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
ion: move shrinker out of heaps

Every heap that uses deferred frees is going to need a shrinker
to shrink the freelist under memory pressure.  Rather than
requiring each heap to implement a shrinker, automatically
register a shrinker if the deferred free flag is set.
The system heap also needs to shrink its page pools, so add
a shrink function to the heap ops that will be called after
shrinking the freelists.

Change-Id: Icda722d683426fadb8ddd1c8e9499264ab682c57
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: f3ae9a8286d63f13715d2082965d6b8849af05a5
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: context differences due to our addition of
 cached page pools and some additional heap callbacks]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
mm: Add notifier framework for showing memory

There are many drivers in the kernel which can hold on
to lots of memory. It can be useful to dump out all those
drivers at key points in the kernel. Introduct a notifier
framework for dumping this information. When the notifiers
are called, drivers can dump out the state of any memory
they may be using.

Change-Id: Ifb2946964bf5d072552dd56d8d6dfdd794af6d84
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
staging: ion: msm: Only parse available dt nodes

ION is currently ignoring the status property of device tree
heap nodes. Make ION aware of the status of the ION heap nodes making
it possible to disable certain heaps.

Change-Id: I96e6af97df6bbd1c24ace9aa476baae28409ea96
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
ion: Always flush using kernel virtual address

Cache operations via userspace address always has a risk of a
page fault. On arm64, userspace addresses are marked as write
protect and fixed up on first accesses. If a userspace address
that has not been written to is invalidated, we will take a
fault, fixup and proceed on. If the mmap semaphore is locked at
the time however we cannot fixup the fault and will abort instead.
Rather than hope the mmap semaphore is not write protected, always
invalidate via the kernel virtual addresses instead.

Change-Id: I71eb0d214cce54ebc82a213ae653f891939f273a
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
ion: msm: remove superfluous function argument

msm_ion_client_create doesn't actually do anything with its heap_mask
parameter. Remove it. Also remove the extra argument from an audio
function that wraps msm_ion_client_create.

The following semantic patch was used to generate this patch:

    @@
    expression E1, E2;
    @@

    msm_ion_client_create(
    -       E1,
            E2)

    @@
    expression E1, E2;
    @@

    msm_audio_ion_client_create(
    -       E1,
            E2)

Change-Id: I403a125a1715b29a3db1f27c993abe0bc6d3fb11
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
ion: msm: move custom zero'ing functions out of core Ion

MSM targets currently use some optimized zero'ing functions. However,
there are always merge conflicts when bringing in patches from upstream
so these custom functions should be moved into the MSM space and the
original zero'ing functions from upstream should be restored.

All users of the custom zero'ing functions should continue to use the
custom functions. The goal, over time, is to unify the approaches but
for now just leave them separated.

Change-Id: I4818c09569976a82b8fecc5cd81129ce65ee7db3
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
ion: msm: plumb ION_HEAP_TYPE_DMA to core Ion

ION_HEAP_TYPE_DMA has made its way into core Ion since it was originally
added to the MSM Ion code base. Move some of the hooks and function
declarations out of MSM-specific code and into core Ion. There are still
some differences in the heap implementations themselves that will need
to be rectified later.

Change-Id: I44a4aa3a48645072cee0f2d0718ce3e795b27c4b
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

Conflicts:
	drivers/staging/android/uapi/linux/ion.h
ion: Register with show_mem notification framework

Bugs in Ion clients are semi-common cause of out of memory
errors. Register with the show_mem notification framework
to let Ion dump out data for debugging. To avoid having to
take an excessive amount of locks, keep a running total of
allocated and potentially orphaned memory.

Change-Id: I52c31459d5bf975c67adb5f3fe17033c8e01d91b
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
msm: ion: Do not check for overlapping ion heaps

To support new usecases, HLOS will permit of sharing
of the CMA pool between the ion heaps. Going forward
we do not need to check if the heaps overlap.

Change-Id: I1dee72147fad994a1c88ea9dfcf7402ba98f3609
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
msm: camera2: cpp: to silence non-fatal errors

In the kernel logs we were printing a error
message, when stream queue is not available
while we enqueue buffer to stream queue.This is
not fatal as we will create the new queue and continue.
Hence we are not printing it as a error message.

Change-Id: I674c8aa9b729fde715fbdc0f688efb03ed3455c9
Signed-off-by: Cherian Deepak <dcheri@codeaurora.org>
ion: this debugfs creation fails - remove code for it

"Failed to create client debugfs at /ion/clients/camera/jpeg-0"