static ssize_t timer_store()

in devfreq.c [1821:1870]


static ssize_t timer_store(struct device *dev, struct device_attribute *attr,
			      const char *buf, size_t count)
{
	struct devfreq *df = to_devfreq(dev);
	char str_timer[DEVFREQ_NAME_LEN + 1];
	int timer = -1;
	int ret = 0, i;

	if (!df->governor || !df->profile)
		return -EINVAL;

	ret = sscanf(buf, "%16s", str_timer);
	if (ret != 1)
		return -EINVAL;

	for (i = 0; i < DEVFREQ_TIMER_NUM; i++) {
		if (!strncmp(timer_name[i], str_timer, DEVFREQ_NAME_LEN)) {
			timer = i;
			break;
		}
	}

	if (timer < 0) {
		ret = -EINVAL;
		goto out;
	}

	if (df->profile->timer == timer) {
		ret = 0;
		goto out;
	}

	mutex_lock(&df->lock);
	df->profile->timer = timer;
	mutex_unlock(&df->lock);

	ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
	if (ret) {
		dev_warn(dev, "%s: Governor %s not stopped(%d)\n",
			 __func__, df->governor->name, ret);
		goto out;
	}

	ret = df->governor->event_handler(df, DEVFREQ_GOV_START, NULL);
	if (ret)
		dev_warn(dev, "%s: Governor %s not started(%d)\n",
			 __func__, df->governor->name, ret);
out:
	return ret ? ret : count;
}