static int bcm47xx_get_invariants(struct ssb_bus *bus, struct ssb_init_invariants *iv) { char buf[20]; int len, err; /* Fill boardinfo structure */ memset(&iv->boardinfo, 0 , sizeof(struct ssb_boardinfo)); len = bcm47xx_nvram_getenv("boardvendor", buf, sizeof(buf)); if (len > 0) { err = kstrtou16(strim(buf), 0, &iv->boardinfo.vendor); if (err) pr_warn("Couldn't parse nvram board vendor entry with value \"%s\"\n", buf); } if (!iv->boardinfo.vendor) iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM; len = bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf)); if (len > 0) { err = kstrtou16(strim(buf), 0, &iv->boardinfo.type); if (err) pr_warn("Couldn't parse nvram board type entry with value \"%s\"\n", buf); } memset(&iv->sprom, 0, sizeof(struct ssb_sprom)); bcm47xx_fill_sprom(&iv->sprom, NULL, false); if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0) iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10); return 0; }
static ssize_t store_value(struct most_dci_obj *dci_obj, struct most_dci_attribute *attr, const char *buf, size_t count) { u16 val; u16 reg_addr; const char *name = attr->attr.name; int err = kstrtou16(buf, 16, &val); if (err) return err; if (!strcmp(name, "arb_address")) { dci_obj->reg_addr = val; return count; } if (!strcmp(name, "arb_value")) { reg_addr = dci_obj->reg_addr; } else if (!strcmp(name, "sync_ep")) { u16 ep = val; reg_addr = DRCI_REG_BASE + DRCI_COMMAND + ep * 16; val = 1; } else if (get_static_reg_addr(ro_regs, name, ®_addr)) { return -EFAULT; } err = drci_wr_reg(dci_obj->usb_device, reg_addr, val); if (err < 0) return err; return count; }
static ssize_t value_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { u16 val; u16 reg_addr; const char *name = attr->attr.name; struct most_dci_obj *dci_obj = to_dci_obj(dev); struct usb_device *usb_dev = dci_obj->usb_device; int err = kstrtou16(buf, 16, &val); if (err) return err; if (!strcmp(name, "arb_address")) { dci_obj->reg_addr = val; return count; } if (!strcmp(name, "arb_value")) err = drci_wr_reg(usb_dev, dci_obj->reg_addr, val); else if (!strcmp(name, "sync_ep")) err = start_sync_ep(usb_dev, val); else if (!get_static_reg_addr(rw_regs, name, ®_addr)) err = drci_wr_reg(usb_dev, reg_addr, val); else return -EFAULT; if (err < 0) return err; return count; }
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 ssize_t ds2780_set_rsgain_setting(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int ret; u16 new_setting; struct power_supply *psy = to_power_supply(dev); struct ds2780_device_info *dev_info = to_ds2780_device_info(psy); ret = kstrtou16(buf, 0, &new_setting); if (ret < 0) return ret; /* Gain can only be from 0 to 1.999 in steps of .001 */ if (new_setting > 1999) { dev_err(dev_info->dev, "Invalid rsgain setting (0 - 1999)\n"); return -EINVAL; } ret = ds2780_set_rsgain_register(dev_info, new_setting); if (ret < 0) return ret; return count; }
int check_user_usb_string(const char *name, struct usb_gadget_strings *stringtab_dev) { unsigned primary_lang; unsigned sub_lang; u16 num; int ret; ret = kstrtou16(name, 0, &num); if (ret) return ret; primary_lang = num & 0x3ff; sub_lang = num >> 10; /* simple sanity check for valid langid */ switch (primary_lang) { case 0: case 0x62 ... 0xfe: case 0x100 ... 0x3ff: return -EINVAL; } if (!sub_lang) return -EINVAL; stringtab_dev->language = num; return 0; }
static ssize_t proximity_thresh_low_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { u16 uNewThresh; int iRet = 0; struct ssp_data *data = dev_get_drvdata(dev); iRet = kstrtou16(buf, 10, &uNewThresh); if (iRet < 0) pr_err("[SSP]: %s - kstrtoint failed.(%d)\n", __func__, iRet); else { if(uNewThresh & 0xfc00) pr_err("[SSP]: %s - allow 10bits.(%d)\n", __func__, uNewThresh); else { uNewThresh &= 0x03ff; data->uProxLoThresh = uNewThresh; set_proximity_threshold(data, data->uProxHiThresh, data->uProxLoThresh); } } ssp_dbg("[SSP]: %s - new prox threshold : hi - %u, lo - %u\n", __func__, data->uProxHiThresh, data->uProxLoThresh); return size; }
static ssize_t ir_current_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { u16 uNewIrCurrent = DEFUALT_IR_CURRENT; int iRet = 0; u16 current_index = 0; struct ssp_data *data = dev_get_drvdata(dev); static u16 set_current[2][16] = { {0, 25, 50, 75, 100, 125, 150, 175, 225, 250, 275, 300, 325, 350, 375, 400}, {2, 28, 34, 50, 66, 82, 98, 114, 130, 146, 162, 178, 194, 210, 226, 242} }; iRet = kstrtou16(buf, 10, &uNewIrCurrent); if (iRet < 0) pr_err("[SSP]: %s - kstrtoint failed.(%d)\n", __func__, iRet); else { for(current_index = 0; current_index < 16; current_index++) { if (set_current[0][current_index] == uNewIrCurrent) { data->uIr_Current = set_current[1][current_index]; } } set_gesture_current(data, data->uIr_Current); data->uIr_Current = uNewIrCurrent; } ssp_dbg("[SSP]: %s - new Ir_Current Setting : %d\n", __func__, data->uIr_Current); return size; }
static ssize_t cec_logical_addr_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { ssize_t ret; u32 state; u16 addr; struct tegra_cec *cec; if (!buf || !count) return -EINVAL; cec = dev_get_drvdata(dev); if (!atomic_read(&cec->init_done)) return -EAGAIN; ret = kstrtou16(buf, 0, &addr); if (ret) return ret; dev_info(dev, "tegra_cec: set logical address: %x\n", (u32)addr); cec->logical_addr = addr; state = readl(cec->cec_base + TEGRA_CEC_HW_CONTROL); state &= ~TEGRA_CEC_HWCTRL_RX_LADDR_MASK; state |= TEGRA_CEC_HWCTRL_RX_LADDR(cec->logical_addr); writel(state, cec->cec_base + TEGRA_CEC_HW_CONTROL); return count; }
static ssize_t ath6kl_bmisstime_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct ath6kl *ar = file->private_data; struct ath6kl_vif *vif; u16 bmiss_time; char buf[32]; ssize_t len; vif = ath6kl_vif_first(ar); if (!vif) return -EIO; len = min(count, sizeof(buf) - 1); if (copy_from_user(buf, user_buf, len)) return -EFAULT; buf[len] = '\0'; if (kstrtou16(buf, 0, &bmiss_time)) return -EINVAL; vif->bmiss_time_t = bmiss_time; /* Enable error report event for bmiss */ ath6kl_wmi_set_err_report_bitmask(ar->wmi, vif->fw_vif_idx, ATH6KL_ERR_REPORT_BMISS_MASK); ath6kl_wmi_bmisstime_cmd(ar->wmi, vif->fw_vif_idx, vif->bmiss_time_t, 0); return count; }
static ssize_t proximity_thresh_low_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct cm36686_data *cm36686 = dev_get_drvdata(dev); u16 thresh_value = ps_reg_init_setting[PS_THD_LOW][CMD]; int err; err = kstrtou16(buf, 10, &thresh_value); if (err < 0) pr_err("%s, kstrtoint failed.", __func__); if (thresh_value > 2) { ps_reg_init_setting[PS_THD_LOW][CMD] = thresh_value; err = cm36686_i2c_write_word(cm36686, REG_PS_THD_LOW, ps_reg_init_setting[PS_THD_LOW][CMD]); if (err < 0) pr_err("%s: cm36686_ps_low_reg is failed. %d\n", __func__, err); pr_info("%s, new low threshold = 0x%x\n", __func__, thresh_value); msleep(150); } else pr_err("%s, wrong low threshold value(0x%x)!!\n", __func__, thresh_value); return size; }
static ssize_t ir_current_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { u16 uNewIrCurrent = DEFUALT_IR_CURRENT; int iRet = 0; u16 current_index = 0; struct ssp_data *data = dev_get_drvdata(dev); static u16 set_current[2][16] = { {0, 6, 13, 20, 26, 33, 40, 46, 53, 60, 66, 73, 80, 86, 93, 100}, {0<<4, 1<<4, 2<<4, 3<<4, 4<<4, 5<<4, 6<<4, 7<<4, 8<<4, 9<<4, 10<<4, 11<<4, 12<<4, 13<<4, 14<<4, 15<<4} }; iRet = kstrtou16(buf, 10, &uNewIrCurrent); if (iRet < 0) pr_err("[SSP]: %s - kstrtoint failed.(%d)\n", __func__, iRet); else { for(current_index = 0; current_index < 16; current_index++) { if (set_current[0][current_index] == uNewIrCurrent) { data->uIr_Current = set_current[1][current_index]; break; } } if(current_index == 16) // current setting value wrong. { return ERROR; } set_gesture_current(data, data->uIr_Current); data->uIr_Current= uNewIrCurrent; } ssp_dbg("[SSP]: %s - new Ir_Current Setting : %d\n", __func__, data->uIr_Current); return size; }
static ssize_t reset_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { int ret; unsigned short do_reset; struct zram *zram; struct block_device *bdev; zram = dev_to_zram(dev); bdev = bdget_disk(zram->disk, 0); /* Do not reset an active device! */ if (bdev->bd_holders) return -EBUSY; ret = kstrtou16(buf, 10, &do_reset); if (ret) return ret; if (!do_reset) return -EINVAL; /* Make sure all pending I/O is finished */ if (bdev) fsync_bdev(bdev); down_write(&zram->init_lock); if (zram->init_done) __zram_reset_device(zram); up_write(&zram->init_lock); return len; }
static ssize_t pmu_reg16_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int ret; int addr; uint16_t value; char *arg[3] = {}, *para, *buf_work, *p; int i; buf_work = kstrdup(buf, GFP_KERNEL); p = buf_work; for (i = 0; i < 3; i++) { para = strsep(&p, " "); if (para == NULL) break; arg[i] = para; } if (i < 2 || i > 3) { ret = 1; goto error; } switch (arg[0][0]) { case 'r': ret = kstrtoint(arg[1], 16, &addr); ret = aml1216_read16(addr, &value); if (!ret) pr_info("reg[0x%03x] = 0x%04x\n", addr, value); break; case 'w': if (i != 3) { /* parameter is not enough */ ret = 1; break; } ret = kstrtoint(arg[1], 16, &addr); ret = kstrtou16(arg[2], 16, &value); ret = aml1216_write16(addr, value); if (!ret) pr_info("set reg[0x%03x] to 0x%04x\n", addr, value); break; default: ret = 1; break; } error: kfree(buf_work); if (ret == 1) printf_usage(); return count; }
static ssize_t usb2_lpm_l1_timeout_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct usb_device *udev = to_usb_device(dev); u16 timeout; if (kstrtou16(buf, 0, &timeout)) return -EINVAL; udev->l1_params.timeout = timeout; return count; }
static ssize_t debug_store(struct device *cd, struct device_attribute *attr, const char *buf, size_t len) { struct video_device *vdev = to_video_device(cd); int res = 0; u16 value; res = kstrtou16(buf, 0, &value); if (res) return res; vdev->debug = value; return len; }
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; }
static ssize_t midi_set_midi_mask_receive(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct usb_interface *interface = to_usb_interface(dev); struct usb_line6 *line6 = usb_get_intfdata(interface); unsigned short value; int ret; ret = kstrtou16(buf, 10, &value); if (ret) return ret; line6->line6midi->midi_mask_receive = value; return count; }
static ssize_t store_led_override(struct qib_pportdata *ppd, const char *buf, size_t count) { struct qib_devdata *dd = ppd->dd; int ret; u16 val; ret = kstrtou16(buf, 0, &val); if (ret) { qib_dev_err(dd, "attempt to set invalid LED override\n"); return ret; } qib_set_led_override(ppd, val); return count; }
static ssize_t ade7854_write_16bit(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; u16 val; ret = kstrtou16(buf, 10, &val); if (ret) goto error_ret; ret = st->write_reg_16(dev, this_attr->address, val); error_ret: return ret ? ret : len; }
static ssize_t store_period(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { char buff[10] = {0,}; int cnt, ret; u16 period; cnt = count; cnt = (buf[cnt-1] == '\n') ? cnt-1 : cnt; memcpy(buff, buf, cnt); buff[cnt] = '\0'; ret = kstrtou16(buff, 0, &period); if (ret != 0) { dev_err(dev, "[VIB] fail to get period.\n"); return count; } g_hap_data->pdata->period = (u16)period; return count; }
static ssize_t store_hrtbt_enb(struct qib_pportdata *ppd, const char *buf, size_t count) { struct qib_devdata *dd = ppd->dd; int ret; u16 val; ret = kstrtou16(buf, 0, &val); if (ret) { qib_dev_err(dd, "attempt to set invalid Heartbeat enable\n"); return ret; } /* * Set the "intentional" heartbeat enable per either of * "Enable" and "Auto", as these are normally set together. * This bit is consulted when leaving loopback mode, * because entering loopback mode overrides it and automatically * disables heartbeat. */ ret = dd->f_set_ib_cfg(ppd, QIB_IB_CFG_HRTBT, val); return ret < 0 ? ret : count; }