cpufreq: Fix freq limit init for cores resuming from hotplug

In the scenario that a non-primary core is resuming from a hotplug, retain cpu0's min max to avoid being reset back to default min/max. There might be some underlying issue on why this is not already done natively... but hey I'm just here for a hotfix.

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Logger: Merge Upstream stuff from N5

* Most importantly the ability to turn off this stupid thing

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Defconfig: Enable KALLYSYMS

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
ext4: avoid bh leak in retry path of ext4_expand_extra_isize_ea()

commit dcb9917ba041866686fe152850364826c4622a36 upstream.

Reported-by: Dave Jones <davej@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
ext4: fix use-after-free in ext4_mb_new_blocks

commit 4e8d2139802ce4f41936a687f06c560b12115247 upstream.

ext4_mb_put_pa should hold pa->pa_lock before accessing pa->pa_count.
While ext4_mb_use_preallocated checks pa->pa_deleted first and then
increments pa->count later, ext4_mb_put_pa decrements pa->pa_count
before holding pa->pa_lock and then sets pa->pa_deleted.

* Free sequence
ext4_mb_put_pa (1):		atomic_dec_and_test pa->pa_count
ext4_mb_put_pa (2):		lock pa->pa_lock
ext4_mb_put_pa (3):			check pa->pa_deleted
ext4_mb_put_pa (4):			set pa->pa_deleted=1
ext4_mb_put_pa (5):		unlock pa->pa_lock
ext4_mb_put_pa (6):		remove pa from a list
ext4_mb_pa_callback:		free pa

* Use sequence
ext4_mb_use_preallocated (1):	iterate over preallocation
ext4_mb_use_preallocated (2):	lock pa->pa_lock
ext4_mb_use_preallocated (3):		check pa->pa_deleted
ext4_mb_use_preallocated (4):		increase pa->pa_count
ext4_mb_use_preallocated (5):	unlock pa->pa_lock
ext4_mb_release_context:	access pa

* Use-after-free sequence
[initial status]		<pa->pa_deleted = 0, pa_count = 1>
ext4_mb_use_preallocated (1):	iterate over preallocation
ext4_mb_use_preallocated (2):	lock pa->pa_lock
ext4_mb_use_preallocated (3):		check pa->pa_deleted
ext4_mb_put_pa (1):		atomic_dec_and_test pa->pa_count
[pa_count decremented]		<pa->pa_deleted = 0, pa_count = 0>
ext4_mb_use_preallocated (4):		increase pa->pa_count
[pa_count incremented]		<pa->pa_deleted = 0, pa_count = 1>
ext4_mb_use_preallocated (5):	unlock pa->pa_lock
ext4_mb_put_pa (2):		lock pa->pa_lock
ext4_mb_put_pa (3):			check pa->pa_deleted
ext4_mb_put_pa (4):			set pa->pa_deleted=1
[race condition!]		<pa->pa_deleted = 1, pa_count = 1>
ext4_mb_put_pa (5):		unlock pa->pa_lock
ext4_mb_put_pa (6):		remove pa from a list
ext4_mb_pa_callback:		free pa
ext4_mb_release_context:	access pa

AddressSanitizer has detected use-after-free in ext4_mb_new_blocks
Bug report: http://goo.gl/rG1On3

Signed-off-by: Junho Ryu <jayr@google.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
ext4: don't calculate total xattr header size unless needed

The function ext4_expand_extra_isize_ea() doesn't need the size of all
of the extended attribute headers.  So if we don't calculate it when
it is unneeded, it we can skip some undeeded memory references, and as
a bonus, we eliminate some kvetching by static code analysis tools.

Addresses-Coverity-Id: #741291

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
writeback: Fix occasional slow sync(1)

In case when system contains no dirty pages, wakeup_flusher_threads()
will submit WB_SYNC_NONE writeback for 0 pages so wb_writeback() exits
immediately without doing anything. Thus sync(1) will write all the
dirty inodes from a WB_SYNC_ALL writeback pass which is slow.

Fix the problem by using get_nr_dirty_pages() in
wakeup_flusher_threads() instead of calculating number of dirty pages
manually. That function also takes number of dirty inodes into account.

CC: stable@vger.kernel.org
Reported-by: Paul Taysom <taysom@chromium.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Cristoforo Cataldo <cristoforo.cataldo@gmail.com>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Revert "Make Fsync Configurable"

This reverts commit a22f8ebbd4d27c3dce87ae4bfd76775561c37fac.

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>

Conflicts:
	fs/sync.c
Revert "Revert "Make Fsync Configurable""

This reverts commit 5b2ace9e35f2156ebafd8d2d08783e326d6756f6.
Drop GPU

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
hercules: Disable 2D GPU

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
hercules: Fix up ACPU

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
cpufreq: Introduce CPU-boost framework

The CPU-boost framework allows you to place hooks in various drivers to boost the CPU for either a specified duration or indefinitely (until it is manually unboosted). If a new boost request is sent while the CPU is boosted then the new boost request will take precedence and immediately override the current boost.

Signed-off-by: Sultanxda <sultanxda@gmail.com>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Add initial CPU-boost hooks

CPU is currently boosted for these activities:
*Taking a picture (1188MHz for 3s)
*Starting video playback (1242MHz for 5s)
*Recording video (594MHz indefinite)
*Turning on the display (972MHz for 7s)

Signed-off-by: Sultanxda <sultanxda@gmail.com>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
cpu_boost: Respect max frequency

If the requested boost frequency is greater than the maxfreq then reduce the boost to 2 steps below the current maxfreq (108MHz below the current maxfreq). If the maxfreq is 486MHz or lower then the boost will be canceled.

Signed-off-by: Sultanxda <sultanxda@gmail.com>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
msm8x60_celox: Add CPU-boost hook in ts power-on sequence

The touchscreen is powered on roughly 100ms before the panel is powered on. This gives us an extra 100ms of earlier boosting when waking the device from sleep.

Signed-off-by: Sultanxda <sultanxda@gmail.com>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
cpu_boost: Add sysfs interface

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
hercules: Enable CPU Boost

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
sweep2wake: Add sensitive option

This is for users (like myself) who feel like the current s2w is too tedious/precise to trigger. This option, when enabled only requires the 1st and last button to be triggered making it easier to initiate with a thumb or without making full contact & discontact with all 4 buttons.

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
selinux: add a ugly workaround to bail early when selinux tries to free a socket that is still in use and it ends in a Kernel panic. These lines are from opensource.samsung.com. While this will most likely put a bandaid over this Kernel panic it does not fix the bug so it might occur somewhere else if the same conditions are met but since I have only seen panics from this hook then we may as well sleep in peace.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>