usb: gadget: rndis: free response queue during REMOTE_NDIS_RESET_MSG

This change “usb: gadget: rndis: free response queue during REMOTE_NDIS_RESET_MSG” (commit 207707d) in Linux kernel is authored by Xerox Lin <xerox_lin [at] htc.com> on Wed Jun 29 14:34:21 2016 +0530.

Description of "usb: gadget: rndis: free response queue during REMOTE_NDIS_RESET_MSG"

The change “usb: gadget: rndis: free response queue during REMOTE_NDIS_RESET_MSG” introduces changes as follows.

usb: gadget: rndis: free response queue during REMOTE_NDIS_RESET_MSG

When rndis data transfer is in progress, some Windows7 Host PC is not
sending the GET_ENCAPSULATED_RESPONSE command for receiving the response
for the previous SEND_ENCAPSULATED_COMMAND processed.

The rndis function driver appends each response for the
SEND_ENCAPSULATED_COMMAND in a queue. As the above process got corrupted,
the Host sends a REMOTE_NDIS_RESET_MSG command to do a soft-reset.
As the rndis response queue is not freed, the previous response is sent
as a part of this REMOTE_NDIS_RESET_MSG's reset response and the Host
block any more Rndis transfers.

Hence free the rndis response queue as a part of this soft-reset so that
the correct response for REMOTE_NDIS_RESET_MSG is sent properly during the
response command.

Signed-off-by: Rajkumar Raghupathy <raghup@codeaurora.org>
Signed-off-by: Xerox Lin <xerox_lin@htc.com>
[AmitP: Cherry-picked this patch and folded other relevant
        fixes from Android common kernel android-4.4]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>

Linux kernel releases containing commit 207707d

The Linux kernel releases containing this commit are as follows.

Linux kernel code changes from "usb: gadget: rndis: free response queue during REMOTE_NDIS_RESET_MSG"

There are 6 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/usb/gadget/function/rndis.c | 6 ++++++
 1 file changed, 6 insertions(+)
 
diff --git a/drivers/usb/gadget/function/rndis.c b/drivers/usb/gadget/function/rndis.c
index 943c21aafd3b..ab6ac1b74ac0 100644
--- a/drivers/usb/gadget/function/rndis.c
+++ b/drivers/usb/gadget/function/rndis.c
@@ -680,6 +680,12 @@ static int rndis_reset_response(struct rndis_params *params,
 {
 	rndis_reset_cmplt_type *resp;
 	rndis_resp_t *r;
+	u8 *xbuf;
+	u32 length;
+
+	/* drain the response queue */
+	while ((xbuf = rndis_get_next_response(params, &length)))
+		rndis_free_response(params, xbuf);
 
 	r = rndis_add_response(params, sizeof(rndis_reset_cmplt_type));
 	if (!r)

The commit for this change in Linux stable tree is 207707d (patch).

Last modified: 2020/02/09