OSDN Git Service

sagit-ice-cold/kernel_xiaomi_msm8998.git
4 years agoMakefile: Pass optimization flags to assembler
Julian Liu [Mon, 16 Sep 2019 14:33:02 +0000 (22:33 +0800)]
Makefile: Pass optimization flags to assembler

4 years agoMakefile: Optimize for our CPU
wloot [Sat, 1 Jun 2019 21:15:08 +0000 (05:15 +0800)]
Makefile: Optimize for our CPU

4 years agoMakefile: Compile with O3
Joe Maples [Fri, 10 Nov 2017 15:51:18 +0000 (10:51 -0500)]
Makefile: Compile with O3

Signed-off-by: Joe Maples <joe@frap129.org>
4 years agoqcacld: check if auth_tag_len exceeds sizeof(hash)
Park Ju Hyung [Sat, 6 Jul 2019 18:00:59 +0000 (03:00 +0900)]
qcacld: check if auth_tag_len exceeds sizeof(hash)

Without this check, memcmp() compile-time check fails

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agoqcacld: disable more debugs
0ranko0P [Tue, 29 Oct 2019 12:03:59 +0000 (20:03 +0800)]
qcacld: disable more debugs

4 years agoqcacld: disable tso debugging
0ranko0P [Tue, 29 Oct 2019 04:10:09 +0000 (12:10 +0800)]
qcacld: disable tso debugging

4 years agoqcacld: nuke rx_wakelock code entirely
Park Ju Hyung [Thu, 7 Mar 2019 02:11:33 +0000 (11:11 +0900)]
qcacld: nuke rx_wakelock code entirely

We're not allowing this to be configurable on this kernel.

Nuke this entirely to reduce resource usage.

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agoqcacld: initialize variables to avoid errors during compilation
Park Ju Hyung [Mon, 15 Apr 2019 09:47:58 +0000 (18:47 +0900)]
qcacld: initialize variables to avoid errors during compilation

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agopower: qcom: Silence clang warning
Harsh Shandilya [Sun, 6 Oct 2019 15:35:45 +0000 (21:05 +0530)]
power: qcom: Silence clang warning

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
4 years agodrivers: video: fbdev: update from sagit-p-oss
0ranko0P [Mon, 28 Oct 2019 11:37:05 +0000 (19:37 +0800)]
drivers: video: fbdev: update from sagit-p-oss

4 years agoqcacld-3.0: Fix another uninitialized variable
Julian Liu [Sat, 20 Jul 2019 09:55:59 +0000 (17:55 +0800)]
qcacld-3.0: Fix another uninitialized variable

Clang warns:
drivers/staging/qcacld-3.0/core/sme/src/csr/csr_util.c:1819:8: error:
      variable 'phyMode2' is used uninitialized whenever 'if' condition is
      false [-Werror,-Wsometimes-uninitialized]
                        if (eCSR_DOT11_MODE_AUTO & phyMode) {
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/qcacld-3.0/core/sme/src/csr/csr_util.c:1826:36: note:
      uninitialized use occurs here
                fMatch = csr_get_phy_mode_in_use(phyMode2, phyModeInBssDesc,
                                                 ^~~~~~~~
drivers/staging/qcacld-3.0/core/sme/src/csr/csr_util.c:1819:4: note:
      remove the 'if' if its condition is always true
                        if (eCSR_DOT11_MODE_AUTO & phyMode) {
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/qcacld-3.0/core/sme/src/csr/csr_util.c:1797:2: note:
      variable 'phyMode2' is declared here
        eCsrPhyMode phyModeInBssDesc = eCSR_DOT11_MODE_AUTO, phyMode2;
        ^
1 error generated.

4 years agoMerge f2fs changes from branch 'memeuibut8.2' of https://github.com/wloot/android_ker...
0Ranko0P [Mon, 21 Oct 2019 12:31:15 +0000 (20:31 +0800)]
Merge f2fs changes from branch 'memeuibut8.2' of https://github.com/wloot/android_kernel_xiaomi_msm8998

4 years agolowmemorykiller: Account for extra_free_kbytes in calcuations
Jeff Vanhoof [Thu, 19 Oct 2017 10:39:30 +0000 (05:39 -0500)]
lowmemorykiller: Account for extra_free_kbytes in calcuations

Account for extra_free_kbytes in calcuations

CRs-fixed: (CR)
Signed-off-by: Jeff Vanhoof <qjv001@motorola.com>
Change-Id: I2c44a1775d43fad40cf49d6303b7552c2c089b6e
Reviewed-on: https://gerrit.mot.com/1076213
SME-Granted: SME Approvals Granted
SLTApproved: Slta Waiver
Tested-by: Jira Key
Reviewed-by: Coverity Analysis <coverity@motorola.com>
Reviewed-by: Igor Kovalenko <igork@motorola.com>
Submit-Approved: Jira Key

4 years agolmk: add inline keywords to in-loop functions
Park Ju Hyung [Thu, 20 Jul 2017 13:04:03 +0000 (22:04 +0900)]
lmk: add inline keywords to in-loop functions

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agolmk: add static keywords to locally used variables
Park Ju Hyung [Thu, 20 Jul 2017 13:01:51 +0000 (22:01 +0900)]
lmk: add static keywords to locally used variables

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
4 years agolowmemorykiller: redesign memory instrumentation
Josh Galicia [Thu, 15 Sep 2016 18:43:49 +0000 (13:43 -0500)]
lowmemorykiller: redesign memory instrumentation

Add tracking node for LMK counts for memory instrumentation.

Change-Id: I7cd201dd4b84de81f08da580b590dad35673753b
Signed-off-by: Josh Galicia <cjg040@motorola.com>
Reviewed-on: https://gerrit.mot.com/899855
SLTApproved: Slta Waiver <sltawvr@motorola.com>
SME-Granted: SME Approvals Granted
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Christopher Fries <cfries@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: Alex Naidis <alex.naidis@linux.com>
4 years agolmk: import rbtree changes from Motorola
Park Ju Hyung [Wed, 17 Jul 2019 17:43:50 +0000 (02:43 +0900)]
lmk: import rbtree changes from Motorola

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
Signed-off-by: Julian Liu <wlootlxt123@gmail.com>
[@wloot: backport to k4.4]

4 years agolowmemorykiller: fix compilation with 4.4
Julian Liu [Thu, 19 Sep 2019 15:44:40 +0000 (23:44 +0800)]
lowmemorykiller: fix compilation with 4.4

4 years agolowmemorykiller: checkout to android-4.9
Julian Liu [Thu, 19 Sep 2019 15:13:56 +0000 (23:13 +0800)]
lowmemorykiller: checkout to android-4.9

4 years agoRevert "{chiron,sagit}_defconfig: Use Simple LMK"
Julian Liu [Thu, 19 Sep 2019 15:10:05 +0000 (23:10 +0800)]
Revert "{chiron,sagit}_defconfig: Use Simple LMK"

This reverts commit ca0e1a2fd5be9399388af504886a2622315bc7bd.

4 years agotreewide: revert "remove duplicate const specifier" patchs
Julian Liu [Fri, 20 Sep 2019 03:57:25 +0000 (11:57 +0800)]
treewide: revert "remove duplicate const specifier" patchs

* C defined grammar

4 years agofs: proc: cpumaxfreq: Fix memory leak in cpumaxfreq_open
Julian Liu [Thu, 19 Sep 2019 19:38:00 +0000 (03:38 +0800)]
fs: proc: cpumaxfreq: Fix memory leak in cpumaxfreq_open

4 years agocamera_v2: Fix memory leak in msm_eeprom_platform_probe
Julian Liu [Thu, 19 Sep 2019 18:37:59 +0000 (02:37 +0800)]
camera_v2: Fix memory leak in msm_eeprom_platform_probe

4 years agonet: ipc_router: Fix memory leak when IPC_LOGGING disabled
Julian Liu [Thu, 19 Sep 2019 18:50:14 +0000 (02:50 +0800)]
net: ipc_router: Fix memory leak when IPC_LOGGING disabled

4 years agoRevert "camera_v2: update from sagit-p-oss"
Julian Liu [Wed, 18 Sep 2019 18:54:17 +0000 (02:54 +0800)]
Revert "camera_v2: update from sagit-p-oss"

This reverts commit e67a25de54ccdc249c887d7ad4829dc1dd127c3f.

4 years agocpuidle: lpm-levels: Remove debug event logging
Danny Lin [Mon, 6 May 2019 04:59:37 +0000 (21:59 -0700)]
cpuidle: lpm-levels: Remove debug event logging

A measurably significant amount of CPU time is spent on logging events
for debugging purposes in lpm_cpuidle_enter. Kill the useless logging to
reduce overhead.

Signed-off-by: Danny Lin <danny@kdrag0n.dev>
4 years ago{chiron,sagit}_defconfig: omit frame pointer
Sultan Alsawaf [Mon, 15 Oct 2018 03:23:55 +0000 (20:23 -0700)]
{chiron,sagit}_defconfig: omit frame pointer

This improves performance by freeing up a register at the expense of a huge
hit to ease of debugging. Since this kernel is not actively being debugged
for anything though, frame pointers can be disabled.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Change-Id: I98f88e981f01336923e08a4585a2b5c6b174512b

4 years agoarm64: don't force FRAME_POINTER
Sultan Alsawaf [Mon, 15 Oct 2018 03:21:25 +0000 (20:21 -0700)]
arm64: don't force FRAME_POINTER

Change-Id: I08261db2f80fb11b7e02af64a4ec011c2dab2b39

4 years ago{chiron,sagit}_defconfig: Use Simple LMK
Sultan Alsawaf [Sun, 12 May 2019 20:12:25 +0000 (13:12 -0700)]
{chiron,sagit}_defconfig: Use Simple LMK

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
[wight554: apply wahoo change on chiron and sagit]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agosimple_lmk: Mark reclaim kthread as performance critical
Sultan Alsawaf [Sun, 12 May 2019 20:12:21 +0000 (13:12 -0700)]
simple_lmk: Mark reclaim kthread as performance critical

Simple LMK's reclaim thread needs to run as quickly as possible to
reduce memory allocation latency when memory pressure is high. Mark it
as performance critical to schedule it on faster CPUs.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agosimple_lmk: Introduce Simple Low Memory Killer for Android
Sultan Alsawaf [Wed, 21 Aug 2019 15:45:15 +0000 (08:45 -0700)]
simple_lmk: Introduce Simple Low Memory Killer for Android

This is a complete low memory killer solution for Android that is small
and simple. Processes are killed according to the priorities that
Android gives them, so that the least important processes are always
killed first. Processes are killed until memory deficits are satisfied,
as observed from kswapd struggling to free up pages. Simple LMK stops
killing processes when kswapd finally goes back to sleep.

The only tunables are the desired amount of memory to be freed per
reclaim event and desired frequency of reclaim events. Simple LMK tries
to free at least the desired amount of memory per reclaim and waits
until all of its victims' memory is freed before proceeding to kill more
processes.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoANDROID: binder: correct the cmd print for BINDER_WORK_RETURN_ERROR
宋金时 [Thu, 10 May 2018 02:05:03 +0000 (02:05 +0000)]
ANDROID: binder: correct the cmd print for BINDER_WORK_RETURN_ERROR

When to execute binder_stat_br the e->cmd has been modifying as BR_OK
instead of the original return error cmd, in fact we want to know the
original return error, such as BR_DEAD_REPLY or BR_FAILED_REPLY, etc.
instead of always BR_OK, in order to avoid the value of the e->cmd is
always BR_OK, so we need assign the value of the e->cmd to cmd before
e->cmd = BR_OK.

Signed-off-by: songjinshi <songjinshi@xiaomi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4 years agobinder: fix incorrect cmd to binder_stat_br
Todd Kjos [Tue, 8 Aug 2017 22:48:36 +0000 (15:48 -0700)]
binder: fix incorrect cmd to binder_stat_br

commit 26549d177410 ("binder: guarantee txn complete / errors delivered
in-order") passed the locally declared and undefined cmd
to binder_stat_br() which results in a bogus cmd field in a trace
event and BR stats are incremented incorrectly.

Change to use e->cmd which has been initialized.

Signed-off-by: Todd Kjos <tkjos@google.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 26549d177410 ("binder: guarantee txn complete / errors delivered in-order")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4 years agofib_rules: Fix payload calculation
Sultan Alsawaf [Thu, 1 Aug 2019 03:10:06 +0000 (20:10 -0700)]
fib_rules: Fix payload calculation

The errant semicolon here results in the final addend getting discarded.

Fixes: ef5fbba6f8da ("net: core: add UID to flows, rules, and routes")
Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agonet/ipv4: fib_trie: Avoid cryptic ternary expressions
Matthias Kaehlcke [Tue, 18 Jun 2019 21:14:40 +0000 (14:14 -0700)]
net/ipv4: fib_trie: Avoid cryptic ternary expressions

empty_child_inc/dec() use the ternary operator for conditional
operations. The conditions involve the post/pre in/decrement
operator and the operation is only performed when the condition
is *not* true. This is hard to parse for humans, use a regular
'if' construct instead and perform the in/decrement separately.

This also fixes two warnings that are emitted about the value
of the ternary expression being unused, when building the kernel
with clang + "kbuild: Remove unnecessary -Wno-unused-value"
(https://lore.kernel.org/patchwork/patch/1089869/):

CC      net/ipv4/fib_trie.o
net/ipv4/fib_trie.c:351:2: error: expression result unused [-Werror,-Wunused-value]
        ++tn_info(n)->empty_children ? : ++tn_info(n)->full_children;

Fixes: 95f60ea3e99a ("fib_trie: Add collapse() and should_collapse() to resize")
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Acked-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
4 years ago{chiron,sagit}_defconfig: Panic in schedule() when stack corruption is found
Sultan Alsawaf [Thu, 1 Aug 2019 01:38:18 +0000 (18:38 -0700)]
{chiron,sagit}_defconfig: Panic in schedule() when stack corruption is found

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
[wight554: apply wahoo change on chiron and sagit]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agolib: Kconfig.debug: Remove debug dependency from SCHED_STACK_END_CHECK
Sultan Alsawaf [Thu, 1 Aug 2019 01:37:06 +0000 (18:37 -0700)]
lib: Kconfig.debug: Remove debug dependency from SCHED_STACK_END_CHECK

This is a very useful feature that doesn't have any real dependencies on
DEBUG_KERNEL. Let it be used in the absence of DEBUG_KERNEL.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoANDROID: sdcardfs: Allocate temporary name buffer on the stack
Sultan Alsawaf [Thu, 1 Aug 2019 01:34:31 +0000 (18:34 -0700)]
ANDROID: sdcardfs: Allocate temporary name buffer on the stack

Since this 4 KiB name buffer is only used temporarily, allocate it on
the stack to improve performance. This is confirmed to be safe according
to runtime stack usage measurements.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agokobject_uevent: Allocate environment buffer on the stack
Sultan Alsawaf [Thu, 1 Aug 2019 01:27:02 +0000 (18:27 -0700)]
kobject_uevent: Allocate environment buffer on the stack

The environment buffer isn't very big; when it's allocated on the stack,
kobject_uevent_env's stack frame size increases to just over 2 KiB,
which is safe considering that we have a 16 KiB stack.

Allocate the environment buffer on the stack instead of using the slab
allocator in order to improve performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoion: system_heap: Speed up system heap allocations
Sultan Alsawaf [Thu, 1 Aug 2019 01:02:49 +0000 (18:02 -0700)]
ion: system_heap: Speed up system heap allocations

The system heap allocation process consists of allocating numerous
temporary buffers that can instead be placed on the stack, to an extent;
if the new 4 KiB on-stack buffer runs out, page_info allocations will
fall back to using kmalloc.

Additionally, since system heap allocations are frequent, they can
benefit from the use of a memory pool for allocating the persistent
sg_table structures. These allocations, along with a few others, also
don't need to be zeroed out.

These changes improve system heap allocation performance considerably.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoANDROID: crypto: heh - Avoid dynamically allocating memory for keys
Sultan Alsawaf [Wed, 31 Jul 2019 20:07:35 +0000 (13:07 -0700)]
ANDROID: crypto: heh - Avoid dynamically allocating memory for keys

The derived keys are usually quite small (48 B). We can use a small
on-stack buffer of 1 KiB to dodge dynamic memory allocation, speeding up
heh_setkey.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoext4: Avoid dynamically allocating memory in ext4_ext_remove_space
Sultan Alsawaf [Wed, 31 Jul 2019 20:06:33 +0000 (13:06 -0700)]
ext4: Avoid dynamically allocating memory in ext4_ext_remove_space

Although path depth is unbounded, we can still fulfill many path
allocations here with a 4 KiB stack allocation, thereby improving
performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoxattr: Avoid dynamically allocating memory in getxattr
Sultan Alsawaf [Wed, 31 Jul 2019 07:04:01 +0000 (00:04 -0700)]
xattr: Avoid dynamically allocating memory in getxattr

Although the maximum xattr size is too big to fit on the stack (64 KiB),
we can still fulfill most getxattr requests with a 4 KiB stack
allocation, thereby improving performance. Such a large stack allocation
here is confirmed to be safe via stack usage measurements at runtime.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agobinfmt_elf: Don't allocate memory dynamically in load_elf_binary
Sultan Alsawaf [Wed, 31 Jul 2019 07:00:01 +0000 (00:00 -0700)]
binfmt_elf: Don't allocate memory dynamically in load_elf_binary

The dynamic memory allocations in load_elf_binary can be replaced by
large stack allocations that bring the total frame size for the function
up to about 4 KiB. We have 16 KiB of stack space, and runtime
measurements confirm that using this much stack memory here is safe.
This improves performance by eliminating the overhead of dynamic memory
allocation.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agostaging: sync: Use an on-stack allocation for fence info ioctl
Sultan Alsawaf [Wed, 31 Jul 2019 06:56:18 +0000 (23:56 -0700)]
staging: sync: Use an on-stack allocation for fence info ioctl

Since the fence info ioctl limits output data length to 4096 bytes, we
can just use a 4096-byte on-stack buffer for it (which is confirmed to
be safe via runtime stack usage measurements). This ioctl is used for
every frame rendered to the display, so eliminating dynamic memory
allocation overhead here improves frame rendering performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomedia: v4l2-ioctl: Use larger on-stack video copy buffers
Sultan Alsawaf [Wed, 31 Jul 2019 06:53:13 +0000 (23:53 -0700)]
media: v4l2-ioctl: Use larger on-stack video copy buffers

We have a 16 KiB stack; buffers of 4 KiB and 512 B work perfectly fine
in place of a small 128-byte buffer and especially no on-stack buffer at
all. This avoids dynamic memory allocation more often, improving
performance, and it's safe according to stack usage measurements at
runtime.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: camera: Optimize memory allocation for small buffers
Sultan Alsawaf [Wed, 31 Jul 2019 06:38:19 +0000 (23:38 -0700)]
msm: camera: Optimize memory allocation for small buffers

Try to use an on-stack buffer for memory allocations that are small
enough to not warrant a dynamic allocation, and eliminate dynamic memory
allocation entirely in msm_camera_cci_i2c_read_seq. This improves
performance by skipping latency-prone dynamic memory allocation when it
isn't needed.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Don't allocate memory dynamically for temp command buffers
Sultan Alsawaf [Wed, 31 Jul 2019 04:35:56 +0000 (21:35 -0700)]
msm: kgsl: Don't allocate memory dynamically for temp command buffers

The temporary command buffer in _set_pagetable_gpu is only the size of a
single page; it is therefore easy to replace the dynamic command buffer
allocation with a static one to improve performance by avoiding the
latency of dynamic memory allocation.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: mdss: Don't allocate memory dynamically for small layer buffers
Sultan Alsawaf [Wed, 31 Jul 2019 04:29:13 +0000 (21:29 -0700)]
msm: mdss: Don't allocate memory dynamically for small layer buffers

There's no reason to dynamically allocate memory for a single, small
struct instance (output_layer) when it can be allocated on the stack.
Additionally, layer_list and validate_info_list are limited by the
maximum number of layers allowed, so they can be replaced by stack
allocations.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoext4 crypto: Use a larger on-stack file name buffer
Sultan Alsawaf [Wed, 31 Jul 2019 04:15:10 +0000 (21:15 -0700)]
ext4 crypto: Use a larger on-stack file name buffer

32 bytes for the on-stack file name buffer is rather small and doesn't
fit many file names, causing dynamic allocation to be used more often
than necessary instead. Increasing the on-stack buffer to 4 KiB is safe
and helps this function avoid dynamic memory allocations far more
frequently.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoselinux: Avoid dynamic memory allocation for small context buffers
Sultan Alsawaf [Wed, 31 Jul 2019 04:13:43 +0000 (21:13 -0700)]
selinux: Avoid dynamic memory allocation for small context buffers

Most context buffers are rather small and can fit on the stack,
eliminating the need to allocate them dynamically. Reserve a 4 KiB
stack buffer for this purpose to avoid the overhead of dynamic
memory allocation.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agokernfs: Avoid dynamic memory allocation for small write buffers
Sultan Alsawaf [Tue, 30 Jul 2019 21:21:10 +0000 (14:21 -0700)]
kernfs: Avoid dynamic memory allocation for small write buffers

Most write buffers are rather small and can fit on the stack,
eliminating the need to allocate them dynamically. Reserve a 4 KiB
stack buffer for this purpose to avoid the overhead of dynamic
memory allocation.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Avoid dynamically allocating small command buffers
Sultan Alsawaf [Tue, 30 Jul 2019 21:19:59 +0000 (14:19 -0700)]
msm: kgsl: Avoid dynamically allocating small command buffers

Most command buffers here are rather small (fewer than 256 words); it's
a waste of time to dynamically allocate memory for such a small buffer
when it could easily fit on the stack.

Conditionally using an on-stack command buffer when the size is small
enough eliminates the need for using a dynamically-allocated buffer most
of the time, reducing GPU command submission latency.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years ago{chiron,sagit}_defconfig: Disable stack frame size warning
Sultan Alsawaf [Tue, 30 Jul 2019 21:19:45 +0000 (14:19 -0700)]
{chiron,sagit}_defconfig: Disable stack frame size warning

The stack frame size warning can be deceptive when it is clear that a
function with a large frame size won't cause stack overflows given how
it is used. Since this warning is more of a nuisance rather than
helpful, disable it.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
[wight554: apply wahoo change on chiron and sagit]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agoext4: Allocate allocation-context on the stack
Sultan Alsawaf [Sat, 13 Jul 2019 00:42:58 +0000 (17:42 -0700)]
ext4: Allocate allocation-context on the stack

The allocation context structure is quite small and easily fits on the
stack. There's no need to allocate it dynamically.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoscatterlist: Don't allocate sg lists using __get_free_page
Sultan Alsawaf [Fri, 12 Jul 2019 23:06:47 +0000 (16:06 -0700)]
scatterlist: Don't allocate sg lists using __get_free_page

Allocating pages with __get_free_page is slower than going through the
slab allocator to grab free pages out from a pool.

These are the results from running the code at the bottom of this
message:
[    1.278602] speedtest: __get_free_page: 9 us
[    1.278606] speedtest: kmalloc: 4 us
[    1.278609] speedtest: kmem_cache_alloc: 4 us
[    1.278611] speedtest: vmalloc: 13 us

kmalloc and kmem_cache_alloc (which is what kmalloc uses for common
sizes behind the scenes) are the fastest choices. Use kmalloc to speed
up sg list allocation.

This is the code used to produce the above measurements:
#include <linux/kthread.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>

static int speedtest(void *data)
{
static const struct sched_param sched_max_rt_prio = {
.sched_priority = MAX_RT_PRIO - 1
};
volatile s64 ctotal = 0, gtotal = 0, ktotal = 0, vtotal = 0;
struct kmem_cache *page_pool;
int i, j, trials = 1000;
volatile ktime_t start;
void *ptr[100];

sched_setscheduler_nocheck(current, SCHED_FIFO, &sched_max_rt_prio);

page_pool = kmem_cache_create("pages", PAGE_SIZE, PAGE_SIZE, SLAB_PANIC,
      NULL);
for (i = 0; i < trials; i++) {
start = ktime_get();
for (j = 0; j < ARRAY_SIZE(ptr); j++)
while (!(ptr[j] = kmem_cache_alloc(page_pool, GFP_KERNEL)));
ctotal += ktime_us_delta(ktime_get(), start);
for (j = 0; j < ARRAY_SIZE(ptr); j++)
kmem_cache_free(page_pool, ptr[j]);

start = ktime_get();
for (j = 0; j < ARRAY_SIZE(ptr); j++)
while (!(ptr[j] = (void *)__get_free_page(GFP_KERNEL)));
gtotal += ktime_us_delta(ktime_get(), start);
for (j = 0; j < ARRAY_SIZE(ptr); j++)
free_page((unsigned long)ptr[j]);

start = ktime_get();
for (j = 0; j < ARRAY_SIZE(ptr); j++)
while (!(ptr[j] = kmalloc(PAGE_SIZE, GFP_KERNEL)));
ktotal += ktime_us_delta(ktime_get(), start);
for (j = 0; j < ARRAY_SIZE(ptr); j++)
kfree(ptr[j]);

start = ktime_get();
*ptr = vmalloc(ARRAY_SIZE(ptr) * PAGE_SIZE);
vtotal += ktime_us_delta(ktime_get(), start);
vfree(*ptr);
}
kmem_cache_destroy(page_pool);

printk("%s: __get_free_page: %lld us\n", __func__, gtotal / trials);
printk("%s: kmalloc: %lld us\n", __func__, ktotal / trials);
printk("%s: kmem_cache_alloc: %lld us\n", __func__, ctotal / trials);
printk("%s: vmalloc: %lld us\n", __func__, vtotal / trials);
complete(data);
return 0;
}

static int __init start_test(void)
{
DECLARE_COMPLETION_ONSTACK(done);

BUG_ON(IS_ERR(kthread_run(speedtest, &done, "malloc_test")));
wait_for_completion(&done);
return 0;
}
late_initcall(start_test);

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomm: kmemleak: Don't die when memory allocation fails
Sultan Alsawaf [Sun, 7 Jul 2019 04:15:19 +0000 (21:15 -0700)]
mm: kmemleak: Don't die when memory allocation fails

When memory is leaking, it's going to be harder to allocate more memory,
making it more likely for this failure condition inside of kmemleak to
manifest itself. This is extremely frustrating since kmemleak kills
itself upon the first instance of memory allocation failure.

Bypass that and make kmemleak more resilient when memory is running low.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomm: kmemleak: Don't require global debug options
Sultan Alsawaf [Sun, 7 Jul 2019 01:59:34 +0000 (18:59 -0700)]
mm: kmemleak: Don't require global debug options

This allows kmemleak to function even when debugfs is globally disabled,
allowing kmemleak to give accurate results for CONFIG_DEBUG_FS=n.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agombcache2: Speed up cache entry creation
Sultan Alsawaf [Wed, 3 Jul 2019 21:09:01 +0000 (14:09 -0700)]
mbcache2: Speed up cache entry creation

In order to prevent redundant entry creation by racing against itself,
mb2_cache_entry_create scans through a large hash-list of all current
entries in order to see if another allocation for the requested new
entry has been made. Furthermore, it allocates memory for a new entry
before scanning through this hash-list, which results in that allocated
memory being discarded when the requested new entry is already present.
This happens more than half the time.

Speed up cache entry creation by keeping a small linked list of
requested new entries in progress, and scanning through that first
instead of the large hash-list. Additionally, don't bother allocating
memory for a new entry until it's known that the allocated memory will
be used.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: mdss: Don't allocate memory dynamically for destination scaler
Sultan Alsawaf [Wed, 31 Jul 2019 04:22:00 +0000 (21:22 -0700)]
msm: mdss: Don't allocate memory dynamically for destination scaler

Every atomic frame commit allocates memory dynamically for the
destination scaler, when those allocations can just be stored on the
stack instead. Eliminate these dynamic memory allocations in the frame
commit path to improve performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoarm64: vdso: Mark vdso_pagelist allocation as not a leak
Sultan Alsawaf [Sun, 30 Jun 2019 04:56:06 +0000 (21:56 -0700)]
arm64: vdso: Mark vdso_pagelist allocation as not a leak

The vdso_pagelist allocation is stored inside the vDSO mappings, which
are static, so the memory is never leaked. However, kmemleak thinks that
vdso_pagelist is leaked because the vDSO mappings are read-only after
init.

Fix kmemleak's false positive by marking the allocation as not a leak.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agodmaengine: Fix memory leak in dma_async_device_register
Sultan Alsawaf [Sun, 30 Jun 2019 04:23:36 +0000 (21:23 -0700)]
dmaengine: Fix memory leak in dma_async_device_register

The atomic reference counter, idr_ref, is leaked when there are no
channels available for a DMA device. Free idr_ref in this case to fix
the memory leak.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoiommu: arm-smmu: Free pgtbl ops when domain contexts are destroyed
Sultan Alsawaf [Tue, 25 Jun 2019 17:53:43 +0000 (10:53 -0700)]
iommu: arm-smmu: Free pgtbl ops when domain contexts are destroyed

When a domain context is initialized, pgtbl ops are allocated, but they
aren't freed when the domain context is destroyed, causing memory to be
leaked. Fix the memory leak by freeing pgtbl ops when domain contexts
are destroyed.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoALSA: control_compat: Don't dynamically allocate single-use structs
Sultan Alsawaf [Sat, 20 Jul 2019 17:58:01 +0000 (10:58 -0700)]
ALSA: control_compat: Don't dynamically allocate single-use structs

All of these dynamically-allocated structs can be simply placed on the
stack, eliminating the overhead of dynamic memory allocation entirely.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Don't allocate memory dynamically for drawobj sync structs
Sultan Alsawaf [Sun, 16 Jun 2019 21:26:47 +0000 (14:26 -0700)]
msm: kgsl: Don't allocate memory dynamically for drawobj sync structs

The memory allocated dynamically here is just used to store a single
instance of a struct. Allocate both possible structs on the stack
instead of allocating them dynamically to improve performance. These
structs also do not need to be zeroed out.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Don't try to wait for fences that have been signaled
Sultan Alsawaf [Sun, 16 Jun 2019 21:04:38 +0000 (14:04 -0700)]
msm: kgsl: Don't try to wait for fences that have been signaled

Trying to wait for fences that have already been signaled incurs a high
setup cost, since dynamic memory allocation must be used. Avoiding this
overhead when it isn't needed improves performance.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agostaging: sync: Add a function to check if a fence has been signaled
Sultan Alsawaf [Sun, 16 Jun 2019 21:02:24 +0000 (14:02 -0700)]
staging: sync: Add a function to check if a fence has been signaled

Knowing if a fence has been signaled is useful for avoiding the overhead
of needlessly setting up a sync operation.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agostaging: android: ashmem: Get rid of the big mutex lock
Sultan Alsawaf [Tue, 11 Jun 2019 17:09:15 +0000 (10:09 -0700)]
staging: android: ashmem: Get rid of the big mutex lock

Ashmem uses a single big mutex lock for all synchronization, and even
uses it when no synchronization issues are present. The contention from
using a single lock results in all-around poor performance.

Use fine-grained locks and atomic constructions to eliminate the big
mutex lock, thereby improving performance greatly.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoASoC: Silence platform not registered message
Sultan Alsawaf [Sun, 2 Jun 2019 17:46:06 +0000 (10:46 -0700)]
ASoC: Silence platform not registered message

This log spam on boot is killing dmesg. Silence it.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoscsi: ufs: Only apply pm_qos to the CPU servicing UFS interrupts
Sultan Alsawaf [Tue, 28 May 2019 02:40:44 +0000 (19:40 -0700)]
scsi: ufs: Only apply pm_qos to the CPU servicing UFS interrupts

Applying pm_qos restrictions to multiple CPUs which aren't used for ufs
processing is a waste of power. Instead, only apply the pm_qos
restrictions to the CPU that services the UFS interrupts to save power.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: camera: Undo pm_qos request upon error
Sultan Alsawaf [Tue, 28 May 2019 02:20:42 +0000 (19:20 -0700)]
msm: camera: Undo pm_qos request upon error

If anything after msm_pm_qos_update_request(CAMERA_DISABLE_PC_LATENCY)
fails, the pm_qos request won't be undone and will waste power. Make
sure it gets unset in the error path to fix this.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoi2c-msm-v2: Add needed includes to header for compilation
Sultan Alsawaf [Mon, 27 May 2019 23:45:42 +0000 (16:45 -0700)]
i2c-msm-v2: Add needed includes to header for compilation

This allows usage of i2c-msm-v2.h without needing to include its
dependencies.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: mdss: Make "Speed up MDP interrupt processing" sagit only
wloot [Sun, 2 Jun 2019 23:05:10 +0000 (07:05 +0800)]
msm: mdss: Make "Speed up MDP interrupt processing" sagit only

4 years agomsm: mdss: Speed up MDP interrupt processing for cmd mode panels
Sultan Alsawaf [Thu, 30 May 2019 06:30:33 +0000 (23:30 -0700)]
msm: mdss: Speed up MDP interrupt processing for cmd mode panels

By preventing the CPU that MDP interrupts are designated to be processed
on from entering deep idle states, the CPU won't need to exit deep idle
when receiving those interrupts and can thus process them faster. This
reduces frame commit latency significantly.

This is only for command-mode panels.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agokernel: Don't allow IRQ affinity masks to have more than one CPU
Sultan Alsawaf [Sun, 26 May 2019 05:48:20 +0000 (22:48 -0700)]
kernel: Don't allow IRQ affinity masks to have more than one CPU

Even with an affinity mask that has multiple CPUs set, IRQs always run
on the first CPU in their affinity mask. Drivers that register an IRQ
affinity notifier (such as pm_qos) will therefore have an incorrect
assumption of where an IRQ is affined.

Fix the IRQ affinity mask deception by forcing it to only contain one
set CPU.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agocpuidle: Optimize pm_qos notifier callback
Sultan Alsawaf [Sun, 26 May 2019 17:18:46 +0000 (10:18 -0700)]
cpuidle: Optimize pm_qos notifier callback

The pm_qos notifier currently suffers from a number of pitfalls: it
sends IPIs to CPUs that may not be idle, waits for the IPIs to finish
propagating while preemption is disabled (resulting in a long busy wait
for the pm_qos_update_target caller), needlessly calls a no-op
function when the IPIs are processed, and sends IPIs even when the CPU
latency requirement is relaxed.

Optimize the pm_qos notifier by using arch_send_call_function_ipi_mask
instead of smp_call_function_many to eliminate the need to call a no-op
function (with the added benefit of it not blocking) and only sending
IPIs to CPUs that are idle. Additionally, only send IPIs when the CPU
latency requirement is tightened, since it's not necessary to kick CPUs
out of idle when the latency requirement is relaxed.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoqos: Execute notifier callbacks atomically
Sultan Alsawaf [Fri, 17 May 2019 06:03:33 +0000 (23:03 -0700)]
qos: Execute notifier callbacks atomically

Allowing the pm_qos notifier callbacks to execute without holding
pm_qos_lock can cause the callbacks to misbehave, e.g. the cpuidle
callback could erroneously send more IPIs than necessary.

Fix this by executing the pm_qos callbacks while pm_qos_lock is held.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoqos: Don't disable interrupts while holding pm_qos_lock
Sultan Alsawaf [Fri, 17 May 2019 06:02:50 +0000 (23:02 -0700)]
qos: Don't disable interrupts while holding pm_qos_lock

None of the pm_qos functions actually run in interrupt context; if some
driver calls pm_qos_update_target in interrupt context then it's already
broken. There's no need to disable interrupts while holding pm_qos_lock,
so don't do it.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoscsi: ufs: Remove 10 ms CPU idle latency unvote timeout
Sultan Alsawaf [Tue, 7 May 2019 08:53:59 +0000 (01:53 -0700)]
scsi: ufs: Remove 10 ms CPU idle latency unvote timeout

This forces the CPU to stay out of deep idle states for far longer than
necessary, which wastes power. Just unvote immediately when requested.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agostaging: sync: Remove fence names by default
Sultan Alsawaf [Sat, 20 Jul 2019 17:33:00 +0000 (10:33 -0700)]
staging: sync: Remove fence names by default

Copying fence debug names for frequent users of sync fences causes a
measurably significant portion of CPU time to be spent on the strlcpy.
Additionally, the sync_fence struct is allocated very frequently, so
wasting space on an unneeded 64-byte name is suboptimal.

Remove the 64-byte name from the struct to reduce its size considerably
and eliminate unnecessary operations on fence names.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: mdss: Speed up mdss_mdp_get_format_params for UBWC formats
Sultan Alsawaf [Sun, 5 May 2019 03:03:21 +0000 (20:03 -0700)]
msm: mdss: Speed up mdss_mdp_get_format_params for UBWC formats

In mdss_mdp_get_format_params, a very large array (mdss_mdp_format_map)
is scanned for a requested format first, and then when the format is
not found in the large array, a small array (mdss_mdp_format_ubwc_map)
is scanned for the requested format. This results in significant
overhead from needlessly scanning the large array for UBWC formats.

To fix this, scan the much-smaller mdss_mdp_format_ubwc_map array first
to search for a requested format.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoqos: Don't allow userspace to impose restrictions on CPU idle levels
Sultan Alsawaf [Fri, 3 May 2019 07:34:19 +0000 (00:34 -0700)]
qos: Don't allow userspace to impose restrictions on CPU idle levels

Giving userspace intimate control over CPU latency requirements is
nonsense. Userspace can't even stop itself from being preempted, so
there's no reason for it to have access to a mechanism primarily used to
eliminate CPU delays on the order of microseconds.

Remove userspace's ability to send pm_qos requests so that it can't hurt
power consumption.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Remove sync debug name generation from hot path
Sultan Alsawaf [Thu, 18 Apr 2019 03:06:20 +0000 (20:06 -0700)]
msm: kgsl: Remove sync debug name generation from hot path

Generating a sync debug name with snprintf in a hot path results in
excessive CPU time wasted on unneeded debug info. Remove the name
generation entirely to cut down CPU waste in the GPU's rendering hot
path.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: mdss: Remove sync debug name generation from hot path
Sultan Alsawaf [Thu, 18 Apr 2019 03:05:02 +0000 (20:05 -0700)]
msm: mdss: Remove sync debug name generation from hot path

Generating a sync debug name with snprintf in a hot path results in
excessive CPU time wasted on unneeded debug info. Remove the name
generation entirely to cut down CPU waste in the frame render hot path.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agosynaptics_dsx_force: Require low latency
Siarhei Vishniakou [Thu, 28 Jun 2018 09:53:18 +0000 (10:53 +0100)]
synaptics_dsx_force: Require low latency

Currently, CPU can enter deep sleep while waiting for data on the i2c
bug. That means an i2c read of 8 bytes can take as long as 10 ms, which
would overrun the desired interrupt handling time.
Use pm qos to require low latency and prevent CPU from entering deep
sleep while handling touch interrupts.

Bug: 110939384
Test: look at the i2c read traces:
1) ./external/chromium-trace/systrace.py --atrace-categories=view,wm,am,app,gfx,i2c,sched,irq,video,power,input,workq,freq
2) perform a fling
3) review the i2c read duration on the touchscreen bus

Change-Id: Icf8ab09324003a85af70517769ced3bae52f705c
Signed-Off-By: Siarhei Vishniakou <svv@google.com>
Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
[wight554: adapted for synaptics_dsx_force]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agomsm: clock-osm: Use CLKFLAG_NO_RATE_CACHE for pwrcl and perfcl clk
Sultan Alsawaf [Mon, 17 Jul 2017 02:52:13 +0000 (19:52 -0700)]
msm: clock-osm: Use CLKFLAG_NO_RATE_CACHE for pwrcl and perfcl clk

Clusters can have frequency change requests ignored when
they come online without having this flag set.
This can result in clusters running at their default frequency
instead of the frequency chosen by the CPU governor.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agobase: dd: Continue probe deferral forever as needed after late_initcall
Sultan Alsawaf [Mon, 15 Apr 2019 03:50:47 +0000 (20:50 -0700)]
base: dd: Continue probe deferral forever as needed after late_initcall

Currently, the probe deferral mechanism gives up on deferring probe
after late_initcall is complete, which could leave some very
slow-to-start drivers broken after the kernel finishes starting up.

Since we don't want to leave behind any drivers that still need probing
after late_initcall, continue the probe deferral sequence forever after
late_initcall until there are no more devices left that are requesting
probe deferral.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoqpnp-fg-gen3: Limit how frequently fg data can be queried
Sultan Alsawaf [Sat, 20 Jul 2019 17:22:54 +0000 (10:22 -0700)]
qpnp-fg-gen3: Limit how frequently fg data can be queried

Querying the fuelgauge for data is expensive, so doing it frequently can
result in a significant increase in power consumption. The fuelgauge
also only generates fresh statistics once per second.

Limit how frequently data queries can be sent to 2 seconds in order to
prevent fuelgauge queries from consuming too much power. Only do this
while there is no USB cable connected to the device, since the charging
drivers need fresh statistics when there's a USB cable connected.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoARM: dts: msm: Disable PM8005 GPIOs
Sultan Alsawaf [Mon, 13 Aug 2018 21:18:29 +0000 (14:18 -0700)]
ARM: dts: msm: Disable PM8005 GPIOs

All of these are disabled and not used on wahoo. Fixes the following init
errors:
[    0.310877] c0      1 qcom,qpnp-pin 800f000.qcom,spmi:qcom,pm8005@4:gpios: qpnp_pin_probe: no device nodes specified in topology
[    0.310901] c0      1 qcom,qpnp-pin: probe of 800f000.qcom,spmi:qcom,pm8005@4:gpios failed with error -22

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoARM: dts: msm8998: Set GPU idle timeout to 64 ms
Sultan Alsawaf [Sun, 12 Aug 2018 02:44:19 +0000 (19:44 -0700)]
ARM: dts: msm8998: Set GPU idle timeout to 64 ms

This matches the ULPS timeout used in MDSS; no need to keep the GPU
running after the display has decided to enter a low-power state.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: ipa3: Fix redundant wakelock releases in error paths
Sultan Alsawaf [Sat, 30 Jun 2018 03:04:40 +0000 (12:04 +0900)]
msm: ipa3: Fix redundant wakelock releases in error paths

In the error paths here, these functions are re-scheduled when they fail;
in other words, these functions are run repeatedly until they succeed.

Since the ipa3 wakelock is released before checking for errors, it can be
released more than once when there is an error and the function that errors
out needs to be re-run.

To fix this, only release the ipa3 wakelock upon success in these functions.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agonet: ipc_router: Decrement ref count for remote port
Deepak Kumar Singh [Wed, 19 Sep 2018 11:45:17 +0000 (17:15 +0530)]
net: ipc_router: Decrement ref count for remote port

Ref count for remote port pointer is not being decremented
at function exit thereby causing memory leak of 128 byte.

Decrementing ref count for remote port pointer after its usage is done.

CRs-Fixed: 2315498
Change-Id: Ida00220201f3dba589a65d9b2ba84b83d6b00004
Signed-off-by: Deepak Kumar Singh <deesin@codeaurora.org>
[wight554: fix conflict]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agousb: pd: Fix memory leak in usbpd_create()
Jack Pham [Wed, 14 Nov 2018 20:01:02 +0000 (12:01 -0800)]
usb: pd: Fix memory leak in usbpd_create()

In both the usbpd_create() failure path and usbpd_destroy(),
some associated allocations, namely the string allocated from
dev_set_name() as well as the resource-mananaged dual_role_instance
structure were not getting freed. These were detected by kmemleak.

unreferenced object 0xffffffe158c37c80 (size 128):
  comm "kworker/6:1", pid 198, jiffies 4294938493 (age 469.090s)
  hex dump (first 32 bytes):
    75 73 62 70 64 30 00 6b 6b 6b 6b 6b 6b 6b 6b 6b  usbpd0.kkkkkkkkk
    6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
  backtrace:
    [<ffffff894d897f38>] kmemleak_alloc+0x60/0xc0
    [<ffffff894ca3ca98>] __kmalloc_track_caller+0x220/0x3bc
    [<ffffff894cc12d00>] kvasprintf+0x80/0x10c
    [<ffffff894cc12dfc>] kvasprintf_const+0x70/0xe4
    [<ffffff894d8892d8>] kobject_set_name_vargs+0x5c/0xe8
    [<ffffff894cf3afdc>] dev_set_name+0x84/0xb0
    [<ffffff894d16aa6c>] usbpd_create+0x84/0x700
    [<ffffff894d172d14>] pdphy_probe+0x21c/0x2ec
    [<ffffff894cf42d88>] platform_drv_probe+0x5c/0xb0
    [<ffffff894cf40208>] driver_probe_device+0x2e8/0x41c
    [<ffffff894cf40c80>] __device_attach_driver+0xcc/0x144
    [<ffffff894cf3e374>] bus_for_each_drv+0x80/0xc8
    [<ffffff894cf40464>] __device_attach+0xa4/0x154
    [<ffffff894cf40534>] device_initial_probe+0x20/0x2c
    [<ffffff894cf3e518>] bus_probe_device+0x34/0x8c
    [<ffffff894cf40a1c>] deferred_probe_work_func+0xcc/0x16c

unreferenced object 0xffffffe158c00580 (size 128):
  comm "kworker/6:1", pid 198, jiffies 4294938493 (age 469.090s)
  hex dump (first 32 bytes):
    78 5d c9 58 e1 ff ff ff 78 5d c9 58 e1 ff ff ff  x].X....x].X....
    24 ef 0c 4d 89 ff ff ff 80 b0 3a 59 e1 ff ff ff  $..M......:Y....
  backtrace:
    [<ffffff894d897f38>] kmemleak_alloc+0x60/0xc0
    [<ffffff894ca3ca98>] __kmalloc_track_caller+0x220/0x3bc
    [<ffffff894cf44198>] devres_alloc_node+0x34/0x70
    [<ffffff894d0cedec>] devm_dual_role_instance_register+0x40/0x178
    [<ffffff894d16af6c>] usbpd_create+0x584/0x700
    [<ffffff894d172d14>] pdphy_probe+0x21c/0x2ec
    [<ffffff894cf42d88>] platform_drv_probe+0x5c/0xb0
    [<ffffff894cf40208>] driver_probe_device+0x2e8/0x41c
    [<ffffff894cf40c80>] __device_attach_driver+0xcc/0x144
    [<ffffff894cf3e374>] bus_for_each_drv+0x80/0xc8
    [<ffffff894cf40464>] __device_attach+0xa4/0x154
    [<ffffff894cf40534>] device_initial_probe+0x20/0x2c
    [<ffffff894cf3e518>] bus_probe_device+0x34/0x8c
    [<ffffff894cf40a1c>] deferred_probe_work_func+0xcc/0x16c
    [<ffffff894c8d1c64>] process_one_work+0x1c0/0x3d4
    [<ffffff894c8d19a4>] process_scheduled_works+0x28/0x40

Both of these can be fixed by making sure to use put_device()
instead of simply kfree(pd), as that will make sure to call
additional cleanup routines for the associated objects.

Change-Id: Id755ddef66308c7d10217b2b8ef56c47421188a5
Signed-off-by: Jack Pham <jackp@codeaurora.org>
4 years agousb: dwc3-msm: Fix memory leak of dwc3 child device
Jack Pham [Sun, 25 Nov 2018 01:36:41 +0000 (17:36 -0800)]
usb: dwc3-msm: Fix memory leak of dwc3 child device

In case of failed probe or driver removal, the dwc3 child device
is left with an extra reference count and hence does not get
cleaned up properly, resulting in a memory leak. kmemleak reports
the following (and others):

unreferenced object 0xffffffdf5934a600 (size 128):
  comm "kworker/2:1", pid 83, jiffies 4294938474 (age 2208.110s)
  hex dump (first 32 bytes):
    00 00 60 0a 00 00 00 00 ff cc 60 0a 00 00 00 00  ..`.......`.....
    a0 5f 2b 7d df ff ff ff 00 02 00 00 00 00 00 00  ._+}............
  backtrace:
    [<ffffff9aeb4a0cb8>] kmemleak_alloc+0x60/0xc0
    [<ffffff9aea63b51c>] __kmalloc+0x220/0x3bc
    [<ffffff9aeafdd5b8>] of_device_alloc+0x98/0x1a8
    [<ffffff9aeafdd87c>] of_platform_device_create_pdata+0x58/0xcc
    [<ffffff9aeafddc38>] of_platform_bus_create+0x220/0x438
    [<ffffff9aeafdded8>] of_platform_populate+0x88/0x104
    [<ffffff9aeacf10f8>] dwc3_msm_probe+0xc7c/0x12f0
    [<ffffff9aeab46514>] platform_drv_probe+0x5c/0xb0
    [<ffffff9aeab43994>] driver_probe_device+0x2e8/0x41c
    [<ffffff9aeab4440c>] __device_attach_driver+0xcc/0x144
    [<ffffff9aeab41b00>] bus_for_each_drv+0x80/0xc8
    [<ffffff9aeab43bf0>] __device_attach+0xa4/0x154
    [<ffffff9aeab43cc0>] device_initial_probe+0x20/0x2c
    [<ffffff9aeab41ca4>] bus_probe_device+0x34/0x8c
    [<ffffff9aeab441a8>] deferred_probe_work_func+0xcc/0x16c
    [<ffffff9aea4d1fe4>] process_one_work+0x1c0/0x3d4

Plug this by adding a call to platform_device_put() which balances
the implicit get_device() from the of_find_device_by_node() call
done during probe.

Change-Id: I1e590cfe14ebbb66005b41f6dfa6a56df9489288
Signed-off-by: Jack Pham <jackp@codeaurora.org>
4 years agomsm: pcie: Fix uninitialized pointer usage in msm_pcie_debug_info()
Sultan Alsawaf [Wed, 31 May 2017 22:39:11 +0000 (15:39 -0700)]
msm: pcie: Fix uninitialized pointer usage in msm_pcie_debug_info()

pdev is used uninitialized in the PCIE_DBG_FS() invocations above its
initialization. Fix it.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: camera: isp: Fix memory leaks in vfe probe
Sultan Alsawaf [Tue, 21 Mar 2017 17:42:56 +0000 (10:42 -0700)]
msm: camera: isp: Fix memory leaks in vfe probe

Memory is needlessly allocated to vfe_parent_dev and vfe_parent_dev->common_sd
and never freed.

Since the allocated memory is not used anywhere outside of vfe_probe(),
and since it's unnecessary, just remove the allocations entirely and use a
stack variable instead.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: mdss: Don't cache the address of a stack variable in timings init
Sultan Alsawaf [Tue, 21 Mar 2017 17:12:10 +0000 (10:12 -0700)]
msm: mdss: Don't cache the address of a stack variable in timings init

When the panel timings are parsed, a stack-allocated variable is used to
store the parsed data; however, this creates two problems. The first
problem is that this creates a memory leak since a kstrdup() address is
stored into the stack-allocated variable at the end of the
mdss_dsi_panel_timing_from_dt() function. The second problem this creates
is that the address of the stack-allocated variable is stored into the
current_timing struct member (inside mdss_dsi_panel_timing_switch()) for
future use in the driver.

Since the data that current_timing points to is expected to persist long
after init, allocate memory for the timing settings to fix the issues.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agosoc: qcom: watchdog_v2: Fix memory leaks when memory_dump_v2 isn't built
Sultan Alsawaf [Tue, 21 Mar 2017 08:06:00 +0000 (01:06 -0700)]
soc: qcom: watchdog_v2: Fix memory leaks when memory_dump_v2 isn't built

When the memory_dump_v2.c driver isn't built (CONFIG_MSM_MEMORY_DUMP_V2=n),
an inline version of msm_dump_data_register() will be used that does
nothing. This means that all memory allocated with the intention of going
to msm_dump_data_register() will be leaked.

Fix this by ignoring the entire code block when CONFIG_MSM_MEMORY_DUMP_V2
is disabled.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: Julian Liu <wlootlxt123@gmail.com>
4 years agopinctrl: qcom: Update irq handle for GPIO pins
Archana Sathyakumar [Wed, 26 Jul 2017 13:37:51 +0000 (07:37 -0600)]
pinctrl: qcom: Update irq handle for GPIO pins

Default handle_irq for tlmm irq chip is handle_edge_irq. For direct
connect GPIOs, the handle_irq is not changed unlike non-direct connect
GPIOs. This causes an interrupt storm for level trigger types as
handle_edge_irq does not mask the interrupt within the function. Change
this to handle_fasteoi_irq such that both level and edge interrupts are
handled correctly.

Change-Id: I79f0d4d92145f85a8043875301400ecf36b46c7b
Signed-off-by: Archana Sathyakumar <asathyak@codeaurora.org>
4 years agocrypto: Make CRYPTO_DEV_QCE depend on CRYPTO_DEV_QCRYPTO being disabled
Sultan Alsawaf [Thu, 17 May 2018 02:57:56 +0000 (19:57 -0700)]
crypto: Make CRYPTO_DEV_QCE depend on CRYPTO_DEV_QCRYPTO being disabled

CRYPTO_DEV_QCE and CRYPTO_DEV_QCRYPTO both yield a qcrypto.o with
matching platform device names, so one of them gets ignored by the
platform device driver since it's redundant.

CRYPTO_DEV_QCRYPTO's qcrypto.o is the up-to-date one, so it should take
precedence and disable CRYPTO_DEV_QCE when it's built.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>