コード例 #1
0
ファイル: intel_epb.c プロジェクト: pranith/linux
static ssize_t energy_perf_bias_store(struct device *dev,
				      struct device_attribute *attr,
				      const char *buf, size_t count)
{
	unsigned int cpu = dev->id;
	u64 epb, val;
	int ret;

	ret = __sysfs_match_string(energy_perf_strings,
				   ARRAY_SIZE(energy_perf_strings), buf);
	if (ret >= 0)
		val = energ_perf_values[ret];
	else if (kstrtou64(buf, 0, &val) || val > MAX_EPB)
		return -EINVAL;

	ret = rdmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb);
	if (ret < 0)
		return ret;

	ret = wrmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS,
			    (epb & ~EPB_MASK) | val);
	if (ret < 0)
		return ret;

	return count;
}
コード例 #2
0
ファイル: gateway_common.c プロジェクト: Anjali05/linux
/**
 * batadv_parse_throughput() - parse supplied string buffer to extract
 *  throughput information
 * @net_dev: the soft interface net device
 * @buff: string buffer to parse
 * @description: text shown when throughput string cannot be parsed
 * @throughput: pointer holding the returned throughput information
 *
 * Return: false on parse error and true otherwise.
 */
bool batadv_parse_throughput(struct net_device *net_dev, char *buff,
			     const char *description, u32 *throughput)
{
	enum batadv_bandwidth_units bw_unit_type = BATADV_BW_UNIT_KBIT;
	u64 lthroughput;
	char *tmp_ptr;
	int ret;

	if (strlen(buff) > 4) {
		tmp_ptr = buff + strlen(buff) - 4;

		if (strncasecmp(tmp_ptr, "mbit", 4) == 0)
			bw_unit_type = BATADV_BW_UNIT_MBIT;

		if (strncasecmp(tmp_ptr, "kbit", 4) == 0 ||
		    bw_unit_type == BATADV_BW_UNIT_MBIT)
			*tmp_ptr = '\0';
	}

	ret = kstrtou64(buff, 10, &lthroughput);
	if (ret) {
		batadv_err(net_dev,
			   "Invalid throughput speed for %s: %s\n",
			   description, buff);
		return false;
	}

	switch (bw_unit_type) {
	case BATADV_BW_UNIT_MBIT:
		/* prevent overflow */
		if (U64_MAX / 10 < lthroughput) {
			batadv_err(net_dev,
				   "Throughput speed for %s too large: %s\n",
				   description, buff);
			return false;
		}

		lthroughput *= 10;
		break;
	case BATADV_BW_UNIT_KBIT:
	default:
		lthroughput = div_u64(lthroughput, 100);
		break;
	}

	if (lthroughput > U32_MAX) {
		batadv_err(net_dev,
			   "Throughput speed for %s too large: %s\n",
			   description, buff);
		return false;
	}

	*throughput = lthroughput;

	return true;
}
コード例 #3
0
static int htifblk_probe(struct device *dev)
{
	static unsigned int index = 0;
	static const char prefix[] = " size=";

	struct htif_device *htif_dev;
	struct htifblk_device *htifblk_dev;
	struct gendisk *disk;
	struct request_queue *queue;
	const char *str;
	u64 size;
	int ret;

	dev_info(dev, "detected disk\n");
	htif_dev = to_htif_dev(dev);

	str = strstr(htif_dev->id, prefix);
	if (unlikely(str == NULL
	    || kstrtou64(str + sizeof(prefix) - 1, 10, &size))) {
		dev_err(dev, "error determining size of disk\n");
		return -ENODEV;
	}
	if (unlikely(size & (SECTOR_SIZE - 1))) {
		dev_warn(dev, "disk size not a multiple of sector size:"
			" %llu\n", size);
	}

	ret = -ENOMEM;
	htifblk_dev = devm_kzalloc(dev, sizeof(struct htifblk_device), GFP_KERNEL);
	if (unlikely(htifblk_dev == NULL))
		goto out;

	htifblk_dev->size = size;
	htifblk_dev->dev = htif_dev;
	htifblk_dev->tag = index;
	spin_lock_init(&htifblk_dev->lock);

	disk = alloc_disk(1);
	if (unlikely(disk == NULL))
		goto out;

	queue = blk_init_queue(htifblk_request, &htifblk_dev->lock);
	if (unlikely(queue == NULL))
		goto out_put_disk;

	queue->queuedata = htifblk_dev;
	blk_queue_max_segments(queue, 1);
	blk_queue_dma_alignment(queue, HTIF_ALIGN - 1);

	disk->queue = queue;
	disk->major = major;
	disk->minors = 1;
	disk->first_minor = 0;
	disk->fops = &htifblk_fops;
	set_capacity(disk, size >> SECTOR_SIZE_SHIFT);
	snprintf(disk->disk_name, DISK_NAME_LEN - 1, "htifblk%u", index++);

	htifblk_dev->disk = disk;
	add_disk(disk);
	dev_info(dev, "added %s\n", disk->disk_name);

	ret = htif_request_irq(htif_dev, htifblk_isr);
	if (unlikely(ret))
		goto out_del_disk;

	dev_set_drvdata(dev, htifblk_dev);
	return 0;

out_del_disk:
	del_gendisk(disk);
	blk_cleanup_queue(disk->queue);
out_put_disk:
	put_disk(disk);
out:
	return ret;
}
コード例 #4
0
// error return value
// recv data error : -ENOMSG or -ERANGE
// kernel data or processing error : -EINVAL
int dct_setData(char *name, int type, void *data, int size)
{
	int ret = 0;
	char *sep = "\n";
	char *sep2 = ",";
	char temp_text[30] = "%s is set to ";
	char *line = NULL;

	char *read_name;
	char *read_type;
	char *read_value;
	char *tmp_log = NULL;
	u64 temp_value;

	DCT_LOG("[DCT][%s] ++\n", __func__);

	if ((tmp_log = kmalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) {
		pr_err("[DCT][%s] Malloc of tmp_log is fail!\n", __func__);
		ret = -ENOMEM;
		goto error;
	}

	if((ret = check_type_info(tmp_log))) {
		goto error;
	}
	
	line = strsep(&dct_recv_str, sep);
	if(line == NULL) {
		sprintf(tmp_log, "requested line is null!\nRequest : %s %s\n", name, dct_tinfo[type].name);
		dct_save_log(tmp_log, true);
		ret = -ENOMSG;
		goto error;
	}

	if (type < 0 || type >= DCT_TYPE_MAX) {
		sprintf(tmp_log, "[%s] request type error(%d)\n", __func__, type);
		dct_save_log(tmp_log, true);
		ret = -EINVAL;
		goto error;
	}
		
	if (size != dct_tinfo[type].size) {
		sprintf(tmp_log, "size error\nrequest name : %s\n(request : %s(%d), target : %d)\nCheck the kernel code",
				name, dct_tinfo[type].name, dct_tinfo[type].size, size);
		dct_save_log(tmp_log, true);
		ret = -EINVAL;
		goto error;
	}

	if (line[strlen(line)-1] == '\r')
		line[strlen(line)-1] = 0;

	if((read_name = strsep(&line, sep2)) == NULL)
	{
		sprintf(tmp_log, "Read data name is NULL\n");
		dct_save_log(tmp_log, true);		
		ret = -ENOMSG;
		goto error;
	}
	if((read_type = strsep(&line, sep2)) == NULL)
	{
		sprintf(tmp_log, "Read data type is NULL\n");
		dct_save_log(tmp_log, true);
		ret = -ENOMSG;
		goto error;
	}
	if((read_value = strsep(&line, sep2)) == NULL)
	{
		sprintf(tmp_log, "Read data name is NULL\n");
		dct_save_log(tmp_log, true);
		ret = -ENOMSG;
		goto error;
	}

	if(strcmp(read_name, name) || strcmp(read_type, dct_tinfo[type].name)) {
		sprintf(tmp_log, "data is wrong!\n");
		sprintf(tmp_log, "%s\tname : Request - %s , Read - %s\n", tmp_log, name, read_name);
		sprintf(tmp_log, "%s\ttype : Request - %s , Read - %s\n", tmp_log, dct_tinfo[type].name, read_type);
		dct_save_log(tmp_log, true);
		ret = -ENOMSG;
		goto error;
	}

	if (read_value[0] == '-') {
		sprintf(tmp_log, "Read value is negative\n(%s,%s,%s)\n", read_name, read_type, read_value);
		dct_save_log(tmp_log, true);
		ret = -ENOMSG;
		goto error;
	}

	ret = kstrtou64(read_value, 10, &temp_value);
	if (ret) {
		//int i=0;
		sprintf(tmp_log, "Data value translation error!\n(%s,%s,%s)\nerrno = %d\n", 
			read_name, read_type, read_value, ret);
		//sprintf(tmp_log, "%s\tread_value len = %d\n", 
		//	tmp_log, strlen(read_value));
		//for(i = 0; i < strlen(read_value); i++) {
		//	sprintf(tmp_log, "%s%hhd ", tmp_log, read_value[i]);	
		//}
		//strcat(tmp_log, "\n");
		ret = -ERANGE;		// unify result value
		dct_save_log(tmp_log, true);
		goto error;
	}

	
	strcat(temp_text, dct_tinfo[type].format);
	strcat(temp_text, "\n");
	switch (type) {
	case DCT_TYPE_U8:
		if (temp_value != (unsigned long long)(u8)temp_value) {
			sprintf(tmp_log, "Data range error!\ndata : %llu\nEnable Max Value: %llu\n", temp_value, 0xffLL);
			dct_save_log(tmp_log, true);
			ret = -ERANGE;
			goto error; 	
		}
		*(u8 *)data = (u8)temp_value;

		sprintf(tmp_log, temp_text, name, *(u8 *)data);
		dct_save_log(tmp_log, false);
		break;
	case DCT_TYPE_U16:
		if (temp_value != (unsigned long long)(u16)temp_value) {
			sprintf(tmp_log, "Data range error!\ndata : %llu\nEnable Max Value: %llu\n", temp_value, 0xffffLL);
			dct_save_log(tmp_log, true);
			ret = -ERANGE;
			goto error; 	
		}
		*(u16 *)data = (u16)temp_value;

		sprintf(tmp_log, temp_text, name, *(u16 *)data);
		dct_save_log(tmp_log, false);
		break;
	case DCT_TYPE_U32:
		if (temp_value != (unsigned long long)(u32)temp_value) {
			sprintf(tmp_log, "Data range error!\ndata : %llu\nEnable Max Value: %llu\n", temp_value, 0xffffffffLL);
			dct_save_log(tmp_log, true);
			ret = -ERANGE;
			goto error; 	
		}
		*(u32 *)data = (u32)temp_value;

		sprintf(tmp_log, temp_text, name, *(u32 *)data);
		dct_save_log(tmp_log, false);
		break;
	case DCT_TYPE_U64:
		if (temp_value != (unsigned long long)(u64)temp_value) {
			sprintf(tmp_log, "Data range error!\ndata : %llu\nEnable Max Value: %llu\n", temp_value, 0xffffffffffffffffLL);
			dct_save_log(tmp_log, true);
			ret = -ERANGE;
			goto error; 	
		}
		*(u64 *)data = (u64)temp_value;

		sprintf(tmp_log, temp_text, name, *(u64 *)data);
		dct_save_log(tmp_log, false);
		break;
	
	}

error:
	if (tmp_log)
		kfree(tmp_log);

	DCT_LOG("[DCT][%s] -- (%d)\n", __func__, ret);

	return ret;
}
コード例 #5
0
ファイル: mobility.c プロジェクト: 1314cc/linux
	rc = pseries_devicetree_update(MIGRATION_SCOPE);
	if (rc)
		printk(KERN_ERR "Post-mobility device tree update "
			"failed: %d\n", rc);

	return;
}

static ssize_t migrate_store(struct class *class, struct class_attribute *attr,
			     const char *buf, size_t count)
{
	u64 streamid;
	int rc;

	rc = kstrtou64(buf, 0, &streamid);
	if (rc)
		return rc;

	do {
		rc = rtas_ibm_suspend_me(streamid);
		if (rc == -EAGAIN)
			ssleep(1);
	} while (rc == -EAGAIN);

	if (rc)
		return rc;

	post_mobility_fixup();
	return count;
}