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

Commit 014d6e75 authored by Manaf Meethalavalappu Pallikunhi's avatar Manaf Meethalavalappu Pallikunhi Committed by Gerrit - the friendly Code Review server
Browse files

drivers: thermal: Use lock before accessing thermal instance list



The thermal zone config read callback is not holding lock before
accessing thermal instance list. There is a chance that both cooling
device binding and thermal zone config show read are happening
concurrently. The cooling device binding tries to add new thermal
instances and the same time thermal zone config show read context
tries to access thermal instance list. It leads to unexpected
behaviour.

Use lock before accessing thermal instance list in thermal zone
config read callback.

Change-Id: I1bea07cb67a7240027dd34cea2ff61def9258b8f
Signed-off-by: default avatarManaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
parent 9ddceddf
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -107,12 +107,16 @@ config_show(struct device *dev, struct device_attribute *attr, char *buf)
	buf_offset = 0;
	buf1_offset = 0;
	buf2_offset = 0;

	mutex_lock(&tz->lock);
	list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
		if (instance->cdev)
			buf_size++;
	}
	if (!buf_size)
	if (!buf_size) {
		mutex_unlock(&tz->lock);
		goto config_exit;
	}
	buf_size *= THERMAL_NAME_LENGTH;
	buf_cdev =  kzalloc(buf_size, GFP_KERNEL);
	buf_cdev_upper = kzalloc(buf_size, GFP_KERNEL);
@@ -153,6 +157,8 @@ config_show(struct device *dev, struct device_attribute *attr, char *buf)
			}
		}
	}
	mutex_unlock(&tz->lock);

	offset += scnprintf(buf + offset, PAGE_SIZE - offset,
				"device %s\n", buf_cdev);
	offset += scnprintf(buf + offset, PAGE_SIZE - offset,