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

Commit d6a49f7b authored by Deepak Kumar's avatar Deepak Kumar Committed by Gerrit - the friendly Code Review server
Browse files

msm: kgsl: Avoid racing against context delete while releasing contexts



While releasing contexts take a reference to context inside read rcu
lock to avoid racing against context deletion. This will avoid using
dangling context pointer in device_release_contexts.

Change-Id: I76e787f6dde5a324fec23e81829174bd28134c6c
Signed-off-by: default avatarDeepak Kumar <dkumar@codeaurora.org>
parent 53d1dd96
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -1072,25 +1072,28 @@ static void device_release_contexts(struct kgsl_device_private *dev_priv)
	struct kgsl_device *device = dev_priv->device;
	struct kgsl_context *context;
	int next = 0;
	int result = 0;

	while (1) {
		read_lock(&device->context_lock);
		context = idr_get_next(&device->context_idr, &next);
		read_unlock(&device->context_lock);

		if (context == NULL)
		if (context == NULL) {
			read_unlock(&device->context_lock);
			break;

		if (context->dev_priv == dev_priv) {
		} else if (context->dev_priv == dev_priv) {
			/*
			 * Hold a reference to the context in case somebody
			 * tries to put it while we are detaching
			 */
			result = _kgsl_context_get(context);
		}
		read_unlock(&device->context_lock);

			if (_kgsl_context_get(context)) {
		if (result) {
			kgsl_context_detach(context);
			kgsl_context_put(context);
			}
			result = 0;
		}

		next = next + 1;