msm: cpuidle: Move msm_cpuidle_get_deep_idle_latency out of ifdef

Some older chipsets such as 7x30 or 7x27 don't use cpuidle for
their idle PM implementation. Since some drivers want to use
msm_cpuidle_get_deep_idle_latency() on these targets, move the
definition outside of the #ifdef. This guarantees that the
function will always return what we want as long as CONFIG_PM is
enabled (which is really what decides if we support idle PM).

Change-Id: Iba0d631ee706ffb7649e139aead8d602c60982cb
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
fs: yaffs2: Add null pointer check before dereferencing inode

In yaffs_rename(), d_entry->d_inode can be NULL if the
target directory doesn't exist or if there is any race
condition such as target directory being deleted while
renaming another directory to target directory name.
Avoid dereferencing d_inode in such cases.

CRs-Fixed: 360748
Change-Id: If95b4992f1056fea78f2e1bd54253cd5c8aac93d
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
usb: gadget: Fix RmNET control to always clear RTS bit

The MODEM requires RTS to be cleared for RmNET use case.
The original code clear all SMD tiocm bits upon USB connection.
This fix leaves the RTS bit set, which is the SMD default.

Change-Id: Ie3aaa285c9a1598dfd7408f062ea7af2f391a7dd
CRs-Fixed: 370682
Signed-off-by: Amit Blay <ablay@codeaurora.org>
checkpatch: strlen and strcmp should not be banned

Software security is an important issue, in general, but it is
especially important in Linux kernel code.  Buffer overflows can have
wide-reaching ramifications and can often be readily exploited to
compromise the entire system.  It is important for every developer to
be aware of security issues while writing code.

However, I've noticed a few "rules" about coding that are resulting in
code that isn't any more secure, and has the disadvantage of obscuring
what the code is doing.  In most instances, the "corrected" code is
actually wrong: we've traded a perceived lack of safety for incorrect
behavior.  These obfuscations also make this code more distant from
upstream kernel standards.

I'm only going to focus here on strcmp/strncmp and strlen/strnlen.  I
choose these two, because in the context of the kernel, it's not easy
to make a general rule, such as "always use the 'n' variant".  These
function have different behavior, and the 'n' isn't just a blanket fix
that makes them better.  In many instances, the correct call is the
plain variant (strcpy has a strlcpy variant which is usually helpful).

Let's start with strlen/strnlen.

	size_t strlen(const char *);
	size_t strnlen(const char *, size_t);

The strlen() function scans for a NUL byte within a string, and
returns the number of characters that had to be skipped to get there.

The strnlen() call is similar, but will stop after after a maximal
number of characters, and return that result.  This variant was
intended for storing variable length strings in fixed-sized buffers,
where the full-length case did not have a trailing NUL.  This storage
model is very uncommon, as is the use of strnlen().

The question becomes, what is the maximal length you should be giving
to strnlen().  If the string is truly variable length (allocated and
filled), there really isn't a meaningful value to use for this.  The
only time that a max length makes sense is when you have something
like:

	char name[MAX_NAME_LENGTH];

but, in this case, strnlen() is still probably not what you want to be
using.  It would be safe to use, if you check the result, and if it is
MAX_NAME_LENGTH, raise some kind of error case.  If later code assumes
there is a NUL at the end, there will still be a buffer overflow.  In
this case, it is much better to check the length before storing it in
this field, and make sure there is room for the NUL.

If the string is a constant, passing in a length doesn't make sense,
since you would have to know the length of the string to check that.
There is no safety issue with calling strlen() on a constant.

So, the simple rule for strnlen()/strlen() is:

  - If the string doesn't have an obvious bound length, such as an
    allocated string, use strlen().

  - If the string is a constant, use strlen().

  - If there is a fixed buffer, strnlen() might make sense, but it is
    probably better to change the design to avoid these types of
    strings.

The only case where strnlen really makes sense is when you have a
string that is passed in from the user.  In this case, it is very
important to check the result, and if the length is at the maximum,
return an error, and don't try to do any processing on the string.

Moving on to strcmp/strncmp.  These functions are similar, except that
they take two string arguments, which gives a lot more combinations.

	int strcmp(const char *, const char *);
	int strncmp(const char *, const char *, size_t);

These will walk both strings (at the same time), and stop when
reaching the first difference between them.  This means that they will
never go further than the length of the shortest string being
compared.  As in strnlen, the max argument to strncmp sets a limit on
the comparison.  Similar to strnlen, the results are unusual when the
limit is reached, but in a sense, even worse, since it may consider
the strings equal without ever reaching the end of either.

Looking over the 200 some uses of strncmp in the msm code, almost all
of them do something akin to:

	strncmp(value, constant, strlen(constant))

If the call has added 1 to the 'strlen' result, the strncmp would just
become an inefficient, but otherwise identical version of strcmp.
However, without the +1, this compares the prefix of 'value' instead
of the entire string.  Only one instance of strncmp in the code
appears to be intentionally checking for a prefix.  The rest have
changed a simple string compare into an unintentional prefix match.

Because there are two strings, it is a little more complex to
determine which to use, but it is very similar.  It might seem that
strncmp() would be useful for checking an unknown buffer (say from
userspace).  However, since strncmp()'s result doesn't distinguish
between finding the end of the string, or hitting the max, there's no
way to know.  Some guidelines:

  - If one of the strings has a known bound length (such as a
    constant, or another string whose length has already been
    checked), AND this bound length is within the expected buffer of
    the other string, it is safe to use strcmp().

  - Otherwise, you may need to use something like strnlen() to
    determine a maximum length before calling strcmp().

  - strncmp() is useful to test a string for a prefix.  No other uses
    make sense.

To facilitate fixing these, remove strlen(), strcmp(), and
strcasecmp() from the list of calls that are banned.  Problems with
these calls need to be caught at a higher level (such as review), and
replacing them with the 'n' variants doesn't help anything.

This will be followed by some patches that fixup the incorrect code
introduced by this "ban".

Change-Id: I77dfe1f2f58e8c951e4b38b23f4ec79f8209b1dc
Signed-off-by: David Brown <davidb@codeaurora.org>
msm: camera: Add support for LED flash for ov8825 cam sensor

LED flash is enabled for OV8825 Camera Sensor.

Change-Id: I47555612bd17f5c750b4e748787d0388076f37fb
Signed-off-by: Lokesh Kumar Aakulu <lkumar@codeaurora.org>
base: genlock: handle error while creating lock/handle inode

A lock/handle inode is required in order to successfully create a
new lock/handle. Failure to report the lock/handle inode error can
result in errors for subsequent function calls.

Change-Id: I622af24e695f4781c4dbf46363931a7da09df677
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
net: sched: Schedule PRIO qdisc when flow control released

The PRIO qdisc supports flow control, such that packet
dequeue can be disabled based on boolean flag 'enable_flow'.
When flow is re-enabled, the latency for new packets
arriving at network driver is high.  To reduce the delay in
scheduling packets, the qdisc will now invoke
__netif_schedule() to expedite dequeue.  This significantly
reduces the latency of packets arriving at network driver.

Change-Id: Ic5fe3faf86f177300d3018b9f60974ba3811641c
CRs-Fixed: 355156
Acked-by: Jimi Shah <jimis@qualcomm.com>
Signed-off-by: Tianyi Gou <tgou@codeaurora.org>
radio-tavarua: Validate whether the current station is good or bad

Provide mechanism to decide whether the currently tuned station
is valid or not.

CRs-Fixed: 371689
Change-Id: I1a28537d242fbb636732b120c9259ad5e7fffcc0
Signed-off-by: Anantha Krishnan <ananthk@codeaurora.org>
tsc2007: Set input property bit to indicate a direct input device

Prop bit is checked in userspace and must be set in
driver in order to be recognized correctly, since it defaults
to mouse pointer.

Change-Id: I5eadfe45baac93b9e315381dcacc5a02c27bc0c9
Signed-off-by: Amy Maloche <amaloche@codeaurora.org>
arm/dt: msm8974: Update PM8941 regulator voltage constraint ranges

Modify the voltage constraint ranges for PMIC PM8941 regulators
LDO 3, LDO 4, and LDO 11 so that they match hardware
documentation guidelines.

Change-Id: Ic0a292e9e79d9d1562b9df04988daad06d027643
Signed-off-by: David Collins <collinsd@codeaurora.org>
msm: pil-q6v4: Update regulator stepping

Hardware profiling has determined that the two step voltage ramp
should be larger for the first step than previously determined.
Instead of stopping at 375mV we should stop at 743.75mV and then
proceed to 1.05V. Update the code accordingly.

Change-Id: I44ffcea4ecc475c1e7f9bfdac44c1a15365a3ea3
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
usb: serial: Check for received data upon unlinking the urb

There is a possibility of runtime suspend in the middle of
data transfer on the rx data path of driver. This results in
the completion of data transfer on bulk IN endpoint with short
packet or integral multiple of 512 bytes. Hence for -ENOENT
transfer status check for non zero data length and pass it to
the consumer in the userspace.

CRs-Fixed: 382161
Change-Id: I72407e8879b6b3b7a9456c1234eec71970272495
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
usb: misc: Add kickstart bridge driver

kickstart bridge driver will be used to download boot images
to mdm, ram-dumps and efs sync.

Change-Id: Id35e2da664ebf4a16c84d6fb67fbf38a2855356a
Signed-off-by: Vamsi Krishna <vskrishn@codeaurora.org>
spinlock_debug: Print offset in addition to symbol name

If one has two spinlocks embedded in a structure that kallsyms
knows about and one of the spinlocks locks up we will print the
name of the containing structure instead of the address of the
lock. This is quite bad, so let's use %pS instead of %ps so we
get an offset into the symbol so we can determine which lock is
having problems.

Change-Id: If6fbb2eb2316b846d96da76c35fcfeadbef64401
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
msm: qdsp5: Increase buffersize of hostPCM interface.

The default audio sample rate of audioflinger is increased
from 44.1k to 48k.Increase the buffersize to take
advantage of that.

Change-Id: I7ffc6c697cb32b6983c9bb5cc6ea73a7a55b5006
Signed-off-by: Sidipotu Ashok <sashok@codeaurora.org>
Perf: Add PMU names to perf output

Output of raw events in perf tools can be hard to distinguish
when multiple PMU's have the same event encoding.

Show the PMU name along with the counter output.

e.g.

 Performance counter stats for 'ls':

          4514688 msm-l2 0x1

Change-Id: I65d4ac03c2fd562519ab78524b37467e7d53dbb3
Signed-off-by: Ashwin Chaugule <ashwinc@codeaurora.org>
mm: add HAVE_MEMBLOCK_NODE_MAP support

ARCH_POPULATES_NODE_MAP in 3.0 is replaced by HAVE_MEMBLOCK_NODE_MAP in
3.4.  add_active_range() is replaced with memblock_set_node().  They do
basically the same thing, but embedding nid field into memblock_region
is much cleaner than a separate early_node_map.

HAVE_MEMBLOCK_NODE_MAP is not selected by default.

See commit 4a2164a7dbf0d3b6a1c2ef6f20c0d54350491a12 for more info.

Change-Id: Icb44a8cea365b2d32df80628a57535a3d46fbd55
Signed-off-by: Junjie Wu <junjiew@codeaurora.org>
trace: Modify timer_start and irq_handler_entry trace events.

The timer_start event now shows whether the timer is
deferrable in case of a low-res timer. The debug_activate
function now includes deferrable flag while calling
trace_timer_start event. irq_handler_entry
event includes the ISR function in the trace event.

Change-Id: Ia2eeb4fa0fae34b301964144dad8bcef7632487c
Signed-off-by: Badhri Jagan Sridharan <badhris@codeaurora.org>
defconfig: 9625: Enable NAND driver, MTD and YAFFS2 configs

Enable all the required config options for NAND controller in
MDM9x25.

Change-Id: Ic4738b12450d114e1b35aeee23fd5bb63499afe7
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
msm: vidc: Increase video driver clients count.

Video driver currently supports registration of 4 clients.
Increasing number of clients count to 6 to support new usecases.
Video driver will limit number of instances to 4.

Change-Id: If00911ef1027b1e44917465791ef3612e6c59ed1
Signed-off-by: Gopikrishnaiah Anandan <agopik@codeaurora.org>