static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; long val; int err; err = kstrtol(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); data->fan_low[nr] = fan_to_reg(val); f71805f_write16(data, F71805F_REG_FAN_LOW(nr), data->fan_low[nr]); mutex_unlock(&data->update_lock); return count; }
static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int index = to_sensor_dev_attr(attr)->index; struct i2c_client *client = to_i2c_client(dev); struct adm1025_data *data = i2c_get_clientdata(client); long val; int err; err = kstrtol(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); data->temp_max[index] = TEMP_TO_REG(val); i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(index), data->temp_max[index]); mutex_unlock(&data->update_lock); return count; }
static ssize_t set_w_member_data(struct device *dev, struct device_attribute \ *dev_attr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); long data; int error; if (attr->index == PSU_SELECT_MEMBER) { error = kstrtol(buf, 16, &data); if (error) return error; if (SELECT_PSU1_EEPROM == data) { psu_member_data = SELECT_PSU1_EEPROM; } else if (SELECT_PSU2_EEPROM == data) { psu_member_data = SELECT_PSU2_EEPROM; } else { return -EINVAL; } } return count; }
static ssize_t set_temp1_crit_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct i2c_client *client = to_i2c_client(dev); struct lm92_data *data = i2c_get_clientdata(client); long val; int err; err = kstrtol(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val; i2c_smbus_write_word_swapped(client, LM92_REG_TEMP_HYST, TEMP_TO_REG(data->temp1_hyst)); mutex_unlock(&data->update_lock); return count; }
static ssize_t ade7854_write_8bit(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; long val; ret = kstrtol(buf, 10, &val); if (ret) goto error_ret; ret = st->write_reg_8(dev, this_attr->address, val); error_ret: return ret ? ret : len; }
static ssize_t nouveau_hwmon_set_pwm1_enable(struct device *d, struct device_attribute *a, const char *buf, size_t count) { struct drm_device *dev = dev_get_drvdata(d); struct nouveau_drm *drm = nouveau_drm(dev); struct nouveau_therm *therm = nouveau_therm(drm->device); long value; int ret; ret = kstrtol(buf, 10, &value); if (ret) return ret; ret = therm->attr_set(therm, NOUVEAU_THERM_ATTR_FAN_MODE, value); if (ret) return ret; else return count; }
/*---write channel 1..4 to rxon for it, 0 to rxoff---*/ static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf, size_t len, loff_t *ppos) { struct wil6210_priv *wil = file->private_data; int rc; long channel; bool on; char *kbuf = kmalloc(len + 1, GFP_KERNEL); if (!kbuf) return -ENOMEM; if (copy_from_user(kbuf, buf, len)) { kfree(kbuf); return -EIO; } kbuf[len] = '\0'; rc = kstrtol(kbuf, 0, &channel); kfree(kbuf); if (rc) return rc; if ((channel < 0) || (channel > 4)) { wil_err(wil, "Invalid channel %ld\n", channel); return -EINVAL; } on = !!channel; if (on) { rc = wmi_set_channel(wil, (int)channel); if (rc) return rc; } rc = wmi_rxon(wil, on); if (rc) return rc; return len; }
static ssize_t l2_all_counter_srcx_write(struct file *filp, const char __user *ubuf, size_t cnt, loff_t *ppos, u32 src_id) { char buf[64]; long val; int ret; u32 l2_id; struct mali_l2_cache_core *l2_cache; if (cnt >= sizeof(buf)) { return -EINVAL; } if (copy_from_user(&buf, ubuf, cnt)) { return -EFAULT; } buf[cnt] = 0; ret = kstrtol(buf, 10, &val); if (ret < 0) { return ret; } if (val < 0) { /* any negative input will disable counter */ val = MALI_HW_CORE_NO_COUNTER; } l2_id = 0; l2_cache = mali_l2_cache_core_get_glob_l2_core(l2_id); while (NULL != l2_cache) { mali_l2_cache_core_set_counter_src(l2_cache, src_id, (u32)val); /* try next L2 */ l2_id++; l2_cache = mali_l2_cache_core_get_glob_l2_core(l2_id); } *ppos += cnt; return cnt; }
ssize_t ide_park_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { #define MAX_PARK_TIMEOUT 30000 ide_drive_t *drive = to_ide_device(dev); long int input; int rc; rc = kstrtol(buf, 10, &input); if (rc) return rc; if (input < -2) return -EINVAL; if (input > MAX_PARK_TIMEOUT) { input = MAX_PARK_TIMEOUT; rc = -EOVERFLOW; } mutex_lock(&ide_setting_mtx); if (input >= 0) { if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD) rc = -EOPNOTSUPP; else if (input || drive->dev_flags & IDE_DFLAG_PARKED) issue_park_cmd(drive, msecs_to_jiffies(input)); } else { if (drive->media == ide_disk) switch (input) { case -1: drive->dev_flags &= ~IDE_DFLAG_NO_UNLOAD; break; case -2: drive->dev_flags |= IDE_DFLAG_NO_UNLOAD; break; } else rc = -EOPNOTSUPP; } mutex_unlock(&ide_setting_mtx); return rc ? rc : len; }
static ssize_t tmp102_set_temp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); struct i2c_client *client = to_i2c_client(dev); struct tmp102 *tmp102 = i2c_get_clientdata(client); long val; int status; if (kstrtol(buf, 10, &val) < 0) return -EINVAL; val = clamp_val(val, -256000, 255000); mutex_lock(&tmp102->lock); tmp102->temp[sda->index] = val; status = i2c_smbus_write_word_swapped(client, tmp102_reg[sda->index], tmp102_mC_to_reg(val)); mutex_unlock(&tmp102->lock); return status ? : count; }
static ssize_t ep93xx_pwm_set_invert(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct platform_device *pdev = to_platform_device(dev); struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); long val; int err; err = kstrtol(buf, 10, &val); if (err) return -EINVAL; if (val == 0) writel(0x0, pwm->mmio_base + EP93XX_PWMx_INVERT); else if (val == 1) writel(0x1, pwm->mmio_base + EP93XX_PWMx_INVERT); else return -EINVAL; return count; }
static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct lm83_data *data = i2c_get_clientdata(client); long val; int nr = attr->index; int err; err = kstrtol(buf, 10, &val); if (err < 0) return err; mutex_lock(&data->update_lock); data->temp[nr] = TEMP_TO_REG(val); i2c_smbus_write_byte_data(client, LM83_REG_W_HIGH[nr - 4], data->temp[nr]); mutex_unlock(&data->update_lock); return count; }
static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); int nr = sensor_attr->index; struct smsc47m192_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; long val; int err; err = kstrtol(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); data->temp_max[nr] = TEMP_TO_REG(val); i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MAX[nr], data->temp_max[nr]); mutex_unlock(&data->update_lock); return count; }
/* * And now the other way around, user-space provides an absolute * hysteresis value and we have to store a relative one */ static ssize_t set_temp2_crit_hyst(struct device *dev, struct device_attribute *dummy, const char *buf, size_t count) { struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = i2c_get_clientdata(client); long val; int err; long hyst; err = kstrtol(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); hyst = temp8_from_reg(data, 2) + data->temp2_offset - val; i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, HYST_TO_REG(hyst)); mutex_unlock(&data->update_lock); return count; }
static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct lm92_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; long val; int err; err = kstrtol(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); data->temp[t_hyst] = TEMP_FROM_REG(data->temp[attr->index]) - val; i2c_smbus_write_word_swapped(client, LM92_REG_TEMP_HYST, TEMP_TO_REG(data->temp[t_hyst])); mutex_unlock(&data->update_lock); return count; }
int main(int argc, char *argv[]) { char *number_str = NULL; long n = 1000; int c, res; /* get args */ while ((c = getopt_long(argc, argv, "n:fvh", long_options, NULL)) != -1) { switch (c) { case 'n': number_str = optarg; break; case 'f': config.f_flag = 1; break; case 'v': case 'h': print_usage_and_die(0); default: print_usage_and_die(1); } } if (argc - optind != 1) print_usage_and_die(1); /* set args */ config.file = argv[optind]; if (number_str && (kstrtol(number_str, 10, &n) || n <= 0)) err("Invalid argument for --number"); config.n = n; /* sanity checks */ if (!is_tailable(config.file)) err("The file '%s' cannot be tailed.", config.file); /* print tail */ res = config.f_flag ? ktail_with_follow() : ktail(); return res ? EXIT_FAILURE : EXIT_SUCCESS; }
unsigned long fbtft_request_gpios_match(struct fbtft_par *par, const struct fbtft_gpio *gpio) { int ret; long val; fbtft_par_dbg(DEBUG_REQUEST_GPIOS_MATCH, par, "%s('%s')\n", __func__, gpio->name); if (strcasecmp(gpio->name, "reset") == 0) { par->gpio.reset = gpio->gpio; return GPIOF_OUT_INIT_HIGH; } else if (strcasecmp(gpio->name, "dc") == 0) { par->gpio.dc = gpio->gpio; return GPIOF_OUT_INIT_LOW; } else if (strcasecmp(gpio->name, "cs") == 0) { par->gpio.cs = gpio->gpio; return GPIOF_OUT_INIT_HIGH; } else if (strcasecmp(gpio->name, "wr") == 0) { par->gpio.wr = gpio->gpio; return GPIOF_OUT_INIT_HIGH; } else if (strcasecmp(gpio->name, "rd") == 0) { par->gpio.rd = gpio->gpio; return GPIOF_OUT_INIT_HIGH; } else if (strcasecmp(gpio->name, "latch") == 0) { par->gpio.latch = gpio->gpio; return GPIOF_OUT_INIT_LOW; } else if (gpio->name[0] == 'd' && gpio->name[1] == 'b') { ret = kstrtol(&gpio->name[2], 10, &val); if (ret == 0 && val < 16) { par->gpio.db[val] = gpio->gpio; return GPIOF_OUT_INIT_LOW; } } else if (strcasecmp(gpio->name, "led") == 0) { par->gpio.led[0] = gpio->gpio; return GPIOF_OUT_INIT_LOW; } return FBTFT_GPIO_NO_MATCH; }
static int skb_write(struct file *file, const char *buffer, unsigned long len, void *data) { int ret; unsigned char userData; if (len > PAGE_SIZE || len < 0) { pr_err("SKB System: cannot allow space for data\n"); return -ENOSPC; } /* write data to the buffer */ ret = copy_from_user(&userData, buffer, 1); if (ret) { pr_err("SKB System: cannot copy data from userspace\n"); return ret; } ret = kstrtol(&userData, 10, &filter_value); if (ret) { pr_err("bad value from user buffer\n"); return ret; } return len; }
static ssize_t power_supply_store_property(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { ssize_t ret; struct power_supply *psy = dev_get_drvdata(dev); const ptrdiff_t off = attr - power_supply_attrs; union power_supply_propval value; long long_val; /* TODO: support other types than int */ ret = kstrtol(buf, 10, &long_val); if (ret < 0) return ret; value.intval = long_val; ret = psy->set_property(psy, off, &value); if (ret < 0) return ret; return count; }
static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct lm63_data *data = i2c_get_clientdata(client); int nr = attr->index; long val; int err; int temp; u8 reg; err = kstrtol(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); switch (nr) { case 2: reg = LM63_REG_REMOTE_TCRIT; if (data->remote_unsigned) temp = TEMP8U_TO_REG(val - data->temp2_offset); else temp = TEMP8_TO_REG(val - data->temp2_offset); break; case 1: reg = LM63_REG_LOCAL_HIGH; temp = TEMP8_TO_REG(val); break; default: /* lookup table */ reg = LM63_REG_LUT_TEMP(nr - 3); temp = lut_temp_to_reg(data, val); } data->temp8[nr] = temp; i2c_smbus_write_byte_data(client, reg, temp); mutex_unlock(&data->update_lock); return count; }
static ssize_t ocrdma_dbgfs_ops_write(struct file *filp, const char __user *buffer, size_t count, loff_t *ppos) { char tmp_str[32]; long reset; int status; struct ocrdma_stats *pstats = filp->private_data; struct ocrdma_dev *dev = pstats->dev; if (*ppos != 0 || count == 0 || count > sizeof(tmp_str)) goto err; if (copy_from_user(tmp_str, buffer, count)) goto err; tmp_str[count-1] = '\0'; if (kstrtol(tmp_str, 10, &reset)) goto err; switch (pstats->type) { case OCRDMA_RESET_STATS: if (reset) { status = ocrdma_mbx_rdma_stats(dev, true); if (status) { pr_err("Failed to reset stats = %d\n", status); goto err; } } break; default: goto err; } return count; err: return -EFAULT; }
static ssize_t set_max_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct i2c_client *client = to_i2c_client(dev); struct ad7414_data *data = i2c_get_clientdata(client); int index = to_sensor_dev_attr(attr)->index; u8 reg = AD7414_REG_LIMIT[index]; long temp; int ret = kstrtol(buf, 10, &temp); if (ret < 0) return ret; temp = SENSORS_LIMIT(temp, -40000, 85000); temp = (temp + (temp < 0 ? -500 : 500)) / 1000; mutex_lock(&data->lock); data->temps[index] = temp; ad7414_write(client, reg, temp); mutex_unlock(&data->lock); return count; }
static ssize_t ep93xx_pwm_set_duty_percent(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct platform_device *pdev = to_platform_device(dev); struct ep93xx_pwm *pwm = platform_get_drvdata(pdev); long val; int err; err = kstrtol(buf, 10, &val); if (err) return -EINVAL; if (val > 0 && val < 100) { u32 term = readl(pwm->mmio_base + EP93XX_PWMx_TERM_COUNT); u32 duty = ((term + 1) * val / 100) - 1; writel(duty, pwm->mmio_base + EP93XX_PWMx_DUTY_CYCLE); pwm->duty_percent = val; return count; } return -EINVAL; }
void parse_wrapfs_options(void *data) { char *options = (char *)data; char *token = options; #ifdef EXTRA_CREDIT char *token2 = NULL; char *debug = NULL; long debugval = 0; #endif wrapfs_debug("raw_data : %s\n", options); set_ops_false(); while (token != NULL) { token = strsep(&options, ","); if (token && strcmp(token, "mmap") == 0) { wrapfs_debug("MMAP is set"); mmap_option_set = true; } #ifdef EXTRA_CREDIT else if (token && strstr(token, "debug") != NULL) { debug = token; token2 = strsep(&debug, "="); if (strstr(token2, "debug") != NULL) { if (kstrtol(debug, 10, &debugval) < 0) { wrapfs_debug( "Invalid debug option. Ignoring it!!"); debugval = 0; } else { wrapfs_debug("Debug level is set: %ld", debugval); set_debug_options(debugval); } } } #endif } /*return 0;*/ }
static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { int index = to_sensor_dev_attr(devattr)->index; struct i2c_client *client = to_i2c_client(dev); struct max1668_data *data = i2c_get_clientdata(client); long temp; int ret; ret = kstrtol(buf, 10, &temp); if (ret < 0) return ret; mutex_lock(&data->update_lock); data->temp_min[index] = SENSORS_LIMIT(temp/1000, -128, 127); if (i2c_smbus_write_byte_data(client, MAX1668_REG_LIML_WR(index), data->temp_min[index])) count = -EIO; mutex_unlock(&data->update_lock); return count; }
static ssize_t set_temp_offset(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); int nr = sensor_attr->index; struct smsc47m192_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); long val; int err; err = kstrtol(buf, 10, &val); if (err) return err; mutex_lock(&data->update_lock); data->temp_offset[nr] = TEMP_TO_REG(val); if (nr > 1) i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]); else if (data->temp_offset[nr] != 0) { /* * offset[0] and offset[1] share the same register, * SFR bit 4 activates offset[0] */ i2c_smbus_write_byte_data(client, SMSC47M192_REG_SFR, (sfr & 0xef) | (nr == 0 ? 0x10 : 0)); data->temp_offset[1-nr] = 0; i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]); } else if ((sfr & 0x10) == (nr == 0 ? 0x10 : 0)) i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_OFFSET(nr), 0); mutex_unlock(&data->update_lock); return count; }
static ssize_t set_temp(struct device *dev, struct device_attribute *da, const char *buf, size_t count) { int res; long val; struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct i2c_client *client = to_i2c_client(dev); struct ds620_data *data = i2c_get_clientdata(client); res = kstrtol(buf, 10, &val); if (res) return res; val = (val * 10 / 625) * 8; mutex_lock(&data->update_lock); data->temp[attr->index] = val; i2c_smbus_write_word_swapped(client, DS620_REG_TEMP[attr->index], data->temp[attr->index]); mutex_unlock(&data->update_lock); return count; }
static ssize_t set_tcrit1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct lm95234_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; int ret = lm95234_update_device(data); long val; if (ret) return ret; ret = kstrtol(buf, 10, &val); if (ret < 0) return ret; val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 255); mutex_lock(&data->update_lock); data->tcrit1[index] = val; i2c_smbus_write_byte_data(data->client, LM95234_REG_TCRIT1(index), val); mutex_unlock(&data->update_lock); return count; }
static ssize_t store_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { int index = to_sensor_dev_attr(devattr)->index; struct tmp401_data *data = tmp401_update_device(dev); long val; u8 reg; if (kstrtol(buf, 10, &val)) return -EINVAL; reg = tmp401_crit_temp_to_register(val, data->config); mutex_lock(&data->update_lock); i2c_smbus_write_byte_data(to_i2c_client(dev), TMP401_TEMP_CRIT_LIMIT[index], reg); data->temp_crit[index] = reg; mutex_unlock(&data->update_lock); return count; }
static ssize_t hyst_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int ret; long temp; struct stts751_priv *priv = dev_get_drvdata(dev); if (kstrtol(buf, 10, &temp) < 0) return -EINVAL; mutex_lock(&priv->access_lock); /* HW works in range -64C to +127.937C */ temp = clamp_val(temp, -64000, priv->therm); priv->hyst = temp; dev_dbg(&priv->client->dev, "setting hyst %ld", temp); temp = priv->therm - temp; ret = stts751_set_temp_reg8(priv, temp, STTS751_REG_HYST); mutex_unlock(&priv->access_lock); if (ret) return ret; return count; }