i2c: qup: fix buffer overflow for multiple msg of maximum xfer len
authorAbhishek Sahu <absahu@codeaurora.org>
Mon, 12 Mar 2018 13:14:59 +0000 (18:44 +0530)
committerWolfram Sang <wsa@the-dreams.de>
Sat, 24 Mar 2018 12:20:30 +0000 (13:20 +0100)
commit6f2f0f6465acbd59391c43352ff0df77df1f01db
tree41df7b2cc692e1da09ef8caab2f5e0c800e76c81
parentecb6e1e5f4352055a5761b945a833a925d51bf8d
i2c: qup: fix buffer overflow for multiple msg of maximum xfer len

The BAM mode requires buffer for start tag data and tx, rx SG
list. Currently, this is being taken for maximum transfer length
(65K). But an I2C transfer can have multiple messages and each
message can be of this maximum length so the buffer overflow will
happen in this case. Since increasing buffer length won’t be
feasible since an I2C transfer can contain any number of messages
so this patch does following changes to make i2c transfers working
for multiple messages case.

1. Calculate the required buffers for 2 maximum length messages
   (65K * 2).
2. Split the descriptor formation and descriptor scheduling.
   The idea is to fit as many messages in one DMA transfers for 65K
   threshold value (max_xfer_sg_len). Whenever the sg_cnt is
   crossing this, then schedule the BAM transfer and subsequent
   transfer will again start from zero.

Signed-off-by: Abhishek Sahu <absahu@codeaurora.org>
Reviewed-by: Andy Gross <andy.gross@linaro.org>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/i2c/busses/i2c-qup.c