“6b14b81899a2e1e5dd0d089f2a41a6118929658d”上不存在“...kernel/git@gitcode.net:openeuler/raspberrypi-kernel.git”
提交 b71600bb 编写于 作者: R Raphael S.Carvalho 提交者: Greg Kroah-Hartman

staging/speakup/kobjects.c: Code improvement.

Well, there is no need to use strcmp since we can make a test of similar semantic by using the var_id field of param.
I moved the test into the VAR_NUM:VAR_TIME case since VAR_STRING will never be "voice".

spk_xlate isn't used anymore (in line 628), then there is no difference between using cp and buf in VAR_STRING case.
Besides, buf is a const char and those changes remove one uneeded line.

I created the function spk_reset_default_value because it clarifies the code and allows code reusing.
Signed-off-by: NRaphael S.Carvalho <raphael.scarv@gmail.com>
Acked-by: NSamuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 ad6343a4
...@@ -585,6 +585,25 @@ ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr, ...@@ -585,6 +585,25 @@ ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr,
} }
EXPORT_SYMBOL_GPL(spk_var_show); 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 * This function is called when a user echos a value to one of the
* variable parameters. * variable parameters.
...@@ -624,56 +643,44 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, ...@@ -624,56 +643,44 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
if (ret == -ERANGE) { if (ret == -ERANGE) {
var_data = param->data; var_data = param->data;
pr_warn("value for %s out of range, expect %d to %d\n", 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); 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) {
spk_reset_default_value("pitch", synth->default_pitch,
value);
spk_reset_default_value("vol", synth->default_vol,
value);
}
break; break;
case VAR_STRING: case VAR_STRING:
len = strlen(buf); len = strlen(cp);
if ((len >= 1) && (buf[len - 1] == '\n')) if ((len >= 1) && (cp[len - 1] == '\n'))
--len; --len;
if ((len >= 2) && (buf[0] == '"') && (buf[len - 1] == '"')) { if ((len >= 2) && (cp[0] == '"') && (cp[len - 1] == '"')) {
++buf; ++cp;
len -= 2; len -= 2;
} }
cp = (char *) buf;
cp[len] = '\0'; cp[len] = '\0';
ret = spk_set_string_var(buf, param, len); ret = spk_set_string_var(cp, param, len);
if (ret == -E2BIG) if (ret == -E2BIG)
pr_warn("value too long for %s\n", pr_warn("value too long for %s\n",
attr->attr.name); param->name);
break; break;
default: default:
pr_warn("%s unknown type %d\n", pr_warn("%s unknown type %d\n",
param->name, (int)param->var_type); param->name, (int)param->var_type);
break; 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 = spk_var_header_by_name("pitch");
if (param) {
spk_set_num_var(synth->default_pitch[value],
param, E_NEW_DEFAULT);
spk_set_num_var(0, param, E_DEFAULT);
}
}
if (synth && synth->default_vol) {
param = spk_var_header_by_name("vol");
if (param) {
spk_set_num_var(synth->default_vol[value],
param, E_NEW_DEFAULT);
spk_set_num_var(0, param, E_DEFAULT);
}
}
}
spin_unlock_irqrestore(&speakup_info.spinlock, flags); spin_unlock_irqrestore(&speakup_info.spinlock, flags);
if (ret == -ERESTART) if (ret == -ERESTART)
pr_info("%s reset to default value\n", attr->attr.name); pr_info("%s reset to default value\n", param->name);
return count; return count;
} }
EXPORT_SYMBOL_GPL(spk_var_store); EXPORT_SYMBOL_GPL(spk_var_store);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册