diag: Perform CRC check on incoming HDLC encoded packet

Diag driver receives HDLC encoded data from the tools and decodes
them. This patch adds checks to the received data. It discards the
packet if the CRC is not correct.

Change-Id: Ie53056844d6d1e6777d15a339896bf6842cfae64
CRs-Fixed: 519902
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: dci: Fix timestamps on dci events

The first event generated by diag on the peripherals will have a
valid timestamp bytes and the subsequent events generated at the
same time will have reduced timestamp bytes to conserve
space in the buffer. Diag driver zeroed out the timestamp bytes
when it encounters DCI events with reduced timestamp bytes. This
patch adds the valid timestamp for those events.

Change-Id: I80b1a7450f605af9bfd8959ea1f26bc9d83b370e
CRs-Fixed: 521415
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: Check correct status variable to send log mask

Diag driver was incorrectly checking the message mask status to
send the log mask control packet to the peripherals. This patch
checks the correct status variable to send the log mask to the
peripherals.

Change-Id: I6733c930e66cabc77c6cfe62b9aa7cd48b9fe13d
CRs-Fixed: 542074
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: NRT read wakelocks held for very long time

During on-device logging with '-b' option,
NRT read wakelocks i.e. diag_nrt_modem_read
and diag_nrt_wcnss_read were held for more than
a day's time. This patch releases the wakelocks
even if SMD channel will be closed.

Change-Id: I7d211aaeaeb8d59369a191c5eef54c02a1b4a61d
CRs-Fixed: 513309
Signed-off-by: Mohit Aggarwal <maggarwa@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: Fix for CRC check for Control byte

0x7E packets can be sent twice in a row.The first 0x7E
is the terminator of the previous command and the next
is a null frame that we should ignore. This patch treats
the 0x7E bytes as packet end only.

Change-Id: I2c02240eead9c61ad8aa6bcf9e920bc63a0574cd
CRs-fixed: 549971
Signed-off-by: Katish Paran <kparan@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: dci: Preventing unitialized stack memcpy operation

At certain point in diag driver there can be memcpy operation
for the unintialized stack. Due to uninitilization of memory
user can obatin valuable information on accessing this stack
in userspace. This patch fixes that issue.

Change-Id: I4bfcf156300132dc426dcadce325e0c76c1d0357
CRs-fixed: 565808
Signed-off-by: Katish Paran <kparan@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: Add new polling command

Diag driver should now support a new polling command for the tools
to recognize the target.

Change-Id: Ia7966cc74c5c74693cebfd64b178831e5ca6f2dd
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: Change format used for printing pointers

Currently, when printing a pointer address the format does not
take advantage of using the pointer conversion specifier. Make
changes to use the pointer conversion specifier.

Change-Id: I27fd10c33952de9e44066c15256c7f29df6c4dd8
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: Fix for diag debugfs buffer overflow

Diag debugfs buffer has potential buffer overflow scenario which can cause
memory corruption. Added safeguard to prevent this.

Crs-fixed: 585147
Change-Id: Ie1f099bb4bb626adff99ae225966aef70c1bc15e
Signed-off-by: Sreelakshmi Gownipalli <sgownipa@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: dci: Index DCI client table by client id

Diag driver maintains a table of all DCI clients. This table
is currently indexed by the PID of the clients. Make changes
to index the table base on an unique client id.

Change-Id: I57bfab9eae1381882b8eb6270d7ac212e0aaf271
CRs-fixed: 590721
Signed-off-by: Katish Paran <kparan@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: msm: qdsp6v2: Check for null pointers

Add check for null data pointer in
adm_callback() and log error message if
true.

CRs-Fixed: 575222
Change-Id: I88a4d19cc2e78610249e404bce93831557995fab
Signed-off-by: Kenneth Westfield <kwestfie@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: msm: qdsp6v2: Check for null data pointer

Add check for null data pointer in
aprv2_core_fn_q() and log error message if
true.

CRs-Fixed: 575228
Change-Id: I0d02913ced422ff3f396375c70ad6929908ee58d
Signed-off-by: Kenneth Westfield <kwestfie@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: msm: qdsp6v2: Check for null pointer

Add check for null pointer after kmalloc in
config_debug_fs_init() and log error message if
true.

CRs-Fixed: 575229
Change-Id: I9824ffa447153581efdf7cb87838538d1e99b0f2
Signed-off-by: Kenneth Westfield <kwestfie@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: msm: Add check for both offset and index variable

-The offset and index variable may leads to array out of
boundary exception.
-Added offset and index overflow check.

Signed-off-by: Mohammad Johny Shaik <mjshai@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: camera: Add defensive check in ISPIF driver

In case of error handling, call ispif release only if ispif handle
is valid. In case of mm-qcamara-daemon crash when camera is not open,
these handles are not valid. Hence it leads to kernel crash in ispif
release handler.

Change-Id: Ifb402b6907052594d12fcf9495694e6c5184af1b
Signed-off-by: Sreesudhan Ramakrish Ramkumar <srramku@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: camera: Add retry mechanism to detect camera sensor

When device power up, probe happens where camera sensors
connected in each slot are detected by reading its chip id. Add
retry mechanism to try 3 times to read chip id for detecting
camera sensors.

Change-Id: Id2788f32fd7255eb9ca748ddce6e92267a1326ef
Signed-off-by: Wei Ding <weiding@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: camera: Fix file perm

Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: camera_v2: cci: check for NULL pointer

in function "msm_cci_subdev_g_chip_ident"
check for NULL pointer and return error
instead of assert

Change-Id: Ia27751c4d6f3d5ead1749e396ffa5c2773f1582b
Signed-off-by: Georgi Hristov <ghristov@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: camera: Limit print in default case of JPEG

Change JPEG_PR_ERR to pr_err_ratelimited in default
case in JPEG ioctl. JPEG_PR_ERR would keep prinitng
when passing invalid parameters in ioctl which will
cause watchdog reset.

Change-Id: Ia8871fda4f10e44e3d2c1216765e26c2e9823038
CRs-fixed: 588260
Signed-off-by: Yiduo Wang <yiduow@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: camera_v2: Use stream cnt for unique stream id

Add new atomic counter for keeping track of stream counts.
The exisitng open_cnt counter is not full-proff since there could
be multiple streams with the stream id in the folowing
scenario:
a) Create stream 1, 2, and 3
b) Destroy stream 2
c) Add new stream; will result in another stream with id 3.

CRs-fixed: 493632
Change-Id: Icfa3cb2fd2c34c6da7e5f09d016fef4577331264
Signed-off-by: Ankit Premrajka <ankitp@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>