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

Commit c52e1e3e authored by Venkat Chinta's avatar Venkat Chinta
Browse files

msm: camera: cpas: Add protection for concurrent execution



This change adds mutex lock in register client to protect
client data. It also sets probe done flag to false during
dev remove to force all other functions that might be
invoked in parallel to return without any action.

Change-Id: Iaf4bf65c8a1e0bedf86952817512fcf0f0a71070
Signed-off-by: default avatarVenkat Chinta <vchinta@codeaurora.org>
parent fc3317fb
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -1214,17 +1214,26 @@ static int cam_cpas_hw_register_client(struct cam_hw_info *cpas_hw,

	rc = cam_common_util_get_string_index(soc_private->client_name,
		soc_private->num_clients, client_name, &client_indx);

	mutex_lock(&cpas_core->client_mutex[client_indx]);

	if (rc || !CAM_CPAS_CLIENT_VALID(client_indx) ||
		CAM_CPAS_CLIENT_REGISTERED(cpas_core, client_indx)) {
		CAM_ERR(CAM_CPAS, "Invalid Client register : %s %d, %d",
		CAM_ERR(CAM_CPAS,
			"Inval client %s %d : %d %d %pK %d",
			register_params->identifier,
			register_params->cell_index, client_indx);
			register_params->cell_index,
			CAM_CPAS_CLIENT_VALID(client_indx),
			CAM_CPAS_CLIENT_REGISTERED(cpas_core, client_indx),
			cpas_core->cpas_client[client_indx], rc);
		mutex_unlock(&cpas_core->client_mutex[client_indx]);
		mutex_unlock(&cpas_hw->hw_mutex);
		return -EPERM;
	}

	cpas_client = kzalloc(sizeof(struct cam_cpas_client), GFP_KERNEL);
	if (!cpas_client) {
		mutex_unlock(&cpas_core->client_mutex[client_indx]);
		mutex_unlock(&cpas_hw->hw_mutex);
		return -ENOMEM;
	}
@@ -1237,6 +1246,7 @@ static int cam_cpas_hw_register_client(struct cam_hw_info *cpas_hw,
			client_indx, cpas_client->data.identifier,
			cpas_client->data.cell_index, rc);
		kfree(cpas_client);
		mutex_unlock(&cpas_core->client_mutex[client_indx]);
		mutex_unlock(&cpas_hw->hw_mutex);
		return -EINVAL;
	}
@@ -1248,12 +1258,13 @@ static int cam_cpas_hw_register_client(struct cam_hw_info *cpas_hw,
	cpas_core->cpas_client[client_indx] = cpas_client;
	cpas_core->registered_clients++;

	mutex_unlock(&cpas_hw->hw_mutex);

	CAM_DBG(CAM_CPAS, "client=[%d][%s][%d], registered_clients=%d",
		client_indx, cpas_client->data.identifier,
		cpas_client->data.cell_index, cpas_core->registered_clients);

	mutex_unlock(&cpas_core->client_mutex[client_indx]);
	mutex_unlock(&cpas_hw->hw_mutex);

	return 0;
}

+1 −0
Original line number Diff line number Diff line
@@ -619,6 +619,7 @@ static int cam_cpas_dev_remove(struct platform_device *dev)
	}

	mutex_lock(&g_cpas_intf->intf_lock);
	g_cpas_intf->probe_done = false;
	cam_unregister_subdev(&g_cpas_intf->subdev);
	cam_cpas_hw_remove(g_cpas_intf->hw_intf);
	mutex_unlock(&g_cpas_intf->intf_lock);