From 6a48f88b528fef7c4b6ad609111a8acfb5d65335 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 28 Mar 2013 11:02:44 +0200 Subject: [PATCH] staging: speakup: use native error codes The mapping as follows: E_RANGE -> ERANGE E_UNDEF -> ENODATA E_TOOLONG -> E2BIG SET_DEFAULT -> ERESTART As a side effect it fixes a bug in spk_var_store() where return code was mistakenly compared to negative value instead of positive. Signed-off-by: Andy Shevchenko Acked-by: Samuel Thibault Signed-off-by: Greg Kroah-Hartman --- drivers/staging/speakup/kobjects.c | 6 +++--- drivers/staging/speakup/speakup.h | 5 ----- drivers/staging/speakup/varhandlers.c | 26 +++++++++++++------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c index d0f660baa4a6..d6d9264e4ca7 100644 --- a/drivers/staging/speakup/kobjects.c +++ b/drivers/staging/speakup/kobjects.c @@ -619,7 +619,7 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, len = E_SET; value = simple_strtol(cp, NULL, 10); ret = spk_set_num_var(value, param, len); - if (ret == E_RANGE) { + if (ret == -ERANGE) { var_data = param->data; pr_warn("value for %s out of range, expect %d to %d\n", attr->attr.name, @@ -637,7 +637,7 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, cp = (char *) buf; cp[len] = '\0'; ret = spk_set_string_var(buf, param, len); - if (ret == E_TOOLONG) + if (ret == -E2BIG) pr_warn("value too long for %s\n", attr->attr.name); break; @@ -670,7 +670,7 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, } spk_unlock(flags); - if (ret == SET_DEFAULT) + if (ret == -ERESTART) pr_info("%s reset to default value\n", attr->attr.name); return count; } diff --git a/drivers/staging/speakup/speakup.h b/drivers/staging/speakup/speakup.h index 1e5691c3fce7..c387a02fc1c2 100644 --- a/drivers/staging/speakup/speakup.h +++ b/drivers/staging/speakup/speakup.h @@ -44,11 +44,6 @@ #define IS_CHAR(x, type) (spk_chartab[((u_char)x)]&type) #define IS_TYPE(x, type) ((spk_chartab[((u_char)x)]&type) == type) -#define SET_DEFAULT -4 -#define E_RANGE -3 -#define E_TOOLONG -2 -#define E_UNDEF -1 - extern int speakup_thread(void *data); extern void spk_reset_default_chars(void); extern void spk_reset_default_chartab(void); diff --git a/drivers/staging/speakup/varhandlers.c b/drivers/staging/speakup/varhandlers.c index 0a237da3acee..be61a4ee78dd 100644 --- a/drivers/staging/speakup/varhandlers.c +++ b/drivers/staging/speakup/varhandlers.c @@ -184,19 +184,19 @@ int spk_set_num_var(int input, struct st_var_header *var, int how) char buf[32]; char *cp; struct var_t *var_data = var->data; + if (var_data == NULL) - return E_UNDEF; + return -ENODATA; if (how == E_NEW_DEFAULT) { if (input < var_data->u.n.low || input > var_data->u.n.high) - ret = E_RANGE; - else - var_data->u.n.default_val = input; - return ret; + return -ERANGE; + var_data->u.n.default_val = input; + return 0; } if (how == E_DEFAULT) { val = var_data->u.n.default_val; - ret = SET_DEFAULT; + ret = -ERESTART; } else { if (how == E_SET) val = input; @@ -207,7 +207,7 @@ int spk_set_num_var(int input, struct st_var_header *var, int how) else if (how == E_DEC) val -= input; if (val < var_data->u.n.low || val > var_data->u.n.high) - return E_RANGE; + return -ERANGE; } var_data->u.n.value = val; if (var->var_type == VAR_TIME && p_val != NULL) { @@ -246,25 +246,25 @@ int spk_set_num_var(int input, struct st_var_header *var, int how) int spk_set_string_var(const char *page, struct st_var_header *var, int len) { - int ret = 0; struct var_t *var_data = var->data; + if (var_data == NULL) - return E_UNDEF; + return -ENODATA; if (len > MAXVARLEN) - return -E_TOOLONG; + return -E2BIG; if (!len) { if (!var_data->u.s.default_val) return 0; - ret = SET_DEFAULT; if (!var->p_val) var->p_val = var_data->u.s.default_val; if (var->p_val != var_data->u.s.default_val) strcpy((char *)var->p_val, var_data->u.s.default_val); + return -ERESTART; } else if (var->p_val) strcpy((char *)var->p_val, page); else - return -E_TOOLONG; - return ret; + return -E2BIG; + return 0; } /* spk_set_mask_bits sets or clears the punc/delim/repeat bits, -- 2.30.2