OSDN Git Service

soc: qcom: qmi: fix a buffer sizing bug
authorAlex Elder <elder@linaro.org>
Fri, 27 Apr 2018 14:08:17 +0000 (09:08 -0500)
committerAndy Gross <andy.gross@linaro.org>
Fri, 25 May 2018 20:53:58 +0000 (15:53 -0500)
commit7df5ff258bd27900d516fea88da10d05602bf8c7
tree003dca0855f32fc21e4c7e059a910807e8fc089e
parent488de0317bc50b0271de7baa03ecc91c3901d8ed
soc: qcom: qmi: fix a buffer sizing bug

In qmi_handle_init(), a buffer is allocated for to hold messages
received through the handle's socket.  Any "normal" messages
(expected by the caller) will have a header prepended, so the
buffer size is adjusted to accomodate that.

The buffer must also be of sufficient size to receive control
messages, so the size is increased if necessary to ensure these
will fit.

Unfortunately the calculation is done wrong, making it possible
for the calculated buffer size to be too small to hold a "normal"
message.  Specifically, if:

  recv_buf_size > sizeof(struct qrtr_ctrl_pkt) - sizeof(struct qmi_header)
AND
  recv_buf_size < sizeof(struct qrtr_ctrl_pkt)

the current logic will use sizeof(struct qrtr_ctrl_pkt) as the
receive buffer size, which is not enough to hold the maximum
"normal" message plus its header.  Currently this problem occurs
for (13 < recv_buf_size < 20).

This patch corrects this.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Andy Gross <andy.gross@linaro.org>
drivers/soc/qcom/qmi_interface.c