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

Commit e460e50d authored by Manaf Meethalavalappu Pallikunhi's avatar Manaf Meethalavalappu Pallikunhi
Browse files

drivers: thermal: Check NULL pointer before using it in thermal stat update



There is a possible chance that some cooling device stats init fails
and later cooling device update or cooling stats sysfs will try to
access stats data for the same cooling device. It may lead to some
unexpected behaviour.

Add a NULL pointer check before accessing thermal cooling device stats
data.

Change-Id: Ieeb84adf0e5d3575ed06b9c64361bbbf902f984e
Signed-off-by: default avatarManaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
parent 364e8d57
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -898,6 +898,9 @@ void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
{
	struct cooling_dev_stats *stats = cdev->stats;

	if (!stats)
		return;

	spin_lock(&stats->lock);

	if (stats->state == new_state)
@@ -919,6 +922,9 @@ static ssize_t total_trans_show(struct device *dev,
	struct cooling_dev_stats *stats = cdev->stats;
	int ret;

	if (!stats)
		return -ENODEV;

	spin_lock(&stats->lock);
	ret = sprintf(buf, "%u\n", stats->total_trans);
	spin_unlock(&stats->lock);
@@ -935,6 +941,9 @@ time_in_state_ms_show(struct device *dev, struct device_attribute *attr,
	ssize_t len = 0;
	int i;

	if (!stats)
		return -ENODEV;

	spin_lock(&stats->lock);
	update_time_in_state(stats);

@@ -953,8 +962,12 @@ reset_store(struct device *dev, struct device_attribute *attr, const char *buf,
{
	struct thermal_cooling_device *cdev = to_cooling_device(dev);
	struct cooling_dev_stats *stats = cdev->stats;
	int i, states = stats->max_states;
	int i, states;

	if (!stats)
		return -ENODEV;

	states = stats->max_states;
	spin_lock(&stats->lock);

	stats->total_trans = 0;
@@ -978,6 +991,9 @@ static ssize_t trans_table_show(struct device *dev,
	ssize_t len = 0;
	int i, j;

	if (!stats)
		return -ENODEV;

	len += snprintf(buf + len, PAGE_SIZE - len, " From  :    To\n");
	len += snprintf(buf + len, PAGE_SIZE - len, "       : ");
	for (i = 0; i < stats->max_states; i++) {