[CPUFREQ] Don't set stat->last_index to -1 if the pol->cur has incorrect value.

If the driver submitted an non-existing pol>cur value (say it
used the default initialized value of zero), when the cpufreq
stats tries to setup its initial values it incorrectly sets
stat->last_index to -1 (or 0xfffff...). And cpufreq_stats_update
tries to update at that index location and fails.

This can be caused by:

stat->last_index = freq_table_get_index(stat, policy->cur);

not finding the appropiate frequency in the table (b/c the policy->cur
is wrong) and we end up crashing. The fix however is
concentrated in the 'cpufreq_stats_update' as the last_index
(and old_index) are updated there. Which means it can reset
the last_index to -1 again and on the next iteration cause a crash.

Without this patch, the following crash is observed:

powernow-k8: Found 1 AMD Athlon(tm) 64 Processor 3700+ (1 cpu cores) (version 2.20.00)
powernow-k8: fid 0x2 (1000 MHz), vid 0x12
powernow-k8: fid 0xa (1800 MHz), vid 0xa
powernow-k8: fid 0xc (2000 MHz), vid 0x8
powernow-k8: fid 0xe (2200 MHz), vid 0x8
Marking TSC unstable due to cpufreq changes
powernow-k8: fid trans failed, fid 0x2, curr 0x0
BUG: unable to handle kernel paging request at ffff880807e07b78
IP: [<ffffffff81479163>] cpufreq_stats_update+0x46/0x5b
.. snip..
Pid: 1, comm: swapper Not tainted 3.0.0-rc2 #45 MICRO-STAR INTERNATIONAL CO., LTD MS-7094/MS-7094
..snip..
Call Trace:
 [<ffffffff81479248>] cpufreq_stat_notifier_trans+0x48/0x7c
 [<ffffffff81095d68>] notifier_call_chain+0x32/0x5e
 [<ffffffff81095e6b>] __srcu_notifier_call_chain+0x47/0x63
 [<ffffffff81095e96>] srcu_notifier_call_chain+0xf/0x11
 [<ffffffff81477e7a>] cpufreq_notify_transition+0x111/0x134
 [<ffffffff8147b0d4>] powernowk8_target+0x53b/0x617
 [<ffffffff8147723a>] __cpufreq_driver_target+0x2e/0x30
 [<ffffffff8147a127>] cpufreq_governor_dbs+0x339/0x356
 [<ffffffff81477394>] __cpufreq_governor+0xa8/0xe9
 [<ffffffff81477525>] __cpufreq_set_policy+0x132/0x13e
 [<ffffffff8147848d>] cpufreq_add_dev_interface+0x272/0x28c

Reported-by: Tobias Diedrich <ranma+xen@tdiedrich.de>
Tested-by: Tobias Diedrich <ranma+xen@tdiedrich.de>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Dave Jones <davej@redhat.com>
Revert "clean up merge error"

This reverts commit 9bb51f3a9b4fabfd5b9ec38c4a66a7a1c1f87809.
base: genlock: Use a signed long for the result from wait_timeout

interruptible_wait_timeout returns a signed long, so make sure that
we use a signed long to hold the result. Using an unsigned value would
horribly misinterpet an error such as -ERESTARTSYS.

CRs-Fixed: 341347
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit be669bc92358653a46c63f2352e6d981f9ed3bdf)

Change-Id: Ifcf555f8719f9c74fdb6d8b5cf2a32582988335b
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
base: genlock: allow synchronization with a single gralloc handle

In order to support synchronization in a process with a single
gralloc handle we require the ability to write lock a buffer
while it is already read locked by the same handle. This change
extends the concept of an exclusive write lock or recursive read
locks to a genlock handle (rather than the genlock lock).
Genlock cannot provide deadlock protection because the same
handle can be used simultaneously by a producer and consumer.
In practice an error will still be generated when the timeout
expires.

CRs-fixed: 356263

Signed-off-by: Jeff Boody <jboody@codeaurora.org>
(cherry picked from commit 6d9076fe46bcba71986a25cf357e71a4d83958c1)

Change-Id: I5d02591586023f4b622915522e2e038c16c9f2f2
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
sched, autogroup: Stop going ahead if autogroup is disabled

when autogroup is disable from the beginning,
sched_autogroup_create_attach()
  autogroup_move_group()                    <== 1
    sched_move_task()                       <== 2
      task_move_group_fair()
        set_task_rq()
          task_group()
            autogroup_task_group()

We go the whole path without doing anything useful.

Then stop going further if autogroup is disabled.

But there will be a race window between 1 and 2, in which
sysctl_sched_autogroup_enabled is enabled. This issue
will be toke by following patch.

Signed-off-by: Yong Zhang <yong.zhang0@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
LKML-Reference: <1298185696-4403-4-git-send-email-yong.zhang0@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
sched, autogroup: Stop claiming ownership of the root task group

Disown it, and only display autogroup association if one exists.

Signed-off-by: Mike Galbraith <efault@gmx.de>
Reviewed-by: Yong Zhang <yong.zhang0@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1298383320.8036.5.camel@marge.simson.net>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Revert "Revert "drivers: misc: pass miscdevice pointer via file private data""

This reverts commit 69884b95102c2e187d04ce17142b31f0c8ce2cdb.
more memory changes from cafs/msm-2.6.38
rcu: introduce kfree_rcu()

Many rcu callbacks functions just call kfree() on the base structure.
These functions are trivial, but their size adds up, and furthermore
when they are used in a kernel module, that module must invoke the
high-latency rcu_barrier() function at module-unload time.

The kfree_rcu() function introduced by this commit addresses this issue.
Rather than encoding a function address in the embedded rcu_head
structure, kfree_rcu() instead encodes the offset of the rcu_head
structure within the base structure.  Because the functions are not
allowed in the low-order 4096 bytes of kernel virtual memory, offsets
up to 4095 bytes can be accommodated.  If the offset is larger than
4095 bytes, a compile-time error will be generated in __kfree_rcu().
If this error is triggered, you can either fall back to use of call_rcu()
or rearrange the structure to position the rcu_head structure into the
first 4096 bytes.

Note that the allowable offset might decrease in the future, for example,
to allow something like kmem_cache_free_rcu().

The new kfree_rcu() function can replace code as follows:

	call_rcu(&p->rcu, simple_kfree_callback);

where "simple_kfree_callback()" might be defined as follows:

	void simple_kfree_callback(struct rcu_head *p)
	{
		struct foo *q = container_of(p, struct foo, rcu);

		kfree(q);
	}

with the following:

	kfree_rcu(&p->rcu, rcu);

Note that the "rcu" is the name of a field in the structure being
freed.  The reason for using this rather than passing in a pointer
to the base structure is that the above approach allows better type
checking.

This commit is based on earlier work by Lai Jiangshan and Manfred Spraul:

Lai's V1 patch: http://lkml.org/lkml/2008/9/18/1
Manfred's patch: http://lkml.org/lkml/2009/1/2/115

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Reviewed-by: David Howells <dhowells@redhat.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
rcu: optimize rcutiny

rcu_sched_qs() currently calls local_irq_save()/local_irq_restore() up
to three times.

Remove irq masking from rcu_qsctr_help() / invoke_rcu_kthread()
and do it once in rcu_sched_qs() / rcu_bh_qs()

This generates smaller code as well.

   text	   data	    bss	    dec	    hex	filename
   2314	    156	     24	   2494	    9be	kernel/rcutiny.old.o
   2250	    156	     24	   2430	    97e	kernel/rcutiny.new.o

Fix an outdated comment for rcu_qsctr_help()
Move invoke_rcu_kthread() definition before its use.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
update pmem per caf

use the older 38 version (before the big update)
add system allocator and removes htc hack inherited
with last pmem update
msm: remove support for hw3d

fixes warning:
In file included from drivers/video/msm/mdp_ppp.c:22:
include/linux/android_pmem.h:56:1: warning: "HW3D_WAIT_FOR_INTERRUPT" redefined
In file included from drivers/video/msm/mdp_ppp.c:19:
include/linux/msm_hw3d.h:27:1: warning: this is the location of the previous definition

also sets put_img back to static
configs: evervolv: enable AUTOGROUP
configs: evervolv unset KALLSYMS

reduces kernel size by .15mb
kgsl: cleanup
[cpufreq] add smartassV2 governor
configs: evervolv build smartassv2
base: genlock: remove BIT macro usage

The BIT macro is not defined for !_KERNEL_ resulting in compile errors.

CRs-fixed: 356263
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
(cherry picked from commit 0977510e0f72b2f1a24f41d5154c2f1b80c96d9a)

Change-Id: Iaf188a1af838c98ca30ce216d7be8ddf85db700c
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
kgsl: fastforward -> ics_chocolate 3.8

commit bcf5ae04a9bf744a7a3d119c93d439a682404877
Author: Olav Haugan <ohaugan@codeaurora.org>
Date:   Tue May 8 08:42:49 2012 -0700

    iommu: Fix flags passed to iommu map functions.

    iommu map functions requires clients to specify whether
    the mappings should be read only or read-write (write only
    is not supported). Ensure clients specify the appropriate
    flags when calling map functions.

    Change-Id: If42b4b0367b4311aa36d3063979ef04af3a43fc6
    Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
msm: boards: update kgsl_3d0_pdata