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

Commit 34faa9f1 authored by Ajay Agarwal's avatar Ajay Agarwal
Browse files

usb: gadget: f_ipc: Re-initialize completion on every read/write



When the driver is waiting for the completion of a queued
read/write request and some system interrupt is triggered, then
the request is dequeued and the core gadget driver calls the
request completion handler as a part of dequeue which increments
the completion's 'done' count to 1.
Next, when a new request is queued, its completion is immediately
done because the wait_for_completion bails out if 'done' count is
non-zero while the request is still queued with the hardware. So
the transfer fails with EALREADY error.
Fix this by re-initializing the completion before new read/write
request is queued. This assigns 0 value to 'done' field of the
completion and normal functionality resumes.

Change-Id: If51a1e4784c69377d296127356b17f8fbf0bc81e
Signed-off-by: default avatarAjay Agarwal <ajaya@codeaurora.org>
parent 5cd2a161
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
/*
 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -265,6 +265,8 @@ static int ipc_write(struct platform_device *pdev, char *buf,
		return -EINVAL;
	}

	reinit_completion(&ipc_dev->write_done);

	if (usb_ep_queue(in, req, GFP_KERNEL)) {
		wait_event_interruptible(ipc_dev->state_wq, ipc_dev->online ||
				ipc_dev->current_state == IPC_DISCONNECTED);
@@ -332,6 +334,8 @@ static int ipc_read(struct platform_device *pdev, char *buf, unsigned int count)
		return -EINVAL;
	}

	reinit_completion(&ipc_dev->read_done);

	if (usb_ep_queue(out, req, GFP_KERNEL)) {
		wait_event_interruptible(ipc_dev->state_wq, ipc_dev->online ||
				ipc_dev->current_state == IPC_DISCONNECTED);