コード例 #1
0
static ssize_t char_write(struct file* file, const char __user *buf,
                          size_t count, loff_t *ppos)
{
    ssize_t num_wr;
    printk( KERN_INFO "char_test, called char_write");

    memset( payload, 0, SIZE);

    if( count > (SIZE-1) )
      num_wr = simple_write_to_buffer(payload, SIZE-1, ppos, buf, count);
    else
      num_wr = simple_write_to_buffer(payload, strlen(buf), ppos, buf, count);
    
    return num_wr;
}
コード例 #2
0
ファイル: user.c プロジェクト: LorDClockaN/htc_spade_2.6.35
static ssize_t snapshot_write(struct file *filp, const char __user *buf,
                              size_t count, loff_t *offp)
{
	struct snapshot_data *data;
	ssize_t res;
	loff_t pg_offp = *offp & ~PAGE_MASK;

	mutex_lock(&pm_mutex);

	data = filp->private_data;

	if (!pg_offp) {
		res = snapshot_write_next(&data->handle);
		if (res <= 0)
			goto unlock;
	} else {
		res = PAGE_SIZE - pg_offp;
	}

	res = simple_write_to_buffer(data_of(data->handle), res, &pg_offp,
			buf, count);
	if (res > 0)
		*offp += res;
unlock:
	mutex_unlock(&pm_mutex);

	return res;
}
コード例 #3
0
ファイル: xgbe-debugfs.c プロジェクト: AlexShiLucky/linux
static ssize_t xgbe_common_write(const char __user *buffer, size_t count,
				 loff_t *ppos, unsigned int *value)
{
	char workarea[32];
	ssize_t len;
	int ret;

	if (*ppos != 0)
		return -EINVAL;

	if (count >= sizeof(workarea))
		return -ENOSPC;

	len = simple_write_to_buffer(workarea, sizeof(workarea) - 1, ppos,
				     buffer, count);
	if (len < 0)
		return len;

	workarea[len] = '\0';
	ret = kstrtouint(workarea, 16, value);
	if (ret)
		return -EIO;

	return len;
}
コード例 #4
0
ファイル: s2mps13.c プロジェクト: qkdang/m462
static ssize_t data_write(struct file *file, const char __user *data, size_t count, loff_t *ppos)
{
	ssize_t size;
	struct regulator_dev *rdev = file->private_data;
	struct s2mps13_info *info = rdev_get_drvdata(rdev);
	int reg_id = rdev_get_id(rdev);
	char buffer[9];

	size = simple_write_to_buffer(buffer, ARRAY_SIZE(buffer), ppos, data, count);

	if (size > 0) {
		if (strncasecmp("OFF", buffer, sizeof("OFF") - 1) == 0) {
			info->opmode[reg_id] = SEC_OPMODE_OFF << S2MPS13_ENABLE_SHIFT;
		} else if (strncasecmp("SUSPEND", buffer, sizeof("SUSPEND") - 1) == 0) {
			info->opmode[reg_id] = SEC_OPMODE_SUSPEND << S2MPS13_ENABLE_SHIFT;
		} else if (strncasecmp("LOWPOWER", buffer, sizeof("LOWPOWER") - 1) == 0) {
			info->opmode[reg_id] = SEC_OPMODE_LOWPOWER << S2MPS13_ENABLE_SHIFT;
		} else if (strncasecmp("ON", buffer, sizeof("ON") - 1) == 0) {
			info->opmode[reg_id] = SEC_OPMODE_ON << S2MPS13_ENABLE_SHIFT;
		} else {
			buffer[ARRAY_SIZE(buffer) - 1] = '\0';
			pr_err("%s is not recognizable.\n", buffer);
		}
	}

	s2m_enable(rdev);

	pr_debug("%s: size=%zd\n", __func__, size);
	return size;
}
コード例 #5
0
static ssize_t data_write_normalmode(struct file *file, const char __user *data, size_t count, loff_t *ppos)
{
	ssize_t size = 0;
	char buffer[8];
	int* gpio = file->private_data;
	size = simple_write_to_buffer(buffer, ARRAY_SIZE(buffer), ppos, data, count);

	if(size > 0) {
		if(strncasecmp("ON",buffer,sizeof("ON")-1) == 0) {
			if (gpio_request(*gpio, "LED_CONTROL")) {
				pr_err("%s : GPIO_LED request port error\n", __func__);
			} else {
				gpio_direction_output(*gpio, 1);
				gpio_free(*gpio);
			}
		} else if (strncasecmp("OFF",buffer,sizeof("OFF")-1) == 0) {
			if (gpio_request(*gpio, "LED_CONTROL")) {
				pr_err("%s : GPIO_LED request port error\n", __func__);
			} else {
				gpio_direction_output(*gpio, 0);
				gpio_free(*gpio);
			}
		}
	}

	return size;
}
コード例 #6
0
static ssize_t data_write_sleepmode(struct file *file, const char __user *data, size_t count, loff_t *ppos)
{
	ssize_t size = 0;
	char buffer[8];
	int* gpio = file->private_data;
	size = simple_write_to_buffer(buffer, ARRAY_SIZE(buffer), ppos, data, count);

	printk("Led : because of sleep current, S5430 turn off LED\n");
	if(size > 0) {
		if(strncasecmp("ON",buffer,sizeof("ON")-1) == 0) {
			if (gpio_request(*gpio, "LED_CONTROL")) {
				pr_err("%s : GPIO_LED request port error\n", __func__);
			} else {
				gpio_free(*gpio);
			}
		} else if (strncasecmp("OFF",buffer,sizeof("OFF")-1) == 0) {
			if (gpio_request(*gpio, "LED_CONTROL")) {
				pr_err("%s : GPIO_LED request port error\n", __func__);
			} else {
				gpio_free(*gpio);
			}
		}
	}

	return size;
}
コード例 #7
0
ファイル: debugfs.c プロジェクト: lumag/linux
/* Write WMI command (w/o mbox header) to this file to send it
 * WMI starts from wil6210_mbox_hdr_wmi header
 */
static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
				  size_t len, loff_t *ppos)
{
	struct wil6210_priv *wil = file->private_data;
	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
	struct wmi_cmd_hdr *wmi;
	void *cmd;
	int cmdlen = len - sizeof(struct wmi_cmd_hdr);
	u16 cmdid;
	int rc, rc1;

	if (cmdlen < 0)
		return -EINVAL;

	wmi = kmalloc(len, GFP_KERNEL);
	if (!wmi)
		return -ENOMEM;

	rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
	if (rc < 0) {
		kfree(wmi);
		return rc;
	}

	cmd = (cmdlen > 0) ? &wmi[1] : NULL;
	cmdid = le16_to_cpu(wmi->command_id);

	rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
	kfree(wmi);

	wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);

	return rc;
}
コード例 #8
0
static ssize_t hifi_debug_level_store(struct file *file, const char __user *buf,
		size_t size, loff_t *data)
{
	ssize_t ret = 0;
	char level_str[MAX_LEVEL_STR_LEN] = {0};
	loff_t pos = 0;

	if (NULL == buf) {
		loge("Input param buf is invalid\n");
		return -EINVAL;
	}
	ret = simple_write_to_buffer(level_str, MAX_LEVEL_STR_LEN - 1 , &pos, buf, size);
	if (ret != size) {
		loge("Input param buf read error, return value: %zd\n", ret);
		return -EINVAL;
	}

	if (!strchr("diwe", level_str[0])) {
		loge("Input param buf is error(valid: d,i,w,e): %s.\n", level_str);
		return -EINVAL;
	}
	if (level_str[1] != '\n') {
		loge("Input param buf is error, last char is not \\n .\n");
		return -EINVAL;
	}

	g_om_data.debug_level = hifi_get_debug_level_num(level_str[0]);
	return size;
}
コード例 #9
0
static ssize_t upgrade_proc_write(struct file *file, const char __user *buf, 
            size_t count, loff_t *ppos)
{
    struct partition_package *package;
    int err;
    size_t size;
    //int len;

    package = kzalloc(count, GFP_KERNEL);
    if (!package) {
        err = -ENOMEM;
        part_err("upgrade_proc_write: fail to malloc package\n");
        goto fail_malloc;
    }

    size = simple_write_to_buffer(package, sizeof(*package), ppos, buf, count);
    if (size < 0) {
        err = size;
        part_err("upgrade_proc_write: fail to receive data(%zu)\n", size);
        goto out;
    }

    err = upgrade_handler(package, size);
    
out:
    kfree(package);
fail_malloc:
    if (err)
        return err;
    else
        return count;
}
コード例 #10
0
ファイル: debugfs.c プロジェクト: 3null/linux
/* Write WMI command (w/o mbox header) to this file to send it
 * WMI starts from wil6210_mbox_hdr_wmi header
 */
static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
				  size_t len, loff_t *ppos)
{
	struct wil6210_priv *wil = file->private_data;
	struct wil6210_mbox_hdr_wmi *wmi;
	void *cmd;
	int cmdlen = len - sizeof(struct wil6210_mbox_hdr_wmi);
	u16 cmdid;
	int rc, rc1;

	if (cmdlen <= 0)
		return -EINVAL;

	wmi = kmalloc(len, GFP_KERNEL);
	if (!wmi)
		return -ENOMEM;

	rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
	if (rc < 0)
		return rc;

	cmd = &wmi[1];
	cmdid = le16_to_cpu(wmi->id);

	rc1 = wmi_send(wil, cmdid, cmd, cmdlen);
	kfree(wmi);

	wil_info(wil, "%s(0x%04x[%d]) -> %d\n", __func__, cmdid, cmdlen, rc1);

	return rc;
}
コード例 #11
0
ファイル: debug.c プロジェクト: AkyZero/wrapfs-latest
static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
						const char __user *user_buf,
						size_t count, loff_t *ppos)
{
	struct ath10k *ar = file->private_data;
	int res;
	char buf[64];
	unsigned int amsdu, ampdu;

	simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);

	/* make sure that buf is null terminated */
	buf[sizeof(buf) - 1] = 0;

	res = sscanf(buf, "%u %u", &amsdu, &ampdu);

	if (res != 2)
		return -EINVAL;

	mutex_lock(&ar->conf_mutex);

	res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
	if (res)
		goto out;

	res = count;
	ar->debug.htt_max_amsdu = amsdu;
	ar->debug.htt_max_ampdu = ampdu;

out:
	mutex_unlock(&ar->conf_mutex);
	return res;
}
コード例 #12
0
ファイル: debugfs.c プロジェクト: twdow/tempesta
static ssize_t
fop_write(struct file *file, const char __user *user_buf,
	  size_t count,
	  loff_t *ppos)
{
	int len;
	TfwDebugfsIoState *state = file->private_data;

	if (!state->is_input) {
		TFW_ERR("Can't write to this debugfs file: "
			"it was open()'ed only for reading\n");
		return -EPERM;
	}

	/* copy data from user-space */
	len = simple_write_to_buffer(state->buf, (state->buf_size - 1),
				     ppos,
				     user_buf, count);
	if (len > 0) {
		state->len += len;
		state->buf[state->len] = '\0';
	}

	return len;
}
コード例 #13
0
ファイル: xenbus.c プロジェクト: gxt/linux
static ssize_t
xenvif_write_io_ring(struct file *filp, const char __user *buf, size_t count,
		     loff_t *ppos)
{
	struct xenvif_queue *queue =
		((struct seq_file *)filp->private_data)->private;
	int len;
	char write[BUFFER_SIZE];

	/* don't allow partial writes and check the length */
	if (*ppos != 0)
		return 0;
	if (count >= sizeof(write))
		return -ENOSPC;

	len = simple_write_to_buffer(write,
				     sizeof(write) - 1,
				     ppos,
				     buf,
				     count);
	if (len < 0)
		return len;

	write[len] = '\0';

	if (!strncmp(write, XENVIF_KICK_STR, sizeof(XENVIF_KICK_STR) - 1))
		xenvif_interrupt(0, (void *)queue);
	else {
		pr_warn("Unknown command to io_ring_q%d. Available: kick\n",
			queue->id);
		count = -EINVAL;
	}
	return count;
}
コード例 #14
0
static ssize_t baseline_debugfs_write(struct file *filp,
		const char __user *buf, size_t count, loff_t *ppos)
{
	struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
	struct cyttsp5_device_access_data *dad = data->dad;
	ssize_t length;
	int rc = 0;

	rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
			buf, count);
	if (rc < 0)
		return rc;

	count = rc;

	mutex_lock(&dad->sysfs_lock);

	length = cyttsp5_ic_parse_input(dad->dev, buf, count, dad->ic_buf,
			CY_MAX_PRBUF_SIZE);
	if (length != 1) {
		dev_err(dad->dev, "%s: Malformed input\n", __func__);
		rc = -EINVAL;
		goto exit_unlock;
	}

	dad->baseline_sensing_mode = dad->ic_buf[0];

exit_unlock:
	mutex_unlock(&dad->sysfs_lock);

	if (rc)
		return rc;

	return count;
}
コード例 #15
0
static ssize_t tee_write_file_settings_tz(struct file *file,
				       const char __user *user_buf,
				       size_t count, loff_t *ppos)
{
	struct device *dev = file->private_data;
	char *buf;
	char *str;
	int val;

	buf = devm_kzalloc(dev, count, GFP_KERNEL);
	if (!buf) {
		dev_err(dev, "can't allocate work buffer\n");
		return count;
	}

	val = simple_write_to_buffer(buf, count, ppos, user_buf, count);
	if (!val) {
		dev_err(dev, "no user data\n");
		goto out;
	}

	str = strstr(buf, STR_DUMP_ALLOCATOR);
	if (str)
		tee_shm_pool_dump(dev, TZop.Allocator, true);

	str = strstr(buf, STR_CMD_HIST);
	if (str)
		tee_debug_dump_cmd_hist(dev, NULL, 0);

out:
	devm_kfree(dev, buf);
	return count;
}
コード例 #16
0
ファイル: debugfs.c プロジェクト: AICP/kernel_moto_shamu
static ssize_t wil_write_file_ssid(struct file *file, const char __user *buf,
				   size_t count, loff_t *ppos)
{
	struct wil6210_priv *wil = file->private_data;
	struct wireless_dev *wdev = wil_to_wdev(wil);
	struct net_device *ndev = wil_to_ndev(wil);

	if (*ppos != 0) {
		wil_err(wil, "Unable to set SSID substring from [%d]\n",
			(int)*ppos);
		return -EINVAL;
	}

	if (count > sizeof(wdev->ssid)) {
		wil_err(wil, "SSID too long, len = %d\n", (int)count);
		return -EINVAL;
	}
	if (netif_running(ndev)) {
		wil_err(wil, "Unable to change SSID on running interface\n");
		return -EINVAL;
	}

	wdev->ssid_len = count;
	return simple_write_to_buffer(wdev->ssid, wdev->ssid_len, ppos,
				      buf, count);
}
コード例 #17
0
ファイル: exp_debugfs.c プロジェクト: gokul-github/linuxpedia
/* write file operation */
static ssize_t mywriter(struct file *fp, const char __user *user_buffer,
                                size_t count, loff_t *position)
{
        if(count > len )
                return -EINVAL;
 	printk("writing\n"); 
        return simple_write_to_buffer(ker_buf, len, position, user_buffer, count);
}
コード例 #18
0
ファイル: ntb_tool.c プロジェクト: mdamt/linux
static ssize_t tool_peer_mw_write(struct file *filep, const char __user *ubuf,
				  size_t size, loff_t *offp)
{
	struct tool_mw *mw = filep->private_data;

	if (!mw->peer)
		return -ENXIO;

	return simple_write_to_buffer(mw->peer, mw->size, offp, ubuf, size);
}
コード例 #19
0
ファイル: file.c プロジェクト: a2hojsjsjs/linux
static ssize_t
configfs_write_bin_file(struct file *file, const char __user *buf,
			size_t count, loff_t *ppos)
{
	struct configfs_buffer *buffer = file->private_data;
	struct dentry *dentry = file->f_path.dentry;
	struct configfs_bin_attribute *bin_attr = to_bin_attr(dentry);
	void *tbuf = NULL;
	ssize_t len;

	mutex_lock(&buffer->mutex);

	/* we don't support switching read/write modes */
	if (buffer->read_in_progress) {
		len = -ETXTBSY;
		goto out;
	}
	buffer->write_in_progress = 1;

	/* buffer grows? */
	if (*ppos + count > buffer->bin_buffer_size) {

		if (bin_attr->cb_max_size &&
			*ppos + count > bin_attr->cb_max_size) {
			len = -EFBIG;
		}

		tbuf = vmalloc(*ppos + count);
		if (tbuf == NULL) {
			len = -ENOMEM;
			goto out;
		}

		/* copy old contents */
		if (buffer->bin_buffer) {
			memcpy(tbuf, buffer->bin_buffer,
				buffer->bin_buffer_size);
			vfree(buffer->bin_buffer);
		}

		/* clear the new area */
		memset(tbuf + buffer->bin_buffer_size, 0,
			*ppos + count - buffer->bin_buffer_size);
		buffer->bin_buffer = tbuf;
		buffer->bin_buffer_size = *ppos + count;
	}

	len = simple_write_to_buffer(buffer->bin_buffer,
			buffer->bin_buffer_size, ppos, buf, count);
	if (len > 0)
		*ppos += len;
out:
	mutex_unlock(&buffer->mutex);
	return len;
}
コード例 #20
0
ファイル: debugfs.c プロジェクト: acton393/linux
/* block ack control, write:
 * - "add <ringid> <agg_size> <timeout>" to trigger ADDBA
 * - "del_tx <ringid> <reason>" to trigger DELBA for Tx side
 * - "del_rx <CID> <TID> <reason>" to trigger DELBA for Rx side
 */
static ssize_t wil_write_back(struct file *file, const char __user *buf,
			      size_t len, loff_t *ppos)
{
	struct wil6210_priv *wil = file->private_data;
	int rc;
	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
	char cmd[9];
	int p1, p2, p3;

	if (!kbuf)
		return -ENOMEM;

	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
	if (rc != len) {
		kfree(kbuf);
		return rc >= 0 ? -EIO : rc;
	}

	kbuf[len] = '\0';
	rc = sscanf(kbuf, "%8s %d %d %d", cmd, &p1, &p2, &p3);
	kfree(kbuf);

	if (rc < 0)
		return rc;
	if (rc < 2)
		return -EINVAL;

	if (0 == strcmp(cmd, "add")) {
		if (rc < 3) {
			wil_err(wil, "BACK: add require at least 2 params\n");
			return -EINVAL;
		}
		if (rc < 4)
			p3 = 0;
		wmi_addba(wil, p1, p2, p3);
	} else if (0 == strcmp(cmd, "del_tx")) {
		if (rc < 3)
			p2 = WLAN_REASON_QSTA_LEAVE_QBSS;
		wmi_delba_tx(wil, p1, p2);
	} else if (0 == strcmp(cmd, "del_rx")) {
		if (rc < 3) {
			wil_err(wil,
				"BACK: del_rx require at least 2 params\n");
			return -EINVAL;
		}
		if (rc < 4)
			p3 = WLAN_REASON_QSTA_LEAVE_QBSS;
		wmi_delba_rx(wil, mk_cidxtid(p1, p2), p3);
	} else {
		wil_err(wil, "BACK: Unrecognized command \"%s\"\n", cmd);
		return -EINVAL;
	}

	return len;
}
コード例 #21
0
ファイル: qcom-debugfs.c プロジェクト: Menpiko/SnaPKernel-N6P
static ssize_t ufs_qcom_dbg_testbus_cfg_write(struct file *file,
				const char __user *ubuf, size_t cnt,
				loff_t *ppos)
{
	struct ufs_qcom_host *host = file->f_mapping->host->i_private;
	char configuration[TESTBUS_CFG_BUFF_LINE_SIZE] = {0};
	loff_t buff_pos = 0;
	char *comma;
	int ret = 0;
	int major;
	int minor;

	cnt = simple_write_to_buffer(configuration, TESTBUS_CFG_BUFF_LINE_SIZE,
		&buff_pos, ubuf, cnt);
	if (cnt < 0) {
		dev_err(host->hba->dev, "%s: failed to read user data\n",
			__func__);
		goto out;
	}

	comma = strnchr(configuration, TESTBUS_CFG_BUFF_LINE_SIZE, ',');
	if (!comma || comma == configuration) {
		dev_err(host->hba->dev,
			"%s: error in configuration of testbus\n", __func__);
		ret = -EINVAL;
		goto out;
	}

	if (sscanf(configuration, "%i,%i", &major, &minor) != 2) {
		dev_err(host->hba->dev,
			"%s: couldn't parse input to 2 numeric values\n",
			__func__);
		ret = -EINVAL;
		goto out;
	}

	host->testbus.select_major = (u8)major;
	host->testbus.select_minor = (u8)minor;

	/*
	 * Sanity check of the {major, minor} tuple is done in the
	 * config function
	 */
	ret = ufs_qcom_testbus_config(host);
	if (!ret)
		dev_dbg(host->hba->dev,
				"%s: New configuration: major=%d, minor=%d\n",
				__func__, host->testbus.select_major,
				host->testbus.select_minor);

out:
	return ret ? ret : cnt;
}
コード例 #22
0
/**
 * ixgbe_dbg_reg_ops_write - write into reg_ops datum
 * @filp: the opened file
 * @buffer: where to find the user's data
 * @count: the length of the user's data
 * @ppos: file position offset
 **/
static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp,
				     const char __user *buffer,
				     size_t count, loff_t *ppos)
{
	struct ixgbe_adapter *adapter = filp->private_data;
	int len;

	/* don't allow partial writes */
	if (*ppos != 0)
		return 0;
	if (count >= sizeof(ixgbe_dbg_reg_ops_buf))
		return -ENOSPC;

	len = simple_write_to_buffer(ixgbe_dbg_reg_ops_buf,
				     sizeof(ixgbe_dbg_reg_ops_buf)-1,
				     ppos,
				     buffer,
				     count);
	if (len < 0)
		return len;

	ixgbe_dbg_reg_ops_buf[len] = '\0';

	if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) {
		u32 reg, value;
		int cnt;
		cnt = sscanf(&ixgbe_dbg_reg_ops_buf[5], "%x %x", &reg, &value);
		if (cnt == 2) {
			IXGBE_WRITE_REG(&adapter->hw, reg, value);
			value = IXGBE_READ_REG(&adapter->hw, reg);
			e_dev_info("write: 0x%08x = 0x%08x\n", reg, value);
		} else {
			e_dev_info("write <reg> <value>\n");
		}
	} else if (strncmp(ixgbe_dbg_reg_ops_buf, "read", 4) == 0) {
		u32 reg, value;
		int cnt;
		cnt = sscanf(&ixgbe_dbg_reg_ops_buf[4], "%x", &reg);
		if (cnt == 1) {
			value = IXGBE_READ_REG(&adapter->hw, reg);
			e_dev_info("read 0x%08x = 0x%08x\n", reg, value);
		} else {
			e_dev_info("read <reg>\n");
		}
	} else {
		e_dev_info("Unknown command %s\n", ixgbe_dbg_reg_ops_buf);
		e_dev_info("Available commands:\n");
		e_dev_info("   read <reg>\n");
		e_dev_info("   write <reg> <value>\n");
	}
	return count;
}
コード例 #23
0
ファイル: pb173.c プロジェクト: jirislaby/pb173
static ssize_t my_write(struct file *filp, const char __user *buf, size_t count,
		loff_t *off)
{
	ssize_t ret;

	mutex_lock(&my_lock);
	ret = simple_write_to_buffer(str, sizeof str - 1, off, buf, count);
	if (ret >= 0)
		str[sizeof str - 1] = 0;
	mutex_unlock(&my_lock);

	return ret;
}
コード例 #24
0
ファイル: olpc.c プロジェクト: 0xroot/Blackphone-BP1-Kernel
static ssize_t ec_debugfs_cmd_write(struct file *file, const char __user *buf,
				    size_t size, loff_t *ppos)
{
	int i, m;
	unsigned char ec_cmd[EC_MAX_CMD_ARGS];
	unsigned int ec_cmd_int[EC_MAX_CMD_ARGS];
	char cmdbuf[64];
	int ec_cmd_bytes;

	mutex_lock(&ec_debugfs_cmd_lock);

	size = simple_write_to_buffer(cmdbuf, sizeof(cmdbuf), ppos, buf, size);

	m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0],
		   &ec_debugfs_resp_bytes,
		   &ec_cmd_int[1], &ec_cmd_int[2], &ec_cmd_int[3],
		   &ec_cmd_int[4], &ec_cmd_int[5]);
	if (m < 2 || ec_debugfs_resp_bytes > EC_MAX_CMD_REPLY) {
		/* reset to prevent overflow on read */
		ec_debugfs_resp_bytes = 0;

		printk(KERN_DEBUG "olpc-ec: bad ec cmd:  "
		       "cmd:response-count [arg1 [arg2 ...]]\n");
		size = -EINVAL;
		goto out;
	}

	/* convert scanf'd ints to char */
	ec_cmd_bytes = m - 2;
	for (i = 0; i <= ec_cmd_bytes; i++)
		ec_cmd[i] = ec_cmd_int[i];

	printk(KERN_DEBUG "olpc-ec: debugfs cmd 0x%02x with %d args "
	       "%02x %02x %02x %02x %02x, want %d returns\n",
	       ec_cmd[0], ec_cmd_bytes, ec_cmd[1], ec_cmd[2], ec_cmd[3],
	       ec_cmd[4], ec_cmd[5], ec_debugfs_resp_bytes);

	olpc_ec_cmd(ec_cmd[0], (ec_cmd_bytes == 0) ? NULL : &ec_cmd[1],
		    ec_cmd_bytes, ec_debugfs_resp, ec_debugfs_resp_bytes);

	printk(KERN_DEBUG "olpc-ec: response "
	       "%02x %02x %02x %02x %02x %02x %02x %02x (%d bytes expected)\n",
	       ec_debugfs_resp[0], ec_debugfs_resp[1], ec_debugfs_resp[2],
	       ec_debugfs_resp[3], ec_debugfs_resp[4], ec_debugfs_resp[5],
	       ec_debugfs_resp[6], ec_debugfs_resp[7], ec_debugfs_resp_bytes);

out:
	mutex_unlock(&ec_debugfs_cmd_lock);
	return size;
}
コード例 #25
0
ファイル: debug.c プロジェクト: AkyZero/wrapfs-latest
/* Simulate firmware crash:
 * 'soft': Call wmi command causing firmware hang. This firmware hang is
 * recoverable by warm firmware reset.
 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
 * vdev id. This is hard firmware crash because it is recoverable only by cold
 * firmware reset.
 */
static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
					      const char __user *user_buf,
					      size_t count, loff_t *ppos)
{
	struct ath10k *ar = file->private_data;
	char buf[32];
	int ret;

	mutex_lock(&ar->conf_mutex);

	simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);

	/* make sure that buf is null terminated */
	buf[sizeof(buf) - 1] = 0;

	if (ar->state != ATH10K_STATE_ON &&
	    ar->state != ATH10K_STATE_RESTARTED) {
		ret = -ENETDOWN;
		goto exit;
	}

	/* drop the possible '\n' from the end */
	if (buf[count - 1] == '\n') {
		buf[count - 1] = 0;
		count--;
	}

	if (!strcmp(buf, "soft")) {
		ath10k_info("simulating soft firmware crash\n");
		ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
	} else if (!strcmp(buf, "hard")) {
		ath10k_info("simulating hard firmware crash\n");
		ret = ath10k_wmi_vdev_set_param(ar, TARGET_NUM_VDEVS + 1,
					ar->wmi.vdev_param->rts_threshold, 0);
	} else {
		ret = -EINVAL;
		goto exit;
	}

	if (ret) {
		ath10k_warn("failed to simulate firmware crash: %d\n", ret);
		goto exit;
	}

	ret = count;

exit:
	mutex_unlock(&ar->conf_mutex);
	return ret;
}
コード例 #26
0
ファイル: debugfs.c プロジェクト: lumag/linux
/* pmc control, write:
 * - "alloc <num descriptors> <descriptor_size>" to allocate PMC
 * - "free" to release memory allocated for PMC
 */
static ssize_t wil_write_pmccfg(struct file *file, const char __user *buf,
				size_t len, loff_t *ppos)
{
	struct wil6210_priv *wil = file->private_data;
	int rc;
	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
	char cmd[9];
	int num_descs, desc_size;

	if (!kbuf)
		return -ENOMEM;

	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
	if (rc != len) {
		kfree(kbuf);
		return rc >= 0 ? -EIO : rc;
	}

	kbuf[len] = '\0';
	rc = sscanf(kbuf, "%8s %d %d", cmd, &num_descs, &desc_size);
	kfree(kbuf);

	if (rc < 0)
		return rc;

	if (rc < 1) {
		wil_err(wil, "pmccfg: no params given\n");
		return -EINVAL;
	}

	if (0 == strcmp(cmd, "alloc")) {
		if (rc != 3) {
			wil_err(wil, "pmccfg: alloc requires 2 params\n");
			return -EINVAL;
		}
		wil_pmc_alloc(wil, num_descs, desc_size);
	} else if (0 == strcmp(cmd, "free")) {
		if (rc != 1) {
			wil_err(wil, "pmccfg: free does not have any params\n");
			return -EINVAL;
		}
		wil_pmc_free(wil, true);
	} else {
		wil_err(wil, "pmccfg: Unrecognized command \"%s\"\n", cmd);
		return -EINVAL;
	}

	return len;
}
コード例 #27
0
ファイル: helloworld.c プロジェクト: RenaultR42/misc
static ssize_t debug_id_writer(struct file *fp, const char __user *buf,
			size_t len, loff_t *ppos)
{
	char tmp[BUFFER_SIZE];
	int size = strlen(EUDYPTULA_ID);

	if (len >= BUFFER_SIZE)
		return -EINVAL;

	if (simple_write_to_buffer(tmp, size, ppos, buf, len) < size)
		return -EINVAL;

	tmp[size] = '\0';
	return strncmp(tmp, EUDYPTULA_ID, size) ? -EINVAL : size;
}
コード例 #28
0
ファイル: helloworld.c プロジェクト: RenaultR42/misc
static ssize_t debug_foo_writer(struct file *fp, const char __user *buf,
			size_t len, loff_t *ppos)
{
	int ret;
	mutex_lock(&debug_foo_mutex);

	if (len >= BUFFER_SIZE)
		return -EINVAL;

	ret = simple_write_to_buffer(foo_value, PAGE_SIZE - 1, ppos, buf, len);

	foo_value[ret] = '\0';
	mutex_unlock(&debug_foo_mutex);
	return ret;
}
コード例 #29
0
ファイル: pb173.c プロジェクト: jkasztur/pb173
static ssize_t my_write(struct file *filp, const char __user *buf, size_t count,
		loff_t *off)
{
	ssize_t ret;

	mutex_lock(&my_lock);
	ret = simple_write_to_buffer(str, sizeof(str) - 1, off, buf, count);
	if (!ret)
		str[sizeof(str) - 1] = 0;
	mutex_unlock(&my_lock);
	atomic_inc(&counter);
	wake_up(&my_wait);

	return ret;
}
コード例 #30
0
static ssize_t pixter_dbgfs_write(struct file *file, const char __user *buf, size_t size, loff_t *ppos)
{
	struct pixter_dbgfs_data *data = file->f_inode->i_private;
	struct pixter_device *dev = data->dev;
	u32 *val = (u32*) data->ptr;
	char str[16] = {0};
	ssize_t ret;

	ret =  simple_write_to_buffer(str, 16, ppos, buf, size);
	sscanf(str, "%d", val);
	if (val == &dev->dbg_timing.timing_ovrd && *val == 0)
		pixter_config_tx(&dev->sd);

	return ret;
}