diff options
Diffstat (limited to 'drivers/staging/speakup/kobjects.c')
| -rw-r--r-- | drivers/staging/speakup/kobjects.c | 260 |
1 files changed, 137 insertions, 123 deletions
diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c index 2093896c546..2ef7f6f201a 100644 --- a/drivers/staging/speakup/kobjects.c +++ b/drivers/staging/speakup/kobjects.c @@ -15,6 +15,7 @@ #include <linux/kernel.h> #include <linux/kobject.h> #include <linux/string.h> +#include <linux/string_helpers.h> #include <linux/sysfs.h> #include <linux/ctype.h> @@ -34,14 +35,14 @@ static ssize_t chars_chartab_show(struct kobject *kobj, size_t bufsize = PAGE_SIZE; unsigned long flags; - spk_lock(flags); + spin_lock_irqsave(&speakup_info.spinlock, flags); *buf_pointer = '\0'; for (i = 0; i < 256; i++) { if (bufsize <= 1) break; if (strcmp("characters", attr->attr.name) == 0) { len = scnprintf(buf_pointer, bufsize, "%d\t%s\n", - i, characters[i]); + i, spk_characters[i]); } else { /* show chartab entry */ if (IS_TYPE(i, B_CTL)) cp = "B_CTL"; @@ -69,7 +70,7 @@ static ssize_t chars_chartab_show(struct kobject *kobj, bufsize -= len; buf_pointer += len; } - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return buf_pointer - buf; } @@ -126,7 +127,7 @@ static ssize_t chars_chartab_store(struct kobject *kobj, size_t desc_length = 0; int i; - spk_lock(flags); + spin_lock_irqsave(&speakup_info.spinlock, flags); while (cp < end) { while ((cp < end) && (*cp == ' ' || *cp == '\t')) @@ -185,12 +186,12 @@ static ssize_t chars_chartab_store(struct kobject *kobj, outptr[desc_length] = '\0'; if (do_characters) { - if (characters[index] != default_chars[index]) - kfree(characters[index]); - characters[index] = desc; + if (spk_characters[index] != spk_default_chars[index]) + kfree(spk_characters[index]); + spk_characters[index] = desc; used++; } else { - charclass = chartab_get_value(keyword); + charclass = spk_chartab_get_value(keyword); if (charclass == 0) { rejected++; cp = linefeed + 1; @@ -206,12 +207,12 @@ static ssize_t chars_chartab_store(struct kobject *kobj, if (reset) { if (do_characters) - reset_default_chars(); + spk_reset_default_chars(); else - reset_default_chartab(); + spk_reset_default_chartab(); } - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); report_char_chartab_status(reset, received, used, rejected, do_characters); return retval; @@ -231,8 +232,8 @@ static ssize_t keymap_show(struct kobject *kobj, struct kobj_attribute *attr, u_char *cp1; u_char ch; unsigned long flags; - spk_lock(flags); - cp1 = key_buf + SHIFT_TBL_SIZE; + spin_lock_irqsave(&speakup_info.spinlock, flags); + cp1 = spk_key_buf + SHIFT_TBL_SIZE; num_keys = (int)(*cp1); nstates = (int)cp1[1]; cp += sprintf(cp, "%d, %d, %d,\n", KEY_MAP_VER, num_keys, nstates); @@ -247,7 +248,7 @@ static ssize_t keymap_show(struct kobject *kobj, struct kobj_attribute *attr, } } cp += sprintf(cp, "0, %d\n", KEY_MAP_VER); - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return (int)(cp-buf); } @@ -264,17 +265,17 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr, u_char *cp1; unsigned long flags; - spk_lock(flags); + spin_lock_irqsave(&speakup_info.spinlock, flags); in_buff = kmemdup(buf, count + 1, GFP_ATOMIC); if (!in_buff) { - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return -ENOMEM; } if (strchr("dDrR", *in_buff)) { - set_key_info(key_defaults, key_buf); + spk_set_key_info(spk_key_defaults, spk_key_buf); pr_info("keymap set to default values\n"); kfree(in_buff); - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return count; } if (in_buff[count - 1] == '\n') @@ -282,22 +283,22 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr, cp = in_buff; cp1 = (u_char *)in_buff; for (i = 0; i < 3; i++) { - cp = s2uchar(cp, cp1); + cp = spk_s2uchar(cp, cp1); cp1++; } i = (int)cp1[-2]+1; i *= (int)cp1[-1]+1; i += 2; /* 0 and last map ver */ if (cp1[-3] != KEY_MAP_VER || cp1[-1] > 10 || - i+SHIFT_TBL_SIZE+4 >= sizeof(key_buf)) { + i+SHIFT_TBL_SIZE+4 >= sizeof(spk_key_buf)) { pr_warn("i %d %d %d %d\n", i, (int)cp1[-3], (int)cp1[-2], (int)cp1[-1]); kfree(in_buff); - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return -EINVAL; } while (--i >= 0) { - cp = s2uchar(cp, cp1); + cp = spk_s2uchar(cp, cp1); cp1++; if (!(*cp)) break; @@ -307,14 +308,14 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr, pr_warn("end %d %d %d %d\n", i, (int)cp1[-3], (int)cp1[-2], (int)cp1[-1]); } else { - if (set_key_info(in_buff, key_buf)) { - set_key_info(key_defaults, key_buf); + if (spk_set_key_info(in_buff, spk_key_buf)) { + spk_set_key_info(spk_key_defaults, spk_key_buf); ret = -EINVAL; pr_warn("set key failed\n"); } } kfree(in_buff); - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return ret; } @@ -340,10 +341,10 @@ static ssize_t silent_store(struct kobject *kobj, struct kobj_attribute *attr, pr_warn("silent value '%c' not in range (0,7)\n", ch); return -EINVAL; } - spk_lock(flags); + spin_lock_irqsave(&speakup_info.spinlock, flags); if (ch&2) { shut = 1; - do_flush(); + spk_do_flush(); } else { shut = 0; } @@ -353,7 +354,7 @@ static ssize_t silent_store(struct kobject *kobj, struct kobj_attribute *attr, spk_shut_up |= shut; else spk_shut_up &= ~shut; - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return count; } @@ -388,7 +389,7 @@ static ssize_t synth_store(struct kobject *kobj, struct kobj_attribute *attr, if (new_synth_name[len - 1] == '\n') len--; new_synth_name[len] = '\0'; - strlwr(new_synth_name); + spk_strlwr(new_synth_name); if ((synth != NULL) && (!strcmp(new_synth_name, synth->name))) { pr_warn("%s already in use\n", new_synth_name); } else if (synth_init(new_synth_name) != 0) { @@ -417,7 +418,7 @@ static ssize_t synth_direct_store(struct kobject *kobj, bytes = min_t(size_t, len, 250); strncpy(tmp, ptr, bytes); tmp[bytes] = '\0'; - xlate(tmp); + string_unescape_any_inplace(tmp); synth_printf("%s", tmp); ptr += bytes; len -= bytes; @@ -455,29 +456,29 @@ static ssize_t punc_show(struct kobject *kobj, struct kobj_attribute *attr, short mask; unsigned long flags; - p_header = var_header_by_name(attr->attr.name); + p_header = spk_var_header_by_name(attr->attr.name); if (p_header == NULL) { pr_warn("p_header is null, attr->attr.name is %s\n", attr->attr.name); return -EINVAL; } - var = get_punc_var(p_header->var_id); + var = spk_get_punc_var(p_header->var_id); if (var == NULL) { pr_warn("var is null, p_header->var_id is %i\n", p_header->var_id); return -EINVAL; } - spk_lock(flags); - pb = (struct st_bits_data *) &punc_info[var->value]; + spin_lock_irqsave(&speakup_info.spinlock, flags); + pb = (struct st_bits_data *) &spk_punc_info[var->value]; mask = pb->mask; for (i = 33; i < 128; i++) { if (!(spk_chartab[i]&mask)) continue; *cp++ = (char)i; } - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return cp-buf; } @@ -497,14 +498,14 @@ static ssize_t punc_store(struct kobject *kobj, struct kobj_attribute *attr, if (x < 1 || x > 99) return -EINVAL; - p_header = var_header_by_name(attr->attr.name); + p_header = spk_var_header_by_name(attr->attr.name); if (p_header == NULL) { pr_warn("p_header is null, attr->attr.name is %s\n", attr->attr.name); return -EINVAL; } - var = get_punc_var(p_header->var_id); + var = spk_get_punc_var(p_header->var_id); if (var == NULL) { pr_warn("var is null, p_header->var_id is %i\n", p_header->var_id); @@ -517,14 +518,14 @@ static ssize_t punc_store(struct kobject *kobj, struct kobj_attribute *attr, x--; punc_buf[x] = '\0'; - spk_lock(flags); + spin_lock_irqsave(&speakup_info.spinlock, flags); if (*punc_buf == 'd' || *punc_buf == 'r') - x = set_mask_bits(0, var->value, 3); + x = spk_set_mask_bits(NULL, var->value, 3); else - x = set_mask_bits(punc_buf, var->value, 3); + x = spk_set_mask_bits(punc_buf, var->value, 3); - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return count; } @@ -542,11 +543,11 @@ ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr, char ch; unsigned long flags; - param = var_header_by_name(attr->attr.name); + param = spk_var_header_by_name(attr->attr.name); if (param == NULL) return -EINVAL; - spk_lock(flags); + spin_lock_irqsave(&speakup_info.spinlock, flags); var = (struct var_t *) param->data; switch (param->var_type) { case VAR_NUM: @@ -579,12 +580,31 @@ ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr, param->name, param->var_type); break; } - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return rv; } EXPORT_SYMBOL_GPL(spk_var_show); /* + * Used to reset either default_pitch or default_vol. + */ +static inline void spk_reset_default_value(char *header_name, + int *synth_default_value, int idx) +{ + struct st_var_header *param; + + if (synth && synth_default_value) { + param = spk_var_header_by_name(header_name); + if (param) { + spk_set_num_var(synth_default_value[idx], + param, E_NEW_DEFAULT); + spk_set_num_var(0, param, E_DEFAULT); + pr_info("%s reset to default value\n", param->name); + } + } +} + +/* * This function is called when a user echos a value to one of the * variable parameters. */ @@ -596,18 +616,19 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, int len; char *cp; struct var_t *var_data; - int value; + long value; unsigned long flags; - param = var_header_by_name(attr->attr.name); + param = spk_var_header_by_name(attr->attr.name); if (param == NULL) return -EINVAL; if (param->data == NULL) return 0; ret = 0; - cp = xlate((char *) buf); + cp = (char *)buf; + string_unescape_any_inplace(cp); - spk_lock(flags); + spin_lock_irqsave(&speakup_info.spinlock, flags); switch (param->var_type) { case VAR_NUM: case VAR_TIME: @@ -617,61 +638,54 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, len = E_INC; else len = E_SET; - speakup_s2i(cp, &value); - ret = set_num_var(value, param, len); - if (ret == E_RANGE) { + if (kstrtol(cp, 10, &value) == 0) + ret = spk_set_num_var(value, param, len); + else + pr_warn("overflow or parsing error has occurred"); + if (ret == -ERANGE) { var_data = param->data; pr_warn("value for %s out of range, expect %d to %d\n", - attr->attr.name, + param->name, var_data->u.n.low, var_data->u.n.high); } + + /* + * If voice was just changed, we might need to reset our default + * pitch and volume. + */ + if (param->var_id == VOICE && synth && + (ret == 0 || ret == -ERESTART)) { + var_data = param->data; + value = var_data->u.n.value; + spk_reset_default_value("pitch", synth->default_pitch, + value); + spk_reset_default_value("vol", synth->default_vol, + value); + } break; case VAR_STRING: - len = strlen(buf); - if ((len >= 1) && (buf[len - 1] == '\n')) + len = strlen(cp); + if ((len >= 1) && (cp[len - 1] == '\n')) --len; - if ((len >= 2) && (buf[0] == '"') && (buf[len - 1] == '"')) { - ++buf; + if ((len >= 2) && (cp[0] == '"') && (cp[len - 1] == '"')) { + ++cp; len -= 2; } - cp = (char *) buf; cp[len] = '\0'; - ret = set_string_var(buf, param, len); - if (ret == E_TOOLONG) + ret = spk_set_string_var(cp, param, len); + if (ret == -E2BIG) pr_warn("value too long for %s\n", - attr->attr.name); + param->name); break; default: pr_warn("%s unknown type %d\n", param->name, (int)param->var_type); break; } - /* - * If voice was just changed, we might need to reset our default - * pitch and volume. - */ - if (strcmp(attr->attr.name, "voice") == 0) { - if (synth && synth->default_pitch) { - param = var_header_by_name("pitch"); - if (param) { - set_num_var(synth->default_pitch[value], param, - E_NEW_DEFAULT); - set_num_var(0, param, E_DEFAULT); - } - } - if (synth && synth->default_vol) { - param = var_header_by_name("vol"); - if (param) { - set_num_var(synth->default_vol[value], param, - E_NEW_DEFAULT); - set_num_var(0, param, E_DEFAULT); - } - } - } - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); - if (ret == SET_DEFAULT) - pr_info("%s reset to default value\n", attr->attr.name); + if (ret == -ERESTART) + pr_info("%s reset to default value\n", param->name); return count; } EXPORT_SYMBOL_GPL(spk_var_store); @@ -694,7 +708,7 @@ static ssize_t message_show_helper(char *buf, enum msg_index_t first, if (bufsize <= 1) break; printed = scnprintf(buf_pointer, bufsize, "%d\t%s\n", - index, msg_get(cursor)); + index, spk_msg_get(cursor)); buf_pointer += printed; bufsize -= printed; } @@ -788,7 +802,7 @@ static ssize_t message_store_helper(const char *buf, size_t count, continue; } - msg_stored = msg_set(curmessage, temp, desc_length); + msg_stored = spk_msg_set(curmessage, temp, desc_length); if (msg_stored < 0) { retval = msg_stored; if (msg_stored == -ENOMEM) @@ -802,7 +816,7 @@ static ssize_t message_store_helper(const char *buf, size_t count, } if (reset) - reset_msg_group(group); + spk_reset_msg_group(group); report_msg_status(reset, received, used, rejected, group->name); return retval; @@ -812,13 +826,13 @@ static ssize_t message_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { ssize_t retval = 0; - struct msg_group_t *group = find_msg_group(attr->attr.name); + struct msg_group_t *group = spk_find_msg_group(attr->attr.name); unsigned long flags; BUG_ON(!group); - spk_lock(flags); + spin_lock_irqsave(&speakup_info.spinlock, flags); retval = message_show_helper(buf, group->start, group->end); - spk_unlock(flags); + spin_unlock_irqrestore(&speakup_info.spinlock, flags); return retval; } @@ -826,7 +840,7 @@ static ssize_t message_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { ssize_t retval = 0; - struct msg_group_t *group = find_msg_group(attr->attr.name); + struct msg_group_t *group = spk_find_msg_group(attr->attr.name); BUG_ON(!group); retval = message_store_helper(buf, count, group); @@ -837,75 +851,75 @@ static ssize_t message_store(struct kobject *kobj, struct kobj_attribute *attr, * Declare the attributes. */ static struct kobj_attribute keymap_attribute = - __ATTR(keymap, ROOT_W, keymap_show, keymap_store); + __ATTR_RW(keymap); static struct kobj_attribute silent_attribute = - __ATTR(silent, USER_W, NULL, silent_store); + __ATTR_WO(silent); static struct kobj_attribute synth_attribute = - __ATTR(synth, USER_RW, synth_show, synth_store); + __ATTR_RW(synth); static struct kobj_attribute synth_direct_attribute = - __ATTR(synth_direct, USER_W, NULL, synth_direct_store); + __ATTR_WO(synth_direct); static struct kobj_attribute version_attribute = __ATTR_RO(version); static struct kobj_attribute delimiters_attribute = - __ATTR(delimiters, USER_RW, punc_show, punc_store); + __ATTR(delimiters, S_IWUSR|S_IRUGO, punc_show, punc_store); static struct kobj_attribute ex_num_attribute = - __ATTR(ex_num, USER_RW, punc_show, punc_store); + __ATTR(ex_num, S_IWUSR|S_IRUGO, punc_show, punc_store); static struct kobj_attribute punc_all_attribute = - __ATTR(punc_all, USER_RW, punc_show, punc_store); + __ATTR(punc_all, S_IWUSR|S_IRUGO, punc_show, punc_store); static struct kobj_attribute punc_most_attribute = - __ATTR(punc_most, USER_RW, punc_show, punc_store); + __ATTR(punc_most, S_IWUSR|S_IRUGO, punc_show, punc_store); static struct kobj_attribute punc_some_attribute = - __ATTR(punc_some, USER_RW, punc_show, punc_store); + __ATTR(punc_some, S_IWUSR|S_IRUGO, punc_show, punc_store); static struct kobj_attribute repeats_attribute = - __ATTR(repeats, USER_RW, punc_show, punc_store); + __ATTR(repeats, S_IWUSR|S_IRUGO, punc_show, punc_store); static struct kobj_attribute attrib_bleep_attribute = - __ATTR(attrib_bleep, USER_RW, spk_var_show, spk_var_store); + __ATTR(attrib_bleep, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute bell_pos_attribute = - __ATTR(bell_pos, USER_RW, spk_var_show, spk_var_store); + __ATTR(bell_pos, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute bleep_time_attribute = - __ATTR(bleep_time, USER_RW, spk_var_show, spk_var_store); + __ATTR(bleep_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute bleeps_attribute = - __ATTR(bleeps, USER_RW, spk_var_show, spk_var_store); + __ATTR(bleeps, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute cursor_time_attribute = - __ATTR(cursor_time, USER_RW, spk_var_show, spk_var_store); + __ATTR(cursor_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute key_echo_attribute = - __ATTR(key_echo, USER_RW, spk_var_show, spk_var_store); + __ATTR(key_echo, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute no_interrupt_attribute = - __ATTR(no_interrupt, USER_RW, spk_var_show, spk_var_store); + __ATTR(no_interrupt, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute punc_level_attribute = - __ATTR(punc_level, USER_RW, spk_var_show, spk_var_store); + __ATTR(punc_level, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute reading_punc_attribute = - __ATTR(reading_punc, USER_RW, spk_var_show, spk_var_store); + __ATTR(reading_punc, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute say_control_attribute = - __ATTR(say_control, USER_RW, spk_var_show, spk_var_store); + __ATTR(say_control, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute say_word_ctl_attribute = - __ATTR(say_word_ctl, USER_RW, spk_var_show, spk_var_store); + __ATTR(say_word_ctl, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); static struct kobj_attribute spell_delay_attribute = - __ATTR(spell_delay, USER_RW, spk_var_show, spk_var_store); + __ATTR(spell_delay, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); /* * These attributes are i18n related. */ static struct kobj_attribute announcements_attribute = - __ATTR(announcements, USER_RW, message_show, message_store); + __ATTR(announcements, S_IWUSR|S_IRUGO, message_show, message_store); static struct kobj_attribute characters_attribute = - __ATTR(characters, USER_RW, chars_chartab_show, chars_chartab_store); + __ATTR(characters, S_IWUSR|S_IRUGO, chars_chartab_show, chars_chartab_store); static struct kobj_attribute chartab_attribute = - __ATTR(chartab, USER_RW, chars_chartab_show, chars_chartab_store); + __ATTR(chartab, S_IWUSR|S_IRUGO, chars_chartab_show, chars_chartab_store); static struct kobj_attribute ctl_keys_attribute = - __ATTR(ctl_keys, USER_RW, message_show, message_store); + __ATTR(ctl_keys, S_IWUSR|S_IRUGO, message_show, message_store); static struct kobj_attribute colors_attribute = - __ATTR(colors, USER_RW, message_show, message_store); + __ATTR(colors, S_IWUSR|S_IRUGO, message_show, message_store); static struct kobj_attribute formatted_attribute = - __ATTR(formatted, USER_RW, message_show, message_store); + __ATTR(formatted, S_IWUSR|S_IRUGO, message_show, message_store); static struct kobj_attribute function_names_attribute = - __ATTR(function_names, USER_RW, message_show, message_store); + __ATTR(function_names, S_IWUSR|S_IRUGO, message_show, message_store); static struct kobj_attribute key_names_attribute = - __ATTR(key_names, USER_RW, message_show, message_store); + __ATTR(key_names, S_IWUSR|S_IRUGO, message_show, message_store); static struct kobj_attribute states_attribute = - __ATTR(states, USER_RW, message_show, message_store); + __ATTR(states, S_IWUSR|S_IRUGO, message_show, message_store); /* * Create groups of attributes so that we can create and destroy them all |
