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

Commit e51c6cff authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "usb: pd: Prevent race between handle_vdm_tx & reset_vdm_state"

parents 9810c3af 79f771f9
Loading
Loading
Loading
Loading
+8 −2
Original line number Original line Diff line number Diff line
@@ -1649,8 +1649,11 @@ static void handle_vdm_tx(struct usbpd *pd, enum pd_sop_type sop_type)
	u32 vdm_hdr;
	u32 vdm_hdr;
	int ret;
	int ret;


	if (!pd->vdm_tx)
	mutex_lock(&pd->svid_handler_lock);
	if (!pd->vdm_tx) {
		mutex_unlock(&pd->svid_handler_lock);
		return;
		return;
	}


	/* only send one VDM at a time */
	/* only send one VDM at a time */
	vdm_hdr = pd->vdm_tx->data[0];
	vdm_hdr = pd->vdm_tx->data[0];
@@ -1664,6 +1667,7 @@ static void handle_vdm_tx(struct usbpd *pd, enum pd_sop_type sop_type)
		pd->current_pr == PR_SRC && !in_src_ams(pd)) {
		pd->current_pr == PR_SRC && !in_src_ams(pd)) {
		/* Set SinkTxNG and reschedule sm_work to send again */
		/* Set SinkTxNG and reschedule sm_work to send again */
		start_src_ams(pd, true);
		start_src_ams(pd, true);
		mutex_unlock(&pd->svid_handler_lock);
		return;
		return;
	}
	}


@@ -1673,6 +1677,7 @@ static void handle_vdm_tx(struct usbpd *pd, enum pd_sop_type sop_type)
		usbpd_err(&pd->dev, "Error (%d) sending VDM command %d\n",
		usbpd_err(&pd->dev, "Error (%d) sending VDM command %d\n",
				ret, SVDM_HDR_CMD(pd->vdm_tx->data[0]));
				ret, SVDM_HDR_CMD(pd->vdm_tx->data[0]));


		mutex_unlock(&pd->svid_handler_lock);
		/* retry when hitting PE_SRC/SNK_Ready again */
		/* retry when hitting PE_SRC/SNK_Ready again */
		if (ret != -EBUSY && sop_type == SOP_MSG)
		if (ret != -EBUSY && sop_type == SOP_MSG)
			usbpd_set_state(pd, PE_SEND_SOFT_RESET);
			usbpd_set_state(pd, PE_SEND_SOFT_RESET);
@@ -1705,6 +1710,7 @@ static void handle_vdm_tx(struct usbpd *pd, enum pd_sop_type sop_type)
	}
	}


	pd->vdm_tx = NULL;
	pd->vdm_tx = NULL;
	mutex_unlock(&pd->svid_handler_lock);
}
}


static void reset_vdm_state(struct usbpd *pd)
static void reset_vdm_state(struct usbpd *pd)
@@ -1721,7 +1727,6 @@ static void reset_vdm_state(struct usbpd *pd)
		}
		}
	}
	}


	mutex_unlock(&pd->svid_handler_lock);
	pd->vdm_state = VDM_NONE;
	pd->vdm_state = VDM_NONE;
	kfree(pd->vdm_tx_retry);
	kfree(pd->vdm_tx_retry);
	pd->vdm_tx_retry = NULL;
	pd->vdm_tx_retry = NULL;
@@ -1732,6 +1737,7 @@ static void reset_vdm_state(struct usbpd *pd)
	pd->vdm_tx = NULL;
	pd->vdm_tx = NULL;
	pd->ss_lane_svid = 0x0;
	pd->ss_lane_svid = 0x0;
	pd->vdm_in_suspend = false;
	pd->vdm_in_suspend = false;
	mutex_unlock(&pd->svid_handler_lock);
}
}


static void handle_get_src_cap_extended(struct usbpd *pd)
static void handle_get_src_cap_extended(struct usbpd *pd)