示例#1
0
static int parse_init_date(const char *date)
{
	char local_str[TIME_LEN + 1];
	char *year_s, *month_s, *day_s, *str;
	unsigned int year_d, month_d, day_d;
	int ret;
	if (strlen(date) != 10)
		return -1;
	memset(local_str, 0, TIME_LEN + 1);
	strncpy(local_str, date, TIME_LEN);
	str = local_str;
	year_s = strsep(&str, "/");
	if (!year_s)
		return -1;
	month_s = strsep(&str, "/");
	if (!month_s)
		return -1;
	day_s = str;
	pr_debug("year: %s\nmonth: %s\nday: %s\n", year_s, month_s, day_s);
	ret = kstrtou32(year_s, 10, &year_d);
	if (ret < 0 || year_d > 2100 || year_d < 1900)
		return -1;
	ret = kstrtou32(month_s, 10, &month_d);
	if (ret < 0 || month_d > 12)
		return -1;
	ret = kstrtou32(day_s, 10, &day_d);
	if (ret < 0 || day_d > 31)
		return -1;
	vrtc_init_date = mktime(year_d, month_d, day_d, 0, 0, 0);
	return 0;
}
static int parse_android_emu(struct f2fs_sb_info *sbi, char *args)
{
    char *sep = args;
    char *sepres;
    int ret;

    if (!sep)
        return -EINVAL;

    sepres = strsep(&sep, ":");
    if (!sep)
        return -EINVAL;
    ret = kstrtou32(sepres, 0, &sbi->android_emu_uid);
    if (ret)
        return ret;

    sepres = strsep(&sep, ":");
    if (!sep)
        return -EINVAL;
    ret = kstrtou32(sepres, 0, &sbi->android_emu_gid);
    if (ret)
        return ret;

    sepres = strsep(&sep, ":");
    ret = kstrtou16(sepres, 8, &sbi->android_emu_mode);
    if (ret)
        return ret;

    if (sep && strstr(sep, "nocase"))
        sbi->android_emu_flags = F2FS_ANDROID_EMU_NOCASE;

    return 0;
}
static int mbox_debugfs_msg_get(char *cmd, mbox_msg_t *msg)
{
	char *_cmd = cmd;
	int i = 0;

	while (1) {
		if (i >= 8)
			break;

		if (' ' == *_cmd) {
			*_cmd = '\0';
			if (kstrtou32(cmd, 16, &msg[i]))
				return -EINVAL;
			cmd = _cmd + 1;
			*_cmd = ' ';
			i++;
		} else if ('\0' == *_cmd) {
			if (kstrtou32(cmd, 16, &msg[i]))
				return -EINVAL;
			i++;
			break;
		} else {
			;
		}
		_cmd++;
	}
	return i;
}
示例#4
0
static int __parse_dt_trip(struct device_node *np,
			   struct thermal_trip_info *trips)
{
	const char *str;
	u32 val;
	int ret;

	ret = of_property_read_string(np, "cdev-type", &str);
	if (ret < 0)
		return ret;
	trips->cdev_type = (char *)str;

	ret = of_property_read_string(np, "trip-type", &str);
	if (ret < 0)
		return ret;

	if (!strcasecmp("active", str))
		trips->trip_type = THERMAL_TRIP_ACTIVE;
	else if (!strcasecmp("passive", str))
		trips->trip_type = THERMAL_TRIP_PASSIVE;
	else if (!strcasecmp("hot", str))
		trips->trip_type = THERMAL_TRIP_HOT;
	else if (!strcasecmp("critical", str))
		trips->trip_type = THERMAL_TRIP_CRITICAL;
	else
		return -EINVAL;

	ret = of_property_read_u32(np, "trip-temp", &val);
	if (ret < 0)
		return ret;
	trips->trip_temp = val;

	trips->hysteresis = 0;
	if (of_property_read_u32(np, "hysteresis", &val) == 0)
		trips->hysteresis = val;

	trips->upper = THERMAL_NO_LIMIT;
	if (of_property_read_string(np, "upper", &str) == 0) {
		if (kstrtou32(str, 10, &val) == 0)
			trips->upper = val;
	}

	trips->lower = THERMAL_NO_LIMIT;
	if (of_property_read_string(np, "lower", &str) == 0) {
		if (kstrtou32(str, 10, &val) == 0)
			trips->lower = val;
	}

	return 0;
}
示例#5
0
文件: qib_sysfs.c 项目: 020gzh/linux
static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
				const char *buf, size_t size)
{
	struct qib_diagc_attr *dattr =
		container_of(attr, struct qib_diagc_attr, attr);
	struct qib_pportdata *ppd =
		container_of(kobj, struct qib_pportdata, diagc_kobj);
	struct qib_ibport *qibp = &ppd->ibport_data;
	u32 val;
	int ret;

	ret = kstrtou32(buf, 0, &val);
	if (ret)
		return ret;

	if (!strncmp(dattr->attr.name, "rc_acks", 7))
		write_per_cpu_rc_acks(ppd, val);
	else if (!strncmp(dattr->attr.name, "rc_qacks", 8))
		write_per_cpu_rc_qacks(ppd, val);
	else if (!strncmp(dattr->attr.name, "rc_delayed_comp", 15))
		write_per_cpu_rc_delayed_comp(ppd, val);
	else
		*(u32 *)((char *)qibp + dattr->counter) = val;
	return size;
}
示例#6
0
文件: light.c 项目: gregkh/greybus
static ssize_t color_store(struct device *dev, struct device_attribute *attr,
			   const char *buf, size_t size)
{
	struct led_classdev *cdev = dev_get_drvdata(dev);
	struct gb_channel *channel = get_channel_from_cdev(cdev);
	u32 color;
	int ret;

	led_lock(cdev);
	if (led_sysfs_is_disabled(cdev)) {
		ret = -EBUSY;
		goto unlock;
	}
	ret = kstrtou32(buf, 0, &color);
	if (ret < 0) {
		dev_err(dev, "could not parse color value %d\n", ret);
		goto unlock;
	}

	ret = gb_lights_color_set(channel, color);
	if (ret < 0)
		goto unlock;

	channel->color = color;
	ret = size;
unlock:
	led_unlock(cdev);
	return ret;
}
static ssize_t ath6kl_inact_period_write(struct file *file,
					 const char __user *user_buf,
					 size_t count, loff_t *ppos)
{
	struct ath6kl *ar = file->private_data;
	int ret;
	char buf[32];
	u32 inact_period;
	size_t len;

	len = min(count, sizeof(buf) - 1);
	if (copy_from_user(buf, user_buf, len))
		return -EFAULT;

	buf[len] = '\0';
	if (kstrtou32(buf, 0, &inact_period))
		return -EINVAL;

	ret = ath6kl_wmi_inact_period_cmd(ar->wmi, inact_period, 0);

	if (ret)
		return ret;

	return count;
}
示例#8
0
static int __init setup_test_suspend(char *value)
{
	int i;
	char *repeat;
	char *suspend_type;

	/* example : "=mem[,N]" ==> "mem[,N]" */
	value++;
	suspend_type = strsep(&value, ",");
	if (!suspend_type)
		return 0;

	repeat = strsep(&value, ",");
	if (repeat) {
		if (kstrtou32(repeat, 0, &test_repeat_count_max))
			return 0;
	}

	for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
		if (!strcmp(pm_labels[i], suspend_type)) {
			test_state_label = pm_labels[i];
			return 0;
		}

	printk(warn_bad_state, suspend_type);
	return 0;
}
示例#9
0
static int dlpar_parse_id_type(char **cmd, struct pseries_hp_errorlog *hp_elog)
{
	char *arg;
	u32 count, index;

	arg = strsep(cmd, " ");
	if (!arg)
		return -EINVAL;

	if (sysfs_streq(arg, "index")) {
		hp_elog->id_type = PSERIES_HP_ELOG_ID_DRC_INDEX;
		arg = strsep(cmd, " ");
		if (!arg) {
			pr_err("No DRC Index specified.\n");
			return -EINVAL;
		}

		if (kstrtou32(arg, 0, &index)) {
			pr_err("Invalid DRC Index specified.\n");
			return -EINVAL;
		}

		hp_elog->_drc_u.drc_index = cpu_to_be32(index);
	} else if (sysfs_streq(arg, "count")) {
		hp_elog->id_type = PSERIES_HP_ELOG_ID_DRC_COUNT;
		arg = strsep(cmd, " ");
		if (!arg) {
			pr_err("No DRC count specified.\n");
			return -EINVAL;
		}

		if (kstrtou32(arg, 0, &count)) {
			pr_err("Invalid DRC count specified.\n");
			return -EINVAL;
		}

		hp_elog->_drc_u.drc_count = cpu_to_be32(count);
	} else {
		pr_err("Invalid id_type specified.\n");
		return -EINVAL;
	}

	return 0;
}
static ssize_t tegra_cpu_volt_store(struct kobject *kobj,
	struct kobj_attribute *attr, const char *buf, size_t count)
{
	unsigned int val;

	if (kstrtou32(buf, 10, &val))
		return -EINVAL;

	mutex_lock(&capping_lock);
	capping_data.capped_voltage = val;
	mutex_unlock(&capping_lock);
	return count;
}
示例#11
0
static int parse_perms(struct sdcardfs_perms *perms, char *args)
{
	char *sep = args;
	char *sepres;
	int ret;

	if (!sep)
		return -EINVAL;

	sepres = strsep(&sep, ":");
	if (!sep)
		return -EINVAL;
	ret = kstrtou32(sepres, 0, &perms->uid);
	if (ret)
		return ret;

	sepres = strsep(&sep, ":");
	if (!sep)
		return -EINVAL;
	ret = kstrtou32(sepres, 0, &perms->gid);
	if (ret)
		return ret;

	sepres = strsep(&sep, ":");
	if (!sep)
		return -EINVAL;
	ret = kstrtou16(sepres, 8, &perms->fmask);
	if (ret)
		return ret;

	sepres = strsep(&sep, ":");
	ret = kstrtou16(sepres, 8, &perms->dmask);
	if (ret)
		return ret;

	return 0;
}
示例#12
0
文件: sysfs.c 项目: 1800alex/linux
static ssize_t store_pw20_state(struct device *dev,
				struct device_attribute *attr,
				const char *buf, size_t count)
{
	u32 value;
	unsigned int cpu = dev->id;

	if (kstrtou32(buf, 0, &value))
		return -EINVAL;

	if (value > 1)
		return -EINVAL;

	smp_call_function_single(cpu, do_store_pw20_state, &value, 1);

	return count;
}
示例#13
0
static ssize_t report_delay_store(struct device *dev,
				  struct device_attribute *attr,
				  const char *buf, size_t count)
{
	struct aml_pmu_api *api = aml_pmu_get_api();
	uint32_t tmp;
	int ret;

	ret = kstrtou32(buf, 10, &tmp);
	if (tmp > 200) {
		AML1216_ERR("input too large, failed to set report_delay\n");
		return count;
	}
	if (api && api->pmu_set_report_delay)
		api->pmu_set_report_delay(tmp);
	else
		AML1216_ERR("API not found\n");
	return count;
}
示例#14
0
static ssize_t pmu_features_store(struct hyp_sysfs_attr *attr,
				  const char *buffer, size_t len)
{
	int ret;
	uint32_t features;
	struct xen_pmu_params xp;

	ret = kstrtou32(buffer, 0, &features);
	if (ret)
		return ret;

	xp.val = features;
	xp.version.maj = XENPMU_VER_MAJ;
	xp.version.min = XENPMU_VER_MIN;
	ret = HYPERVISOR_xenpmu_op(XENPMU_feature_set, &xp);
	if (ret)
		return ret;

	return len;
}
static ssize_t capping_enable_store(struct kobject *kobj,
	struct kobj_attribute *attr, const char *buf, size_t count)
{
	unsigned int val;
	int voltage;

	if (kstrtou32(buf, 10, &val))
		return -EINVAL;

	mutex_lock(&capping_lock);
	capping_data.voltage_capping_enabled = (bool)val;
	voltage = capping_data.capped_voltage;
	mutex_unlock(&capping_lock);
	if (val && voltage)
		tegra_cpu_set_volt_cap(tegra_edp_find_maxf(voltage));
	else
		tegra_cpu_set_volt_cap(0);

	return count;
}
示例#16
0
static ssize_t ade7854_write_32bit(struct device *dev,
				   struct device_attribute *attr,
				   const char *buf,
				   size_t len)
{
	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
	struct ade7854_state *st = iio_priv(indio_dev);

	int ret;
	u32 val;

	ret = kstrtou32(buf, 10, &val);
	if (ret)
		goto error_ret;
	ret = st->write_reg_32(dev, this_attr->address, val);

error_ret:
	return ret ? ret : len;
}
示例#17
0
static ssize_t store_rpm_delay(struct device *dev, struct device_attribute
                               *attr, const char *buf, size_t count)
{
    struct mmc_card *card = mmc_dev_to_card(dev);
    unsigned int delay;

    if (!card) {
        pr_err("%s: %s: card is NULL\n", dev_name(dev), __func__);
        return -EINVAL;
    }

    if (!kstrtou32(buf, 0, &delay)) {
        if (delay < 2000) {
            pr_err("%s: %s: less than 2 sec delay is unsupported\n",
                   mmc_hostname(card->host), __func__);
            return -EINVAL;
        }
        card->idle_timeout = delay;
    }

    return count;
}
示例#18
0
文件: dlpar.c 项目: 3null/linux
static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
{
	struct device_node *dn, *parent;
	u32 drc_index;
	int rc;

	rc = kstrtou32(buf, 0, &drc_index);
	if (rc)
		return -EINVAL;

	parent = of_find_node_by_path("/cpus");
	if (!parent)
		return -ENODEV;

	dn = dlpar_configure_connector(cpu_to_be32(drc_index), parent);
	if (!dn)
		return -EINVAL;

	of_node_put(parent);

	rc = dlpar_acquire_drc(drc_index);
	if (rc) {
		dlpar_free_cc_nodes(dn);
		return -EINVAL;
	}

	rc = dlpar_attach_node(dn);
	if (rc) {
		dlpar_release_drc(drc_index);
		dlpar_free_cc_nodes(dn);
		return rc;
	}

	rc = dlpar_online_cpu(dn);
	if (rc)
		return rc;

	return count;
}
示例#19
0
static ssize_t display_wss_store(struct omap_dss_device *dssdev,
	const char *buf, size_t size)
{
	u32 wss;
	int r;

	if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
		return -ENOENT;

	r = kstrtou32(buf, 0, &wss);
	if (r)
		return r;

	if (wss > 0xfffff)
		return -EINVAL;

	r = dssdev->driver->set_wss(dssdev, wss);
	if (r)
		return r;

	return size;
}
示例#20
0
文件: debugfs.c 项目: krzk/linux
/* debugfs verext file write handler.
 * This function is called when the 'verext' file is opened for write
 */
static ssize_t
mwifiex_verext_write(struct file *file, const char __user *ubuf,
		     size_t count, loff_t *ppos)
{
	int ret;
	u32 versionstrsel;
	struct mwifiex_private *priv = (void *)file->private_data;
	char buf[16];

	memset(buf, 0, sizeof(buf));

	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
		return -EFAULT;

	ret = kstrtou32(buf, 10, &versionstrsel);
	if (ret)
		return ret;

	priv->versionstrsel = versionstrsel;

	return count;
}
示例#21
0
文件: cong.c 项目: Anjali05/linux
static ssize_t set_param(struct file *filp, const char __user *buf,
			 size_t count, loff_t *pos)
{
	struct mlx5_ib_dbg_param *param = filp->private_data;
	int offset = param->offset;
	char lbuf[11] = { };
	u32 var;
	int ret;

	if (count > sizeof(lbuf))
		return -EINVAL;

	if (copy_from_user(lbuf, buf, count))
		return -EFAULT;

	lbuf[sizeof(lbuf) - 1] = '\0';

	if (kstrtou32(lbuf, 0, &var))
		return -EINVAL;

	ret = mlx5_ib_set_cc_params(param->dev, param->port_num, offset, var);
	return ret ? ret : count;
}
示例#22
0
/*
 * idt_dbgfs_csr_write() - CSR debugfs-node write callback
 * @filep:	Pointer to the file system file descriptor
 * @buf:	Buffer to read data from
 * @count:	Size of the buffer
 * @offp:	Offset within the file
 *
 * It accepts either "0x<reg addr>:0x<value>" for saving register address
 * and writing value to specified DWORD register or "0x<reg addr>" for
 * just saving register address in order to perform next read operation.
 *
 * WARNING No spaces are allowed. Incoming string must be strictly formated as:
 * "<reg addr>:<value>". Register address must be aligned within 4 bytes
 * (one DWORD).
 */
static ssize_t idt_dbgfs_csr_write(struct file *filep, const char __user *ubuf,
				   size_t count, loff_t *offp)
{
	struct idt_89hpesx_dev *pdev = filep->private_data;
	char *colon_ch, *csraddr_str, *csrval_str;
	int ret, csraddr_len, csrval_len;
	u32 csraddr, csrval;
	char *buf;

	/* Copy data from User-space */
	buf = kmalloc(count + 1, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

	ret = simple_write_to_buffer(buf, count, offp, ubuf, count);
	if (ret < 0)
		goto free_buf;
	buf[count] = 0;

	/* Find position of colon in the buffer */
	colon_ch = strnchr(buf, count, ':');

	/*
	 * If there is colon passed then new CSR value should be parsed as
	 * well, so allocate buffer for CSR address substring.
	 * If no colon is found, then string must have just one number with
	 * no new CSR value
	 */
	if (colon_ch != NULL) {
		csraddr_len = colon_ch - buf;
		csraddr_str =
			kmalloc(sizeof(char)*(csraddr_len + 1), GFP_KERNEL);
		if (csraddr_str == NULL) {
			ret = -ENOMEM;
			goto free_buf;
		}
		/* Copy the register address to the substring buffer */
		strncpy(csraddr_str, buf, csraddr_len);
		csraddr_str[csraddr_len] = '\0';
		/* Register value must follow the colon */
		csrval_str = colon_ch + 1;
		csrval_len = strnlen(csrval_str, count - csraddr_len);
	} else /* if (str_colon == NULL) */ {
		csraddr_str = (char *)buf; /* Just to shut warning up */
		csraddr_len = strnlen(csraddr_str, count);
		csrval_str = NULL;
		csrval_len = 0;
	}

	/* Convert CSR address to u32 value */
	ret = kstrtou32(csraddr_str, 0, &csraddr);
	if (ret != 0)
		goto free_csraddr_str;

	/* Check whether passed register address is valid */
	if (csraddr > CSR_MAX || !IS_ALIGNED(csraddr, SZ_4)) {
		ret = -EINVAL;
		goto free_csraddr_str;
	}

	/* Shift register address to the right so to have u16 address */
	pdev->csr = (csraddr >> 2);

	/* Parse new CSR value and send it to IDT, if colon has been found */
	if (colon_ch != NULL) {
		ret = kstrtou32(csrval_str, 0, &csrval);
		if (ret != 0)
			goto free_csraddr_str;

		ret = idt_csr_write(pdev, pdev->csr, csrval);
		if (ret != 0)
			goto free_csraddr_str;
	}

	/* Free memory only if colon has been found */
free_csraddr_str:
	if (colon_ch != NULL)
		kfree(csraddr_str);

	/* Free buffer allocated for data retrieved from User-space */
free_buf:
	kfree(buf);

	return (ret != 0 ? ret : count);
}
static ssize_t
mbox_debugfs_write(struct file *filp, const char __user *ubuf,
					size_t cnt, loff_t *ppos)
{
	char debugfs_cmd[128];
	char *_cmd = NULL;
	char *_tmp = NULL;
	char rp_name[24];
	u32 _mbox_index;
	mbox_msg_t msg[8];
	mbox_msg_len_t len;

	if (NULL == ubuf || 0 == cnt) {
		cnt = -EINVAL;
		goto out;
	}

	/*to avoid overflow*/
	if (sizeof(debugfs_cmd)/sizeof(char) < cnt) {
		cnt = -EINVAL;
		goto out;
	}

	if (copy_from_user(debugfs_cmd, ubuf, cnt - 1)) {
		cnt = -EINVAL;
		goto out;
	}

	debugfs_cmd[cnt - 1] = '\0';
	_cmd = debugfs_cmd;
	pr_debug("%s: [cmd: %s[cnt: %d]]\n", MODULE_NAME, debugfs_cmd, (int)cnt);

	if (!strncmp("get ", _cmd, strlen("get "))) {
		_cmd = _cmd + strlen("get ");
		if (mbox_debugfs_mbox_get(_cmd)) {
			cnt = -EINVAL;
			goto out;
		}
	} else if (!strncmp("put ", _cmd, strlen("put "))) {
		_cmd = _cmd + strlen("put ");
		if (!strncmp("mailbox-", _cmd, strlen("mailbox-"))) {
			_cmd = _cmd + strlen("mailbox-");
			if (kstrtou32(_cmd, 10, &_mbox_index)) {
				cnt = -EINVAL;
				goto out;
			} else {
				if (mbox_debugfs_mbox_put(_mbox_index)) {
					cnt = -EINVAL;
					goto out;
				}
			}
		} else {
			cnt = -EINVAL;
			goto out;
		}
	} else if (!strncmp("show", _cmd, strlen("show"))) {
		mbox_debufs_mbox_show();
	} else if (!strncmp("config ", _cmd, strlen("config "))) {
		_cmd = _cmd + strlen("config ");
		if (!strncmp("mailbox-", _cmd, strlen("mailbox-"))) {
			_cmd = _cmd + strlen("mailbox-");
			_tmp = _cmd;
			while ((' ' != *_tmp) && ('\0' != *_tmp))
				_tmp++;
			if ('\0' == *_tmp) {
				cnt = -EINVAL;
				goto out;
			}

			*_tmp = '\0';
			if (kstrtou32(_cmd, 10, &_mbox_index)) {
				cnt = -EINVAL;
				goto out;
			}

			*_tmp = ' ';
			_cmd = _tmp + 1;
			_tmp = _cmd;
			while ((' ' != *_tmp) && ('\0' != *_tmp))
				_tmp++;
			strncpy(rp_name, _cmd, _tmp - _cmd);
			rp_name[_tmp - _cmd] = '\0';

			if (mbox_debugfs_mbox_config(_mbox_index, rp_name)) {
				cnt = -EINVAL;
				goto out;
			}
		} else {
			cnt = -EINVAL;
			goto out;
		}
	} else if (!strncmp("send ", _cmd, strlen("send "))) {
		_cmd = _cmd + strlen("send ");
		if (!strncmp("mailbox-", _cmd, strlen("mailbox-"))) {
			_cmd = _cmd + strlen("mailbox-");
			_tmp = _cmd;
			while ((' ' != *_tmp) && ('\0' != *_tmp))
				_tmp++;
			if ('\0' == *_tmp) {
				cnt = -EINVAL;
				goto out;
			}
			*_tmp = '\0';
			if (kstrtou32(_cmd, 10, &_mbox_index)) {
				cnt = -EINVAL;
				goto out;
			}
			*_tmp = ' ';
			_cmd = _tmp + 1;

			len = mbox_debugfs_msg_get(_cmd, msg);
			if (len < 0) {
				cnt = -EINVAL;
				goto out;
			}

			if (mbox_debugfs_msg_send(_mbox_index, msg, len)) {
				cnt = -EINVAL;
				goto out;
			}
		} else {
			cnt = -EINVAL;
			goto out;
		}
	} else if (!strncmp("set times ", _cmd, strlen("set times "))) {
		_cmd = _cmd + strlen("set times ");
		_tmp = _cmd;
		while ((' ' != *_tmp) && ('\0' != *_tmp))
				_tmp++;
		*_tmp = '\0';
		if (kstrtos32(_cmd, 10, &debugfs_ipc_times)) {
			cnt = -EINVAL;
			goto out;
		}

		pr_info("set ipc times %d\n", debugfs_ipc_times);
	} else {
		cnt = -EINVAL;
		goto out;
	}

out:
	return cnt;
}
static ssize_t
irqaff_debugfs_write(struct file *filp, const char __user *ubuf,
					size_t cnt, loff_t *ppos)
{
	char debugfs_cmd[128];
	char *_cmd = NULL;
	char *_tmp = NULL;
	unsigned int irq;
	unsigned int cpu;

	if (copy_from_user(debugfs_cmd, ubuf, cnt - 1)) {
		cnt = -EINVAL;
		goto out;
	}

	debugfs_cmd[cnt - 1] = '\0';
	_cmd = debugfs_cmd;
	pr_debug("%s: [cmd: %s[cnt: %d]]\n", MODULE_NAME, debugfs_cmd, cnt);

	if (!strncmp("register ", _cmd, strlen("register "))) {
		_cmd = _cmd + strlen("register ");
		_tmp = _cmd;
		while ((' ' != *_tmp) && ('\0' != *_tmp))
			_tmp++;
		if ('\0' == *_tmp) {
			cnt = -EINVAL;
			goto out;
		}

		*_tmp = '\0';
		if (kstrtou32(_cmd, 10, &irq)) {
			cnt = -EINVAL;
			goto out;
		}

		*_tmp = ' ';
		_cmd = _tmp + 1;
		_tmp = _cmd;
		while ((' ' != *_tmp) && ('\0' != *_tmp))
			_tmp++;

		*_tmp = '\0';
		if (kstrtou32(_cmd, 10, &cpu)) {
			cnt = -EINVAL;
			goto out;
		}

		hisi_irqaffinity_register(irq, cpu);
	} else if (!strncmp("unregister ", _cmd, strlen("unregister "))) {
		_cmd = _cmd + strlen("unregister ");
		_tmp = _cmd;
		while ((' ' != *_tmp) && ('\0' != *_tmp))
			_tmp++;

		*_tmp = '\0';
		if (kstrtou32(_cmd, 10, &irq)) {
			cnt = -EINVAL;
			goto out;
		}

		hisi_irqaffinity_unregister(irq);
	} else {
		cnt = -EINVAL;
		goto out;
	}

out:
	return cnt;
}
示例#25
0
文件: slcan.c 项目: AK101111/linux
/* Send one completely decapsulated can_frame to the network layer */
static void slc_bump(struct slcan *sl)
{
	struct sk_buff *skb;
	struct can_frame cf;
	int i, tmp;
	u32 tmpid;
	char *cmd = sl->rbuff;

	cf.can_id = 0;

	switch (*cmd) {
	case 'r':
		cf.can_id = CAN_RTR_FLAG;
		/* fallthrough */
	case 't':
		/* store dlc ASCII value and terminate SFF CAN ID string */
		cf.can_dlc = sl->rbuff[SLC_CMD_LEN + SLC_SFF_ID_LEN];
		sl->rbuff[SLC_CMD_LEN + SLC_SFF_ID_LEN] = 0;
		/* point to payload data behind the dlc */
		cmd += SLC_CMD_LEN + SLC_SFF_ID_LEN + 1;
		break;
	case 'R':
		cf.can_id = CAN_RTR_FLAG;
		/* fallthrough */
	case 'T':
		cf.can_id |= CAN_EFF_FLAG;
		/* store dlc ASCII value and terminate EFF CAN ID string */
		cf.can_dlc = sl->rbuff[SLC_CMD_LEN + SLC_EFF_ID_LEN];
		sl->rbuff[SLC_CMD_LEN + SLC_EFF_ID_LEN] = 0;
		/* point to payload data behind the dlc */
		cmd += SLC_CMD_LEN + SLC_EFF_ID_LEN + 1;
		break;
	default:
		return;
	}

	if (kstrtou32(sl->rbuff + SLC_CMD_LEN, 16, &tmpid))
		return;

	cf.can_id |= tmpid;

	/* get can_dlc from sanitized ASCII value */
	if (cf.can_dlc >= '0' && cf.can_dlc < '9')
		cf.can_dlc -= '0';
	else
		return;

	*(u64 *) (&cf.data) = 0; /* clear payload */

	/* RTR frames may have a dlc > 0 but they never have any data bytes */
	if (!(cf.can_id & CAN_RTR_FLAG)) {
		for (i = 0; i < cf.can_dlc; i++) {
			tmp = hex_to_bin(*cmd++);
			if (tmp < 0)
				return;
			cf.data[i] = (tmp << 4);
			tmp = hex_to_bin(*cmd++);
			if (tmp < 0)
				return;
			cf.data[i] |= tmp;
		}
	}

	skb = dev_alloc_skb(sizeof(struct can_frame) +
			    sizeof(struct can_skb_priv));
	if (!skb)
		return;

	skb->dev = sl->dev;
	skb->protocol = htons(ETH_P_CAN);
	skb->pkt_type = PACKET_BROADCAST;
	skb->ip_summed = CHECKSUM_UNNECESSARY;

	can_skb_reserve(skb);
	can_skb_prv(skb)->ifindex = sl->dev->ifindex;
	can_skb_prv(skb)->skbcnt = 0;

	memcpy(skb_put(skb, sizeof(struct can_frame)),
	       &cf, sizeof(struct can_frame));

	sl->dev->stats.rx_packets++;
	sl->dev->stats.rx_bytes += cf.can_dlc;
	netif_rx_ni(skb);
}
static ssize_t stage1_store(struct kobject *kobj, struct kobj_attribute *attr,
			    const char *buf, size_t count)
{
	char cur_name[DEVNAME_SIZE] = "";
	int test_len, cur_len;
	int i, j;
	int id;
	int select;
	struct msdc_host *host;
	int ret;
	/* char *p_log; */
	/* id = 3; */
	select = -1;
	/* sscanf(kobj->name, "%d", &id); */
	kstrtoint(kobj->name, 0, &id);

	if (id >= HOST_MAX_NUM) {
		pr_err("[%s] id<%d> is bigger than HOST_MAX_NUM<%d>\n", __func__, id, HOST_MAX_NUM);
		return count;
	}

	host = mtk_msdc_host[id];
	/* sscanf(attr->attr.name, "%s", cur_name); */
	strncpy(cur_name, attr->attr.name, DEVNAME_SIZE);

	for (i = 0; i < TOTAL_STAGE1_NODE_COUNT; i++) {
		test_len = strlen(stage1_nodes[i]);
		cur_len = strlen(cur_name);
		if ((test_len == cur_len) && (strncmp(stage1_nodes[i], cur_name, cur_len) == 0)) {
			select = i;
			break;
		}
	}

	switch (select) {
	case VOLTAGE:
		/* sscanf(buf, "%u", &cur_voltage[id]); */
		kstrtou32(buf, 0, &cur_voltage[id]);
		break;
	case PARAMS:
		memset(cur_name, 0, DEVNAME_SIZE);
		cur_name[0] = 1;
		cur_name[1] = E_AUTOK_PARM_MAX;
		memcpy(&cur_name[2], &cur_voltage[id], sizeof(unsigned int));
		store_autok(&p_single_autok[id], cur_name, count);

		pr_debug("[AUTOKD] Enter Store Autok");
		pr_debug("[AUTOKD] p_single_autok[%d].vol_count=%d", id,
		       p_single_autok[id].vol_count);
		pr_debug("[AUTOKD] p_single_autok[%d].param_count=%d", id,
		       p_single_autok[id].param_count);
		for (i = 0; i < p_single_autok[id].vol_count; i++) {
			pr_debug("[AUTOKD] p_single_autok[%d].vol_list[%d]=%d", id, i,
			       p_single_autok[id].vol_list[i]);
		}
		for (i = 0; i < p_single_autok[id].vol_count; i++) {
			for (j = 0; j < p_single_autok[id].param_count; j++)
				pr_debug("[AUTOKD] p_single_autok[%d].ai_data[%d][%d]=%d", id, i, j,
				       p_single_autok[id].ai_data[i][j].data.sel);
		}
		/* [FIXDONE] Start to do autok alforithm; data is in p_single_autok */
#ifdef UT_TEST
#error "remove me"
		if (is_first_stage1 == 1) {
			/* claim host */
#ifdef CONFIG_SDIOAUTOK_SUPPORT
			/* mt_cpufreq_disable(0, true); */
			/* FIXME@CCJ mt_vcore_dvfs_disable_by_sdio(0, true); */
#endif
#ifdef MTK_SDIO30_ONLINE_TUNING_SUPPORT
			atomic_set(&host->ot_work.ot_disable, 1);
#endif				/* MTK_SDIO30_ONLINE_TUNING_SUPPORT */
			autok_claim_host(host);

			is_first_stage1 = 0;
		}
#endif
#ifdef AUTOK_THREAD
		p_autok_thread_data->host = host;
		p_autok_thread_data->stage = 1;
		p_autok_thread_data->p_autok_predata = &p_single_autok[id];
		p_autok_thread_data->log = autok_log_info;
		task = kthread_run(&autok_thread_func, (void *)(p_autok_thread_data), "autokp");
#endif
		break;
	case DONE:
		/* sscanf(buf, "%d", &i); */
		kstrtoint(buf, 0, &i);
		p_autok_thread_data->is_autok_done[id] = (u8) i;
		break;
	case LOG:
		/* sscanf(buf, "%d", &i); */
		kstrtoint(buf, 0, &i);
		if (is_full_log != i) {
			is_full_log = i;
			if (i == 0) {
				debugfs_remove(autok_log_entry);
				/* kfree(autok_log_info); */
			} else {
				autok_log_entry =
				    debugfs_create_file("autok_log", 0660, NULL, NULL,
							&autok_log_fops);
				i_gid_write(autok_log_entry->d_inode, 1000);
				autok_log_info = kzalloc(LOG_SIZE, GFP_KERNEL);
				total_msg_size = 0;	/* rewind the counter to 0 when allocate new buffer */
			}
		}
		break;
	default:
		break;
	}
	return count;
}