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

Commit e6c39aef authored by Jack Pham's avatar Jack Pham Committed by Gerrit - the friendly Code Review server
Browse files

usb: pd: Fix unintentional discarding of outgoing VDM



Currently when a VDM message arrives, any pending VDM TX message
queued will be aborted. But this will inadvertently discard an
initiated Discover Identity if an incoming message such as
Attention arrives just before it. Since there is no TX response
to Attention, the engine should have just been able to resume
the Discover ID message. In general, only discard VDM TX messages
when attempting to queue a new outgoing VDM.

Change-Id: Ife42a19b8f909b0550b6bd44ed470e87a922d6e3
Signed-off-by: default avatarJack Pham <jackp@codeaurora.org>
parent 2e7c3098
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -1304,8 +1304,13 @@ int usbpd_send_vdm(struct usbpd *pd, u32 vdm_hdr, const u32 *vdos, int num_vdos)
{
	struct vdm_tx *vdm_tx;

	if (pd->vdm_tx)
		return -EBUSY;
	if (pd->vdm_tx) {
		usbpd_warn(&pd->dev, "Discarding previously queued VDM tx (SVID:0x%04x)\n",
				VDM_HDR_SVID(pd->vdm_tx->data[0]));

		kfree(pd->vdm_tx);
		pd->vdm_tx = NULL;
	}

	vdm_tx = kzalloc(sizeof(*vdm_tx), GFP_KERNEL);
	if (!vdm_tx)
@@ -1523,17 +1528,13 @@ static void handle_vdm_rx(struct usbpd *pd, struct rx_msg *rx_msg)
		return;
	}

	/* if this interrupts a previous exchange, abort queued response */
	if (cmd_type == SVDM_CMD_TYPE_INITIATOR && pd->vdm_tx) {
		usbpd_dbg(&pd->dev, "Discarding previously queued SVDM tx (SVID:0x%04x)\n",
				VDM_HDR_SVID(pd->vdm_tx->data[0]));

		kfree(pd->vdm_tx);
		pd->vdm_tx = NULL;
	}

	if (handler && handler->svdm_received) {
		handler->svdm_received(handler, cmd, cmd_type, vdos, num_vdos);

		/* handle any previously queued TX */
		if (pd->vdm_tx && !pd->sm_queued)
			kick_sm(pd, 0);

		return;
	}