示例#1
0
static int init_rq_attribs(void)
{
	int i;
	int err = 0;
	const int attr_count = 4;

	struct attribute **attribs =
		kzalloc(sizeof(struct attribute *) * attr_count, GFP_KERNEL);

	if (!attribs)
		goto rel;

	rq_info.rq_avg = 0;
	rq_info.rq_poll_ms = 0;

	attribs[0] = MSM_RQ_STATS_RW_ATTRIB(def_timer_ms);
#if defined(CONFIG_KOR_MODEL_SHV_E120S)|| defined(CONFIG_KOR_MODEL_SHV_E120K) || defined(CONFIG_KOR_MODEL_SHV_E120L)
	attribs[1] = MSM_RQ_STATS_RW_ATTRIB(run_queue_avg);
#else
	attribs[1] = MSM_RQ_STATS_RO_ATTRIB(run_queue_avg);
#endif
	attribs[2] = MSM_RQ_STATS_RW_ATTRIB(run_queue_poll_ms);
	attribs[3] = NULL;

	for (i = 0; i < attr_count - 1 ; i++) {
		if (!attribs[i])
			goto rel;
	}

	rq_info.attr_group = kzalloc(sizeof(struct attribute_group),
						GFP_KERNEL);
	if (!rq_info.attr_group)
		goto rel;
	rq_info.attr_group->attrs = attribs;

	/* Create /sys/devices/system/cpu/cpu0/rq-stats/... */
	rq_info.kobj = kobject_create_and_add("rq-stats",
			&get_cpu_sysdev(0)->kobj);
	if (!rq_info.kobj)
		goto rel;

	err = sysfs_create_group(rq_info.kobj, rq_info.attr_group);
	if (err)
		kobject_put(rq_info.kobj);
	else
		kobject_uevent(rq_info.kobj, KOBJ_ADD);

	if (!err)
		return err;

rel:
	for (i = 0; i < attr_count - 1 ; i++)
		kfree(attribs[i]);
	kfree(attribs);
	kfree(rq_info.attr_group);
	kfree(rq_info.kobj);

	return -ENOMEM;
}
static int init_rq_attribs(void)
{
    int i;
    int err = 0;
    const int attr_count = 4;

    struct attribute **attribs =
        kzalloc(sizeof(struct attribute *) * attr_count, GFP_KERNEL);

    if (!attribs) {
        pr_err("%s: Allocate attribs failed!\n", __func__);
        goto rel;
    }

    rq_info.rq_avg = 0;

    attribs[0] = MSM_RQ_STATS_RW_ATTRIB(def_timer_ms);
    attribs[1] = MSM_RQ_STATS_RO_ATTRIB(run_queue_avg);
    attribs[2] = MSM_RQ_STATS_RW_ATTRIB(run_queue_poll_ms);
    attribs[3] = NULL;

    for (i = 0; i < attr_count - 1 ; i++) {
        if (!attribs[i]) {
            pr_err("%s: Allocate attribs[%d] failed!\n", __func__, i);
            goto rel2;
        }
    }

    rq_info.attr_group = kzalloc(sizeof(struct attribute_group),
                                 GFP_KERNEL);
    if (!rq_info.attr_group) {
        pr_err("%s: Allocate rq_info.attr_group failed!\n", __func__);
        goto rel3;
    }
    rq_info.attr_group->attrs = attribs;

    /* Create /sys/devices/system/cpu/cpu0/rq-stats/... */
    rq_info.kobj = kobject_create_and_add("rq-stats",
                                          &get_cpu_sysdev(0)->kobj);
    if (!rq_info.kobj) {
        pr_err("%s: Create rq_info.kobj failed!\n", __func__);
        goto rel3;
    }

    err = sysfs_create_group(rq_info.kobj, rq_info.attr_group);
    if (err)
        kobject_put(rq_info.kobj);
    else
        kobject_uevent(rq_info.kobj, KOBJ_ADD);

    if (!err) {
        pr_info("%s: Initialize done.\n", __func__);
        init_done = 1;
        return err;
    }

rel3:
    kfree(rq_info.attr_group);
    kfree(rq_info.kobj);
rel2:
    for (i = 0; i < attr_count - 1; i++)
        kfree(attribs[i]);
rel:
    kfree(attribs);

    return -ENOMEM;
}