Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0698e522 authored by Sriharsha Allenki's avatar Sriharsha Allenki Committed by Gerrit - the friendly Code Review server
Browse files

usb: gadget: f_gps: Fix multiple notifications for single response



When there are multiple responses pending with
the driver, the notify count is greater than 1.
In this case host may acknowledge multiple notifications
but is still fetching only one response. This breaks
the sync between the notify count and number of
responses and results in data loss.
Fix this by notifying the host of a available response
only on the completion handler of previous
get response.

CRs-Fixed: 2098360
Change-Id: Ica48682246ecaacc4cdc1f45edf60ad954636663
Signed-off-by: default avatarSriharsha Allenki <sallenki@codeaurora.org>
parent 1995d3a6
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -649,14 +649,24 @@ static void gps_notify_complete(struct usb_ep *ep, struct usb_request *req)

		pr_debug("%s: decrement notify_count:%u\n", __func__,
				atomic_read(&dev->notify_count));
		if (atomic_dec_and_test(&dev->notify_count))
			break;
		atomic_dec(&dev->notify_count);

		gps_queue_notify_request(dev);
		break;
	}
}

static void gps_ctrl_send_response_complete(struct usb_ep *ep,
		struct usb_request *req)
{
	struct f_gps *dev = (struct f_gps *)req->context;

	pr_debug("%s: response queue count:%u notify count: %u\n", __func__,
			atomic_read(&dev->resp_q_count),
			atomic_read(&dev->notify_count));
	if (atomic_read(&dev->notify_count) > 0)
		gps_queue_notify_request(dev);
}

static int
gps_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
{
@@ -709,6 +719,8 @@ gps_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
			memcpy(req->buf, cpkt->buf, len);
			ret = len;

			req->complete = gps_ctrl_send_response_complete;
			req->context = dev;
			gps_free_ctrl_pkt(cpkt);
		}
		break;