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

Commit 441cc5ee authored by Skylar Chang's avatar Skylar Chang
Browse files

msm: ipa3: add lock for num_q6_rule



There is a race condition be observed
on global variable num_q6_rule used in
ipa wan-driver. The fix is to add lock
to prevent different threads are accessing
it at the same time.

Change-Id: Ia9190c60361cb5605b61963309beca3acdeac89d
Signed-off-by: default avatarSkylar Chang <chiaweic@codeaurora.org>
parent d14a930f
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -411,12 +411,15 @@ int copy_ul_filter_rule_to_ipa(struct ipa_install_fltr_rule_req_msg_v01
{
	int i, j;

	/* prevent multi-threads accessing num_q6_rule */
	mutex_lock(&add_mux_channel_lock);
	if (rule_req->filter_spec_list_valid == true) {
		num_q6_rule = rule_req->filter_spec_list_len;
		IPAWANDBG("Received (%d) install_flt_req\n", num_q6_rule);
	} else {
		num_q6_rule = 0;
		IPAWANERR("got no UL rules from modem\n");
		mutex_unlock(&add_mux_channel_lock);
		return -EINVAL;
	}

@@ -610,9 +613,11 @@ int copy_ul_filter_rule_to_ipa(struct ipa_install_fltr_rule_req_msg_v01
	num_q6_rule = 0;
	memset(ipa_qmi_ctx->q6_ul_filter_rule, 0,
		sizeof(ipa_qmi_ctx->q6_ul_filter_rule));
	mutex_unlock(&add_mux_channel_lock);
	return -EINVAL;

success:
	mutex_unlock(&add_mux_channel_lock);
	return 0;
}

@@ -1621,9 +1626,12 @@ static int ipa_wwan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
				/* already got Q6 UL filter rules*/
				if (ipa_qmi_ctx &&
					ipa_qmi_ctx->modem_cfg_emb_pipe_flt
					== false)
					== false) {
					/* protect num_q6_rule */
					mutex_lock(&add_mux_channel_lock);
					rc = wwan_add_ul_flt_rule_to_ipa();
				else
					mutex_unlock(&add_mux_channel_lock);
				} else
					rc = 0;
				egress_set = true;
				if (rc)
+14 −1
Original line number Diff line number Diff line
@@ -423,6 +423,8 @@ int ipa3_copy_ul_filter_rule_to_ipa(struct ipa_install_fltr_rule_req_msg_v01
{
	int i, j;

	/* prevent multi-threads accessing rmnet_ipa3_ctx->num_q6_rules */
	mutex_lock(&rmnet_ipa3_ctx->add_mux_channel_lock);
	if (rule_req->filter_spec_ex_list_valid == true) {
		rmnet_ipa3_ctx->num_q6_rules =
			rule_req->filter_spec_ex_list_len;
@@ -431,6 +433,8 @@ int ipa3_copy_ul_filter_rule_to_ipa(struct ipa_install_fltr_rule_req_msg_v01
	} else {
		rmnet_ipa3_ctx->num_q6_rules = 0;
		IPAWANERR("got no UL rules from modem\n");
		mutex_unlock(&rmnet_ipa3_ctx->
					add_mux_channel_lock);
		return -EINVAL;
	}

@@ -633,9 +637,13 @@ int ipa3_copy_ul_filter_rule_to_ipa(struct ipa_install_fltr_rule_req_msg_v01
	rmnet_ipa3_ctx->num_q6_rules = 0;
	memset(ipa3_qmi_ctx->q6_ul_filter_rule, 0,
		sizeof(ipa3_qmi_ctx->q6_ul_filter_rule));
	mutex_unlock(&rmnet_ipa3_ctx->
		add_mux_channel_lock);
	return -EINVAL;

success:
	mutex_unlock(&rmnet_ipa3_ctx->
		add_mux_channel_lock);
	return 0;
}

@@ -1429,8 +1437,13 @@ static int handle3_egress_format(struct net_device *dev,

	if (rmnet_ipa3_ctx->num_q6_rules != 0) {
		/* already got Q6 UL filter rules*/
		if (ipa3_qmi_ctx->modem_cfg_emb_pipe_flt == false)
		if (ipa3_qmi_ctx->modem_cfg_emb_pipe_flt == false) {
			/* prevent multi-threads accessing num_q6_rules */
			mutex_lock(&rmnet_ipa3_ctx->add_mux_channel_lock);
			rc = ipa3_wwan_add_ul_flt_rule_to_ipa();
			mutex_unlock(&rmnet_ipa3_ctx->
				add_mux_channel_lock);
		}
		if (rc)
			IPAWANERR("install UL rules failed\n");
		else