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

Commit 568c58cf authored by Lina Iyer's avatar Lina Iyer
Browse files

drivers: lpm: cleanup error handling



Clean up error handling in power drivers. Also use the recommended
variants of kzalloc, snprintf etc. Remove unwanted debug prints and warn
and refactor redundant code as functions.

Change-Id: If41d285e45a81cab9bd3458f2131dcacd2950492
Signed-off-by: default avatarLina Iyer <ilina@codeaurora.org>
parent 712e7c39
Loading
Loading
Loading
Loading
+120 −144
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ enum lpm_type {
	IDLE = 0,
	SUSPEND,
	LATENCY,
	LPM_TYPE_NR
	LPM_TYPE_NR,
};

struct lpm_type_str {
@@ -38,6 +38,18 @@ static const struct lpm_type_str lpm_types[] = {
static struct lpm_level_avail *cpu_level_available[NR_CPUS];
static struct platform_device *lpm_pdev;

static int lpm_of_read_u32(struct device_node *dn, const char *key,
					u32 *val, bool is_err)
{
	int ret;

	ret = of_property_read_u32(dn, key, val);
	if (is_err && ret)
		pr_err("%s:failed to read key:%s ret:%d\n", dn->name, key, ret);

	return ret;
}

static void *get_enabled_ptr(struct kobj_attribute *attr,
					struct lpm_level_avail *avail)
{
@@ -143,15 +155,15 @@ static int create_lvl_avail_nodes(const char *name,
	if (!kobj)
		return -ENOMEM;

	attr_group = devm_kzalloc(&lpm_pdev->dev, sizeof(*attr_group),
	attr_group = devm_kcalloc(&lpm_pdev->dev, 1, sizeof(*attr_group),
				  GFP_KERNEL);
	if (!attr_group) {
		ret = -ENOMEM;
		goto failed;
	}

	attr = devm_kzalloc(&lpm_pdev->dev,
		sizeof(*attr) * (LPM_TYPE_NR + 1), GFP_KERNEL);
	attr = devm_kcalloc(&lpm_pdev->dev, LPM_TYPE_NR + 1, sizeof(*attr),
			    GFP_KERNEL);
	if (!attr) {
		ret = -ENOMEM;
		goto failed;
@@ -182,10 +194,8 @@ static int create_lvl_avail_nodes(const char *name,
	attr_group->attrs = attr;

	ret = sysfs_create_group(kobj, attr_group);
	if (ret) {
		ret = -ENOMEM;
	if (ret)
		goto failed;
	}

	avail->idle_enabled = true;
	avail->suspend_enabled = true;
@@ -194,7 +204,7 @@ static int create_lvl_avail_nodes(const char *name,
	avail->idx = index;
	avail->cpu_node = cpu_node;

	return ret;
	return 0;

failed:
	kobject_put(kobj);
@@ -211,8 +221,8 @@ static int create_cpu_lvl_nodes(struct lpm_cluster *p, struct kobject *parent)
	int ret = 0;
	struct list_head *pos;

	cpu_kobj = devm_kzalloc(&lpm_pdev->dev, sizeof(*cpu_kobj) *
			cpumask_weight(&p->child_cpus), GFP_KERNEL);
	cpu_kobj = devm_kcalloc(&lpm_pdev->dev, cpumask_weight(&p->child_cpus),
				sizeof(*cpu_kobj), GFP_KERNEL);
	if (!cpu_kobj)
		return -ENOMEM;

@@ -229,8 +239,9 @@ static int create_cpu_lvl_nodes(struct lpm_cluster *p, struct kobject *parent)
				goto release_kobj;
			}

			level_list = devm_kzalloc(&lpm_pdev->dev,
					lpm_cpu->nlevels * sizeof(*level_list),
			level_list = devm_kcalloc(&lpm_pdev->dev,
						  lpm_cpu->nlevels,
						  sizeof(*level_list),
						  GFP_KERNEL);
			if (!level_list) {
				ret = -ENOMEM;
@@ -297,11 +308,8 @@ int create_cluster_lvl_nodes(struct lpm_cluster *p, struct kobject *kobj)
			return ret;
	}

	if (!list_empty(&p->cpu)) {
	if (!list_empty(&p->cpu))
		ret = create_cpu_lvl_nodes(p, cluster_kobj);
		if (ret)
			return ret;
	}

	return ret;
}
@@ -333,148 +341,124 @@ bool lpm_cluster_mode_allow(struct lpm_cluster *cluster,
				avail->suspend_enabled);
}

static int parse_cluster_params(struct device_node *node,
		struct lpm_cluster *c)
static int parse_cluster_params(struct device_node *dn, struct lpm_cluster *c)
{
	char *key;
	int ret;

	key = "label";
	ret = of_property_read_string(node, key, &c->cluster_name);
	if (ret)
		goto fail;
	ret = of_property_read_string(dn, "label", &c->cluster_name);
	if (ret) {
		pr_err("Failed to read label ret: %d\n", ret);
		return ret;
	}

	key = "qcom,psci-mode-shift";
	ret = of_property_read_u32(node, key, &c->psci_mode_shift);
	ret = lpm_of_read_u32(dn, "qcom,psci-mode-shift",
			      &c->psci_mode_shift, true);
	if (ret)
		goto fail;
		return ret;

	key = "qcom,psci-mode-mask";
	ret = of_property_read_u32(node, key, &c->psci_mode_mask);
	ret = lpm_of_read_u32(dn, "qcom,psci-mode-mask",
			      &c->psci_mode_mask, true);
	if (ret)
		goto fail;
		return ret;

	key = "qcom,disable-prediction";
	c->lpm_prediction = !(of_property_read_bool(node, key));
	c->lpm_prediction = !(of_property_read_bool(dn,
						    "qcom,disable-prediction"));

	if (c->lpm_prediction) {
		key = "qcom,clstr-tmr-add";
		ret = of_property_read_u32(node, key, &c->tmr_add);
		ret = lpm_of_read_u32(dn, "qcom,clstr-tmr-add", &c->tmr_add,
				      false);
		if (ret || c->tmr_add < TIMER_ADD_LOW ||
					c->tmr_add > TIMER_ADD_HIGH)
					c->tmr_add > TIMER_ADD_HIGH) {
			c->tmr_add = DEFAULT_TIMER_ADD;
			ret = 0;
		}
	}

	/* Set default_level to 0 as default */
	c->default_level = 0;

	return 0;
fail:
	pr_err("Failed to read key: %s ret: %d\n", key, ret);

	return ret;
}

static int parse_power_params(struct device_node *node,
		struct power_params *pwr)
static int parse_power_params(struct device_node *dn, struct power_params *pwr)
{
	char *key;
	int ret;

	key = "qcom,entry-latency-us";
	ret  = of_property_read_u32(node, key, &pwr->entry_latency);
	if (ret)
		goto fail;

	key = "qcom,exit-latency-us";
	ret  = of_property_read_u32(node, key, &pwr->exit_latency);
	ret  = lpm_of_read_u32(dn, "qcom,entry-latency-us",
			       &pwr->entry_latency, true);
	if (ret)
		goto fail;
		return ret;

	key = "qcom,min-residency-us";
	ret = of_property_read_u32(node, key, &pwr->min_residency);
	ret  = lpm_of_read_u32(dn, "qcom,exit-latency-us",
			       &pwr->exit_latency, true);
	if (ret)
		goto fail;

		return ret;
fail:
	pr_err("Failed to read key: %s node: %s\n", key, node->name);

	ret = lpm_of_read_u32(dn, "qcom,min-residency-us",
			      &pwr->min_residency, true);

	return ret;
}

static int parse_cluster_level(struct device_node *node,
static int parse_cluster_level(struct device_node *dn,
			       struct lpm_cluster *cluster)
{
	struct lpm_cluster_level *level = &cluster->levels[cluster->nlevels];
	int ret = -ENOMEM;
	char *key;

	key = "label";
	ret = of_property_read_string(node, key, &level->level_name);
	if (ret)
		goto failed;
	ret = of_property_read_string(dn, "label", &level->level_name);
	if (ret) {
		pr_err("Failed to read label ret: %d\n", ret);
		return ret;
	}

	key = "qcom,psci-mode";
	ret = of_property_read_u32(node, key, &level->psci_id);
	ret = lpm_of_read_u32(dn, "qcom,psci-mode", &level->psci_id, true);
	if (ret)
		goto failed;
		return ret;

	level->is_reset = of_property_read_bool(node, "qcom,is-reset");
	level->is_reset = of_property_read_bool(dn, "qcom,is-reset");

	if (cluster->nlevels != cluster->default_level) {
		key = "qcom,min-child-idx";
		ret = of_property_read_u32(node, key, &level->min_child_level);
		ret = lpm_of_read_u32(dn, "qcom,min-child-idx",
				      &level->min_child_level, true);
		if (ret)
			goto failed;
			return ret;

		if (cluster->min_child_level > level->min_child_level)
			cluster->min_child_level = level->min_child_level;
	}

	level->notify_rpm = of_property_read_bool(node, "qcom,notify-rpm");
	level->notify_rpm = of_property_read_bool(dn, "qcom,notify-rpm");

	key = "parse_power_params";
	ret = parse_power_params(node, &level->pwr);
	if (ret)
		goto failed;
	ret = parse_power_params(dn, &level->pwr);
	if (ret) {
		pr_err("Failed to parse power params ret:%d\n", ret);
		return ret;
	}

	key = "qcom,reset-level";
	ret = of_property_read_u32(node, key, &level->reset_level);
	ret = lpm_of_read_u32(dn, "qcom,reset-level",
			      &level->reset_level, false);
	if (ret == -EINVAL)
		level->reset_level = LPM_RESET_LVL_NONE;
	else if (ret)
		goto failed;
		return ret;

	cluster->nlevels++;

	return 0;
failed:
	pr_err("Failed to read key: %s ret: %d\n", key, ret);

	return ret;
}

static int parse_cpu_mode(struct device_node *n, struct lpm_cpu_level *l)
{
	char *key;
	int ret;

	key = "label";
	ret = of_property_read_string(n, key, &l->name);
	if (ret)
		goto fail;

	key = "qcom,psci-cpu-mode";
	ret = of_property_read_u32(n, key, &l->psci_id);
	if (ret)
		goto fail;

	ret = of_property_read_string(n, "label", &l->name);
	if (ret) {
		pr_err("Failed to read label level: %s\n", l->name);
		return ret;
fail:
	pr_err("Failed to read key: %s level: %s\n", key, l->name);
	}

	return ret;
	return lpm_of_read_u32(n, "qcom,psci-cpu-mode", &l->psci_id, true);
}

static int get_cpumask_for_node(struct device_node *node, struct cpumask *mask)
@@ -515,7 +499,6 @@ static int parse_cpu(struct device_node *node, struct lpm_cpu *cpu)

	struct device_node *n;
	int ret, i;
	const char *key;

	for_each_child_of_node(node, n) {
		struct lpm_cpu_level *l = &cpu->levels[cpu->nlevels];
@@ -534,14 +517,13 @@ static int parse_cpu(struct device_node *node, struct lpm_cpu *cpu)
			return ret;
		}

		key = "qcom,use-broadcast-timer";
		l->use_bc_timer = of_property_read_bool(n, key);
		l->use_bc_timer = of_property_read_bool(n,
					"qcom,use-broadcast-timer");

		key = "qcom,is-reset";
		l->is_reset = of_property_read_bool(n, key);
		l->is_reset = of_property_read_bool(n, "qcom,is-reset");

		key = "qcom,reset-level";
		ret = of_property_read_u32(n, key, &l->reset_level);
		ret = lpm_of_read_u32(n, "qcom,reset-level", &l->reset_level,
								false);
		of_node_put(n);

		if (ret == -EINVAL)
@@ -559,67 +541,63 @@ static int parse_cpu(struct device_node *node, struct lpm_cpu *cpu)
	return 0;
}

static int parse_cpu_levels(struct device_node *node, struct lpm_cluster *c)
static int parse_cpu_levels(struct device_node *dn, struct lpm_cluster *c)
{
	int ret;
	char *key;
	struct lpm_cpu *cpu;

	cpu = devm_kzalloc(&lpm_pdev->dev, sizeof(*cpu), GFP_KERNEL);
	cpu = devm_kcalloc(&lpm_pdev->dev, 1, sizeof(*cpu), GFP_KERNEL);
	if (!cpu)
		return -ENOMEM;

	if (get_cpumask_for_node(node, &cpu->related_cpus))
	if (get_cpumask_for_node(dn, &cpu->related_cpus))
		return -EINVAL;

	cpu->parent = c;

	key = "qcom,psci-mode-shift";
	ret = of_property_read_u32(node, key, &cpu->psci_mode_shift);
	ret = lpm_of_read_u32(dn, "qcom,psci-mode-shift",
			      &cpu->psci_mode_shift, true);
	if (ret)
		goto failed;
		return ret;

	key = "qcom,psci-mode-mask";
	ret = of_property_read_u32(node, key, &cpu->psci_mode_mask);
	ret = lpm_of_read_u32(dn, "qcom,psci-mode-mask",
			      &cpu->psci_mode_mask, true);
	if (ret)
		goto failed;
		return ret;

	key = "qcom,disable-prediction";
	cpu->lpm_prediction = !(of_property_read_bool(node, key));
	cpu->lpm_prediction = !(of_property_read_bool(dn,
					"qcom,disable-prediction"));

	if (cpu->lpm_prediction) {
		key = "qcom,ref-stddev";
		ret = of_property_read_u32(node, key, &cpu->ref_stddev);
		ret = lpm_of_read_u32(dn, "qcom,ref-stddev",
				      &cpu->ref_stddev, false);
		if (ret || cpu->ref_stddev < STDDEV_LOW ||
					cpu->ref_stddev > STDDEV_HIGH)
			cpu->ref_stddev = DEFAULT_STDDEV;

		key = "qcom,tmr-add";
		ret = of_property_read_u32(node, key, &cpu->tmr_add);
		ret = lpm_of_read_u32(dn, "qcom,tmr-add",
				      &cpu->tmr_add, false);
		if (ret || cpu->tmr_add < TIMER_ADD_LOW ||
					cpu->tmr_add > TIMER_ADD_HIGH)
			cpu->tmr_add = DEFAULT_TIMER_ADD;

		key = "qcom,ref-premature-cnt";
		ret = of_property_read_u32(node, key, &cpu->ref_premature_cnt);
		ret = lpm_of_read_u32(dn, "qcom,ref-premature-cnt",
				      &cpu->ref_premature_cnt, false);
		if (ret || cpu->ref_premature_cnt < PREMATURE_CNT_LOW ||
				cpu->ref_premature_cnt > PREMATURE_CNT_HIGH)
			cpu->ref_premature_cnt = DEFAULT_PREMATURE_CNT;
	}

	key = "parse_cpu";
	ret = parse_cpu(node, cpu);
	if (ret)
		goto failed;
	ret = parse_cpu(dn, cpu);
	if (ret) {
		pr_err("Failed to parse cpu %s\n", dn->name);
		return ret;
	}

	cpumask_or(&c->child_cpus, &c->child_cpus, &cpu->related_cpus);
	list_add(&cpu->list, &c->cpu);

	return ret;

failed:
	pr_err("Failed to read key: %s node: %s\n", key, node->name);
	return ret;
}

void free_cluster_node(struct lpm_cluster *cluster)
@@ -647,10 +625,9 @@ struct lpm_cluster *parse_cluster(struct device_node *node,
{
	struct lpm_cluster *c;
	struct device_node *n;
	char *key;
	int ret = 0, i;

	c = devm_kzalloc(&lpm_pdev->dev, sizeof(*c), GFP_KERNEL);
	c = devm_kcalloc(&lpm_pdev->dev, 1, sizeof(*c), GFP_KERNEL);
	if (!c)
		return ERR_PTR(-ENOMEM);

@@ -671,25 +648,28 @@ struct lpm_cluster *parse_cluster(struct device_node *node,
		}

		if (!of_node_cmp(n->name, "qcom,pm-cluster-level")) {
			key = "qcom,pm-cluster-level";
			if (parse_cluster_level(n, c))
			if (parse_cluster_level(n, c)) {
				pr_err("Failed parse pm-cluster-level\n");
				goto failed_parse_cluster;
			}
		} else if (!of_node_cmp(n->name, "qcom,pm-cluster")) {
			struct lpm_cluster *child;

			key = "qcom,pm-cluster";
			child = parse_cluster(n, c);
			if (!child)
			if (!child) {
				pr_err("Failed parse pm-cluster\n");
				goto failed_parse_cluster;
			}

			list_add(&child->list, &c->child);
			cpumask_or(&c->child_cpus, &c->child_cpus,
					&child->child_cpus);
			c->aff_level = child->aff_level + 1;
		} else if (!of_node_cmp(n->name, "qcom,pm-cpu")) {
			key = "qcom,pm-cpu";
			if (parse_cpu_levels(n, c))
			if (parse_cpu_levels(n, c)) {
				pr_err("Failed parse pm-cpu\n");
				goto failed_parse_cluster;
			}

			c->aff_level = 1;
		}
@@ -711,7 +691,6 @@ struct lpm_cluster *parse_cluster(struct device_node *node,
	return c;

failed_parse_cluster:
	pr_err("Failed parse cluster:%s\n", key);
	of_node_put(n);
	if (parent)
		list_del(&c->list);
@@ -749,7 +728,6 @@ void cluster_dt_walkthrough(struct lpm_cluster *cluster)

	for (i = 0; i < id; i++)
		snprintf(str+i, 10 - i, "\t");
	pr_info("%d\n", __LINE__);

	for (i = 0; i < cluster->nlevels; i++) {
		struct lpm_cluster_level *l = &cluster->levels[i];
@@ -759,7 +737,6 @@ void cluster_dt_walkthrough(struct lpm_cluster *cluster)
	}

	list_for_each_entry(cpu, &cluster->cpu, list) {
		pr_info("%d\n", __LINE__);
		for (j = 0; j < cpu->nlevels; j++)
			pr_info("%s\tCPU level name: %s\n", str,
						cpu->levels[j].name);
@@ -770,7 +747,6 @@ void cluster_dt_walkthrough(struct lpm_cluster *cluster)
	list_for_each(list, &cluster->child) {
		struct lpm_cluster *n;

		pr_info("%d\n", __LINE__);
		n = list_entry(list, typeof(*n), list);
		cluster_dt_walkthrough(n);
	}
+2 −4
Original line number Diff line number Diff line
@@ -1413,7 +1413,6 @@ static int cpuidle_register_cpu(struct cpuidle_driver *drv,
	struct cpuidle_device *device;
	int cpu, ret;


	if (!mask || !drv)
		return -EINVAL;

@@ -1485,8 +1484,8 @@ static int cluster_cpuidle_register(struct lpm_cluster *cl)
			struct lpm_cpu_level *cpu_level = &lpm_cpu->levels[i];

			snprintf(st->name, CPUIDLE_NAME_LEN, "C%u\n", i);
			snprintf(st->desc, CPUIDLE_DESC_LEN, "%s",
					cpu_level->name);
			strlcpy(st->desc, cpu_level->name, CPUIDLE_DESC_LEN);

			st->flags = 0;
			st->exit_latency = cpu_level->pwr.exit_latency;
			st->target_residency = 0;
@@ -1584,7 +1583,6 @@ static void register_cluster_lpm_stats(struct lpm_cluster *cl,
	kfree(level_name);

	list_for_each_entry(cpu, &cl->cpu, list) {
		pr_err("%s()\n", __func__);
		register_cpu_lpm_stats(cpu, cl);
	}
	if (!list_empty(&cl->cpu))
+4 −8
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ struct event_timer_info *add_event_timer(uint32_t irq,
				void (*function)(void *), void *data)
{
	struct event_timer_info *event_info =
			kzalloc(sizeof(struct event_timer_info), GFP_KERNEL);
			kcalloc(1, sizeof(*event_info), GFP_KERNEL);

	if (!event_info)
		return NULL;
@@ -103,7 +103,7 @@ struct event_timer_info *add_event_timer(uint32_t irq,

	/* Init rb node and hr timer */
	timerqueue_init(&event_info->node);
	pr_debug("New Event Added. Event %pK(on cpu%d). irq %d.\n",
	pr_debug("New Event Added. Event %pK(on cpu%d). irq %d\n",
					event_info, event_info->cpu, irq);

	return event_info;
@@ -126,8 +126,6 @@ static bool is_event_next(struct event_timer_info *event)
		goto exit_is_next_event;

	next_event = container_of(next, struct event_timer_info, node);
	if (!next_event)
		goto exit_is_next_event;

	if (next_event == event)
		ret = true;
@@ -200,8 +198,6 @@ static enum hrtimer_restart event_hrtimer_cb(struct hrtimer *hrtimer)
	while (next && (ktime_to_ns(next->expires)
		<= ktime_to_ns(hrtimer->node.expires))) {
		event = container_of(next, struct event_timer_info, node);
		if (!event)
			goto hrtimer_cb_exit;

		WARN_ON_ONCE(event->cpu != cpu);

@@ -221,7 +217,7 @@ static enum hrtimer_restart event_hrtimer_cb(struct hrtimer *hrtimer)
		event = container_of(next, struct event_timer_info, node);
		create_hrtimer(event);
	}
hrtimer_cb_exit:

	spin_unlock_irqrestore(&event_timer_lock, flags);
	return HRTIMER_NORESTART;
}
@@ -307,7 +303,7 @@ static void irq_affinity_change_notifier(struct irq_affinity_notify *notify,
	old_cpu = event->cpu;

	if (msm_event_debug_mask && MSM_EVENT_TIMER_DEBUG)
		pr_debug("irq %d, event %pK, old_cpu(%d)->new_cpu(%d).\n",
		pr_debug("irq %d, event %pK, old_cpu(%d)->new_cpu(%d)\n",
						irq, event, old_cpu, new_cpu);

	/* No change in IRQ affinity */
+39 −98
Original line number Diff line number Diff line
@@ -46,6 +46,19 @@ static struct level_stats suspend_time_stats;

static DEFINE_PER_CPU_SHARED_ALIGNED(struct lpm_stats, cpu_stats);

bool str_is_reset(const char __user *in, size_t count)
{
	loff_t ppos = 0;
	char buffer[64] = { 0 };
	int ret = simple_write_to_buffer(buffer, sizeof(buffer) - 1,
					 &ppos, in, count - 1);

	if (ret > 0)
		return strcmp(buffer, lpm_stats_reset) ? false : true;

	return false;
}

static uint64_t get_total_sleep_time(unsigned int cpu_id)
{
	struct lpm_stats *stats = &per_cpu(cpu_stats, cpu_id);
@@ -96,25 +109,15 @@ static void level_stats_print(struct seq_file *m, struct level_stats *stats)
{
	int i = 0;
	int64_t bucket_time = 0;
	char seqs[MAX_STR_LEN] = {0};
	uint64_t s = stats->total_time;
	uint32_t ns = do_div(s, NSEC_PER_SEC);

	snprintf(seqs, MAX_STR_LEN,
		"[%s] %s:\n"
		"  success count: %7d\n"
	seq_printf(m, "[%s] %s:\n success count: %7d\n"
		"total success time: %lld.%09u\n",
		stats->owner->name,
		stats->name,
		stats->success_count,
		s, ns);
	seq_puts(m, seqs);
		stats->owner->name, stats->name, stats->success_count, s, ns);

	if (stats->failed_count) {
		snprintf(seqs, MAX_STR_LEN, "  failed count: %7d\n",
			stats->failed_count);
		seq_puts(m, seqs);
	}
	if (stats->failed_count)
		seq_printf(m, "  failed count: %7d\n", stats->failed_count);

	bucket_time = stats->first_bucket_time;
	for (i = 0;
@@ -122,30 +125,21 @@ static void level_stats_print(struct seq_file *m, struct level_stats *stats)
		i++) {
		s = bucket_time;
		ns = do_div(s, NSEC_PER_SEC);
		snprintf(seqs, MAX_STR_LEN,
			"\t<%6lld.%09u: %7d (%lld-%lld)\n",
		seq_printf(m, "\t<%6lld.%09u: %7d (%lld-%lld)\n",
			s, ns, stats->bucket[i],
			stats->min_time[i],
			stats->max_time[i]);
		seq_puts(m, seqs);
		bucket_time <<= CONFIG_MSM_IDLE_STATS_BUCKET_SHIFT;
	}
	snprintf(seqs, MAX_STR_LEN,
		"\t>=%5lld.%09u:%8d (%lld-%lld)\n",
	seq_printf(m, "\t>=%5lld.%09u:%8d (%lld-%lld)\n",
		s, ns, stats->bucket[i],
		stats->min_time[i],
		stats->max_time[i]);
	seq_puts(m, seqs);
}

static int level_stats_file_show(struct seq_file *m, void *v)
{
	struct level_stats *stats = NULL;

	if (!m->private)
		return -EINVAL;

	stats = (struct level_stats *) m->private;
	struct level_stats *stats = (struct level_stats *) m->private;

	level_stats_print(m, stats);

@@ -207,11 +201,6 @@ static int lpm_stats_file_show(struct seq_file *m, void *v)
{
	struct lpm_stats *stats = (struct lpm_stats *)m->private;

	if (!m->private) {
		pr_err("%s: Invalid pdata, Cannot print stats\n", __func__);
		return -EINVAL;
	}

	level_stats_print_all(m, stats);
	level_stats_print(m, &suspend_time_stats);

@@ -226,25 +215,13 @@ static int lpm_stats_file_open(struct inode *inode, struct file *file)
static ssize_t level_stats_file_write(struct file *file,
	const char __user *buffer, size_t count, loff_t *off)
{
	char buf[MAX_STR_LEN] = {0};
	struct inode *in = file->f_inode;
	struct level_stats *stats = (struct level_stats *)in->i_private;
	size_t len = strnlen(lpm_stats_reset, MAX_STR_LEN);

	if (!stats)
		return -EINVAL;

	if (count != len+1)
		return -EINVAL;

	if (copy_from_user(buf, buffer, len))
		return -EFAULT;

	if (strcmp(buf, lpm_stats_reset))
	if (!str_is_reset(buffer, count))
		return -EINVAL;

	level_stats_reset(stats);

	return count;
}

@@ -260,21 +237,10 @@ static void reset_cpu_stats(void *info)
static ssize_t lpm_stats_file_write(struct file *file,
	const char __user *buffer, size_t count, loff_t *off)
{
	char buf[MAX_STR_LEN] = {0};
	struct inode *in = file->f_inode;
	struct lpm_stats *stats = (struct lpm_stats *)in->i_private;
	size_t len = strnlen(lpm_stats_reset, MAX_STR_LEN);

	if (!stats)
		return -EINVAL;

	if (count != len+1)
		return -EINVAL;

	if (copy_from_user(buf, buffer, len))
		return -EFAULT;

	if (strcmp(buf, lpm_stats_reset))
	if (!str_is_reset(buffer, count))
		return -EINVAL;

	level_stats_reset_all(stats);
@@ -290,32 +256,22 @@ static ssize_t lpm_stats_file_write(struct file *file,

int lifo_stats_file_show(struct seq_file *m, void *v)
{
	struct lpm_stats *stats = NULL;
	struct lpm_stats *stats = (struct lpm_stats *)m->private;
	struct list_head *centry = NULL;
	struct lpm_stats *pos = NULL;
	char seqs[MAX_STR_LEN] = {0};

	if (!m->private)
		return -EINVAL;

	stats = (struct lpm_stats *)m->private;

	if (list_empty(&stats->child)) {
		pr_err("%s: ERROR: Lifo level with no children.\n",
		pr_err("%s: ERROR: Lifo level with no children\n",
			__func__);
		return -EINVAL;
	}

	centry = &stats->child;
	list_for_each_entry(pos, centry, sibling) {
		snprintf(seqs, MAX_STR_LEN,
			"%s:\n"
			"\tLast-In:%u\n"
			"\tFirst-Out:%u\n",
		seq_printf(m, "%s:\n\tLast-In:%u\n\tFirst-Out:%u\n",
			pos->name,
			pos->lifo.last_in,
			pos->lifo.first_out);
		seq_puts(m, seqs);
	}
	return 0;
}
@@ -342,21 +298,10 @@ static void lifo_stats_reset_all(struct lpm_stats *stats)
static ssize_t lifo_stats_file_write(struct file *file,
	const char __user *buffer, size_t count, loff_t *off)
{
	char buf[MAX_STR_LEN] = {0};
	struct inode *in = file->f_inode;
	struct lpm_stats *stats = (struct lpm_stats *)in->i_private;
	size_t len = strnlen(lpm_stats_reset, MAX_STR_LEN);

	if (!stats)
		return -EINVAL;

	if (count != len+1)
		return -EINVAL;

	if (copy_from_user(buf, buffer, len))
		return -EFAULT;

	if (strcmp(buf, lpm_stats_reset))
	if (!str_is_reset(buffer, count))
		return -EINVAL;

	lifo_stats_reset_all(stats);
@@ -406,7 +351,6 @@ static void update_last_in_stats(struct lpm_stats *stats)
			return;
		}
	}
	WARN(1, "Should not reach here\n");
}

static void update_first_out_stats(struct lpm_stats *stats)
@@ -424,7 +368,6 @@ static void update_first_out_stats(struct lpm_stats *stats)
			return;
		}
	}
	WARN(1, "Should not reach here\n");
}

static inline void update_exit_stats(struct lpm_stats *stats, uint32_t index,
@@ -455,7 +398,7 @@ static int config_level(const char *name, const char **levels,
	INIT_LIST_HEAD(&stats->sibling);
	INIT_LIST_HEAD(&stats->child);

	stats->time_stats = kcalloc(num_levels, sizeof(struct level_stats),
	stats->time_stats = kcalloc(num_levels, sizeof(*stats->time_stats),
					GFP_KERNEL);
	if (!stats->time_stats)
		return -ENOMEM;
@@ -511,7 +454,7 @@ static ssize_t total_sleep_time_show(struct kobject *kobj,
	unsigned int cpu = cpu_sleep_time->cpu;
	uint64_t total_time = get_total_sleep_time(cpu);

	return snprintf(buf, MAX_TIME_LEN, "%llu.%09u\n", total_time,
	return scnprintf(buf, MAX_TIME_LEN, "%llu.%09u\n", total_time,
			do_div(total_time, NSEC_PER_SEC));
}

@@ -525,7 +468,7 @@ static struct kobject *local_module_kobject(void)
		int err;
		struct module_kobject *mk;

		mk = kzalloc(sizeof(*mk), GFP_KERNEL);
		mk = kcalloc(1, sizeof(*mk), GFP_KERNEL);
		if (!mk)
			return ERR_PTR(-ENOMEM);

@@ -555,7 +498,7 @@ static int create_sysfs_node(unsigned int cpu, struct lpm_stats *stats)
	struct kobject *cpu_kobj = NULL;
	struct lpm_sleep_time *ts = NULL;
	struct kobject *stats_kobj;
	char cpu_name[] = "cpuXX";
	char cpu_name[10] = { 0 };
	int ret = -ENOMEM;

	stats_kobj = local_module_kobject();
@@ -568,7 +511,7 @@ static int create_sysfs_node(unsigned int cpu, struct lpm_stats *stats)
	if (!cpu_kobj)
		return -ENOMEM;

	ts = kzalloc(sizeof(*ts), GFP_KERNEL);
	ts = kcalloc(1, sizeof(*ts), GFP_KERNEL);
	if (!ts)
		goto failed;

@@ -604,10 +547,10 @@ static struct lpm_stats *config_cpu_level(const char *name,

	for_each_cpu(cpu, mask) {
		int ret = 0;
		char cpu_name[MAX_STR_LEN] = {0};
		char cpu_name[16] = { 0 };

		stats = &per_cpu(cpu_stats, cpu);
		snprintf(cpu_name, MAX_STR_LEN, "%s%d", name, cpu);
		snprintf(cpu_name, sizeof(cpu_name), "%s%d", name, cpu);
		cpumask_set_cpu(cpu, &stats->mask);

		stats->is_cpu = true;
@@ -654,7 +597,7 @@ static struct lpm_stats *config_cluster_level(const char *name,
	struct lpm_stats *stats = NULL;
	int ret = 0;

	stats = kzalloc(sizeof(struct lpm_stats), GFP_KERNEL);
	stats = kcalloc(1, sizeof(*stats), GFP_KERNEL);
	if (!stats)
		return ERR_PTR(-ENOMEM);

@@ -741,9 +684,7 @@ struct lpm_stats *lpm_stats_config_level(const char *name,
	struct lpm_stats *stats = NULL;

	if (!levels || num_levels <= 0 || IS_ERR(parent)) {
		pr_err("%s: Invalid input\n\t\tlevels = %p\n\t\t"
			"num_levels = %d\n\t\tparent = %ld\n",
			__func__, levels, num_levels, PTR_ERR(parent));
		pr_err("%s: Invalid input\n", __func__);
		return ERR_PTR(-EINVAL);
	}

+2 −2
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ static inline int msm_rpmstats_append_data_to_buf(char *buf,
	actual_last_sleep = get_time_in_msec(data->accumulated);

#if defined(CONFIG_MSM_RPM_SMD)
	return snprintf(buf, buflength,
	return scnprintf(buf, buflength,
		"RPM Mode:%s\n\t count:%d\ntime in last mode(msec):%llu\n"
		"time since last mode(sec):%llu\nactual last sleep(msec):%llu\n"
		"client votes: %#010x\n\n",
@@ -103,7 +103,7 @@ static inline int msm_rpmstats_append_data_to_buf(char *buf,
		time_since_last_mode, actual_last_sleep,
		data->client_votes);
#else
	return snprintf(buf, buflength,
	return scnprintf(buf, buflength,
		"RPM Mode:%s\n\t count:%d\ntime in last mode(msec):%llu\n"
		"time since last mode(sec):%llu\nactual last sleep(msec):%llu\n\n",
		stat_type, data->count, time_in_last_mode,
Loading