msm: usbaudio: Add check for NULL before dereferencing

kzalloc() and usb_ifnum_to_if() both APIs can return NULL. Current
code is not checking return value and derefencing which may crash
device if it is set to NULL. Fix this by checking return value
against NULL and handling the same.

CRs-Fixed: 562273
Change-Id: I0d2c910f43321e94fc447b19ae3e3207727e24f3
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
usb: adb: Don't set rx_done on every set_alt to fix USBCV failure

ADB driver maintains rx_done to keep a track of whether RX
usb_request is already queued to hardware or not.
Commit 26444ce5 "usb: adb: Don't dequeue request during system
suspend" adds a regression where this flag may mistakenly get
set if host sends explicit SET_INTERFACE after SET_CONFIGURATION.
This results in ADB set_alt getting called back to back without
adb_disable. This behavior is not seen with hosts normally, but
USBCV compliance tester sends these requests.
Setting rx_done in set_alt results in adb_read to mistakenly
assume that RX request got completed with 0 length and it retries
queuing the RX request (which is already with hardware). This
results in usb_ep_queue failure and returning -EIO from adb_read
causes USB re-enumeration. USBCV compliance tests fail due to device
disconnect during test.

Change-Id: Ia5d922712d7805f8f8a3485cecd589871d234adf
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
diag: dci: Safeguard to prevent integer overflow

At certain point in diag driver there can be integer overflow
thus can lead to memory leak. Added a safegaurd for it.

Change-Id: I9347405d8f1f95ed42fe0abf35cbf4c362281bdf
CRs-fixed: 565160
Signed-off-by: Katish Paran <kparan@codeaurora.org>
msm: sps: Add integer wrap check for debugfs buffer

When converting debugfs buffer size to kilobytes value
there is a possible integer overflow and it may result
into negative value.

Fix the issue by adding integer wrap check for buffer
size just before conversion.

CRs-fixed: 564177
Change-Id: If4615561ea6a1c58e8be8c1b72f7881c068d8520
Signed-off-by: Dipen Parmar <dipenp@codeaurora.org>
Merge "msm: sps: Add integer wrap check for debugfs buffer"
usb: gadget: ECM: Check if data interface is UP while bus_suspend

CDC ECM requires DATA interface to support two alternate settings.
Bulk (IO) endpoints must be supported only in 1st alternate setting,
not in the default one. Alternate setting is chosen by host using
SET_INTERFACE command after SET_CONFIGURATION. SET_CONFIG results
in set_alt(0) followed by set_alt(1) when SET_INTERFACE is sent.
There is a possibility of USB bus getting suspended between this
window of SET_CONFIG and SET_INTERFACE. This currently results in
a crash in bus_suspend routine of ECM which assumes that by this
time DATA interface would be up. Fix this by adding a check in
ECM bus_suspend/resume routines to bail out if set_alt(1) is not
yet received by device.

CRs-fixed: 614120
Change-Id: Ic002b75f20d2d4f23f6a5dd7b4df365c25f20e0f
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
USB: msm_otg: Allow platforms to vote for BUS bw on cable connect

Some platforms require voting for NOC bandwidth (and PNOC clocks)
when enabling/disabling USB clocks. It is also recommended to have
NOC running when USB is active or in session.
Hence, allow such platforms to specify MIN BUS vote along with NONE
(or inactive) and MAX USB votes. If MIN vote is not specified then
driver treats NONE vote as MIN vote.
Overall platforms should be passing these votes based on that:
NO vote is used when USB cable is not connected or there is no USB
session. MAX vote is used when USB is operating in peripheral mode
and MIN vote is used for any other scenario e.g. host mode or when
turning off USB clocks as part of putting USB in low power state.
MIN vote shouldn't be a significant value to avoid increase in power
numbers.

CRs-Fixed: 624360
Change-Id: Ia4498356b026963f7a6fda8a30ecbd9c1cd98924
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
ARM: dts: msm: Specify MIN BUS voting as long as USB is active on 9x25

MSM9x25 requires voting for NOC bandwidth (and PNOC clocks) until
USB enters LPM or as long as controller is running. Otherwise clock
gating at PNOC may result in USB controller reporting FATAL error.
Hence, add BUS bandwidth vote for the same.

CRs-Fixed: 624360
Change-Id: Id3620190ba99058c2a0253045517e54b8d1aa3c7
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
msm: audio: qdsp6v2: memeset msm_audio_stats to zero

memeset msm_audio_stats to zero before copying to user space.

Change-Id: Ia0756e3b99ba87e1d188b257e285c961b82276ce
CRs-fixed: 549307
Signed-off-by: Laxminath Kasam <lkasam@codeaurora.org>
msm: qdsp6v2: Deleting kernel driver from arch/arm/mach-msm/qdsp6v2

Driver is registering under misc driver but exists under arch/arm/mach

Change-Id: Ib5e504189b22a67ec322fb8b79fbf7caf4f9ce56
CRs-Fixed: 548017
Signed-off-by: Laxminath Kasam <lkasam@codeaurora.org>
printk: convert byte-buffer to variable-length record buffer

- Record-based stream instead of the traditional byte stream
  buffer. All records carry a 64 bit timestamp, the syslog facility
  and priority in the record header.

- Records consume almost the same amount, sometimes less memory than
  the traditional byte stream buffer (if printk_time is enabled). The record
  header is 16 bytes long, plus some padding bytes at the end if needed.
  The byte-stream buffer needed 3 chars for the syslog prefix, 15 char for
  the timestamp and a newline.

- Buffer management is based on message sequence numbers. When records
  need to be discarded, the reading heads move on to the next full
  record. Unlike the byte-stream buffer, no old logged lines get
  truncated or partly overwritten by new ones. Sequence numbers also
  allow consumers of the log stream to get notified if any message in
  the stream they are about to read gets discarded during the time
  of reading.

- Better buffered IO support for KERN_CONT continuation lines, when printk()
  is called multiple times for a single line. The use of KERN_CONT is now
  mandatory to use continuation; a few places in the kernel need trivial fixes
  here. The buffering could possibly be extended to per-cpu variables to allow
  better thread-safety for multiple printk() invocations for a single line.

- Full-featured syslog facility value support. Different facilities
  can tag their messages. All userspace-injected messages enforce a
  facility value > 0 now, to be able to reliably distinguish them from
  the kernel-generated messages. Independent subsystems like a
  baseband processor running its own firmware, or a kernel-related
  userspace process can use their own unique facility values. Multiple
  independent log streams can co-exist that way in the same
  buffer. All share the same global sequence number counter to ensure
  proper ordering (and interleaving) and to allow the consumers of the
  log to reliably correlate the events from different facilities.

CRs-fixed: 561659
Change-Id: I8fd2cdfe1b9a675f3f707cbd7b180a9c30e58f73
Tested-by: William Douglas <william.douglas@intel.com>
Signed-off-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
Git-commit: 7ff9554bb578ba02166071d2d487b7fc7d860d62
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kmsg: export printk records to the /dev/kmsg interface

Support for multiple concurrent readers of /dev/kmsg, with read(),
seek(), poll() support. Output of message sequence numbers, to allow
userspace log consumers to reliably reconnect and reconstruct their
state at any given time. After open("/dev/kmsg"), read() always
returns *all* buffered records. If only future messages should be
read, SEEK_END can be used. In case records get overwritten while
/dev/kmsg is held open, or records get faster overwritten than they
are read, the next read() will return -EPIPE and the current reading
position gets updated to the next available record. The passed
sequence numbers allow the log consumer to calculate the amount of
lost messages.

  [root@mop ~]# cat /dev/kmsg
  5,0,0;Linux version 3.4.0-rc1+ (kay@mop) (gcc version 4.7.0 20120315 ...
  6,159,423091;ACPI: PCI Root Bridge [PCI0] (domain 0000 [bus 00-ff])
  7,160,424069;pci_root PNP0A03:00: host bridge window [io  0x0000-0x0cf7] (ignored)
   SUBSYSTEM=acpi
   DEVICE=+acpi:PNP0A03:00
  6,339,5140900;NET: Registered protocol family 10
  30,340,5690716;udevd[80]: starting version 181
  6,341,6081421;FDC 0 is a S82078B
  6,345,6154686;microcode: CPU0 sig=0x623, pf=0x0, revision=0x0
  7,346,6156968;sr 1:0:0:0: Attached scsi CD-ROM sr0
   SUBSYSTEM=scsi
   DEVICE=+scsi:1:0:0:0
  6,347,6289375;microcode: CPU1 sig=0x623, pf=0x0, revision=0x0

CRs-fixed: 561659
Change-Id: Ic686ea4a185c331b82df556976e54bb2b49922a7
Cc: Karel Zak <kzak@redhat.com>
Tested-by: William Douglas <william.douglas@intel.com>
Signed-off-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
Git-commit: e11fea92e13fb91c50bacca799a6131c81929986
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kmsg: use do_div() to divide 64bit integer

On Tue, May 8, 2012 at 10:02 AM, Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> kernel/built-in.o: In function `devkmsg_read':
> printk.c:(.text+0x27e8): undefined reference to `__udivdi3'
> Most probably the "msg->ts_nsec / 1000" since
> ts_nsec is a u64 and this is a 32 bit build ...

Change-Id: I1e9712d7427d9f8fbf434abb60f8293ca1d4e5ee
CRs-fixed: 561659
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 5fc3249068c1ed87c6fd485f42ced24132405629
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
printk - fix compilation for CONFIG_PRINTK=n

CRs-fixed: 561659
Change-Id: I74051ca1e9245b8811f5ea68d2869522711d81d6
Reported-by: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 7f3a781d6fd81e397c3928c9af33f1fc63232db6
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
printk() - do not merge continuation lines of different threads

This prevents the merging of printk() continuation lines of different
threads, in the case they race against each other.

It should properly isolate "atomic" single-line printk() users from
continuation users, to make sure the single-line users will never be
merged with the racy continuation ones.

Change-Id: I4d7bd0bf059ec75e693341bde1ef9cc863571a01
CRs-fixed: 561659
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 5c5d5ca51abd728c8de3be43ffd6bb00f977bfcd
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
printk() - restore timestamp printing at console output

The output of the timestamps got lost with the conversion of the
kmsg buffer to records; restore the old behavior.

Document, that CONFIG_PRINTK_TIME now only controls the output of
the timestamps in the syslog() system call and on the console, and
not the recording of the timestamps.

Change-Id: I8ec7f32020dc3b388ac67d9ea13706515d128700
CRs-fixed: 561659
Cc: Joe Perches <joe@perches.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Sasha Levin <levinsasha928@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Reported-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 649e6ee33f73ba1c4f2492c6de9aff2254b540cb
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
printk: correctly align __log_buf

__log_buf must be aligned, because a 64-bit value is written directly
to it as part of struct log. Alignment of the log entries is typically
handled by log_store(), but this only triggers for subsequent entries,
not the very first (or wrapped) entries.

Change-Id: Idc5d44e81b7504a8ebf55bbab5d18c8fcd3e4a69
CRs-fixed: 561659
Cc: Kay Sievers <kay@vrfy.org>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: f8450fca6ecdea38b5a882fdf6cd097e3ec8651c
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
printk: add stub for prepend_timestamp()

Add a stub for prepend_timestamp() when CONFIG_PRINTK is not
enabled.  Fixes this build error:

kernel/printk.c:1770:3: error: implicit declaration of function 'prepend_timestamp'

Change-Id: I1b1fc431932feda313b873ae5c584cb1185845d5
CRs-fixed: 561659
Cc: Kay Sievers <kay@vrfy.org>
Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 1fce677971e29ceaa7c569741fa9c685a7b1052a
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
printk: use mutex lock to stop syslog_seq from going wild

Although syslog_seq and log_next_seq stuff are protected by logbuf_lock
spin log, it's not enough. Say we have two processes A and B, and let
syslog_seq = N, while log_next_seq = N + 1, and the two processes both
come to syslog_print at almost the same time. And No matter which
process get the spin lock first, it will increase syslog_seq by one,
then release spin lock; thus later, another process increase syslog_seq
by one again. In this case, syslog_seq is bigger than syslog_next_seq.
And latter, it would make:
   wait_event_interruptiable(log_wait, syslog != log_next_seq)
don't wait any more even there is no new write comes. Thus it introduce
a infinite loop reading.

I can easily see this kind of issue by the following steps:
  # cat /proc/kmsg # at meantime, I don't kill rsyslog
                   # So they are the two processes.
  # xinit          # I added drm.debug=6 in the kernel parameter line,
                   # so that it will produce lots of message and let that
                   # issue happen

It's 100% reproducable on my side. And my disk will be filled up by
/var/log/messages in a quite short time.

So, introduce a mutex_lock to stop syslog_seq from going wild just like
what devkmsg_read() does. It does fix this issue as expected.

v2: use mutex_lock_interruptiable() instead (comments from Kay)

Change-Id: I5df420c07ff9e52015e0bcf5568a64ff9dedddb8
CRs-fixed: 561659
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Fengguang Wu <fengguang.wu@intel.com>
Acked-By: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 4a77a5a06ec66ed05199b301e7c25f42f979afdc
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
printk: replacing the raw_spin_lock/unlock with raw_spin_lock/unlock_irq

In function devkmsg_read/writev/llseek/poll/open()..., the function
raw_spin_lock/unlock is used, there is potential deadlock case happening.
CPU1: thread1 doing the cat /dev/kmsg:
        raw_spin_lock(&logbuf_lock);
        while (user->seq == log_next_seq) {
when thread1 run here, at this time one interrupt is coming on CPU1 and running
based on this thread,if the interrupt handle called the printk which need the
logbuf_lock spin also, it will cause deadlock.

So we should use raw_spin_lock/unlock_irq here.

Change-Id: If9b5bdb0cce99b0a70b094bef72bf843921b48a8
CRs-fixed: 561659
Acked-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 5c53d819c71c63fdc91f30a59164583f68e2d63a
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>