Commit 38081c71 authored by Narcisa Ana Maria Vasile's avatar Narcisa Ana Maria Vasile Committed by Greg Kroah-Hartman

staging: speakup: i18n.c: Refactor conditionals in spk_msg_set

Reduce the indentation level in spk_msg_set and remove
unnecessary return variable.
Signed-off-by: default avatarNarcisa Ana Maria Vasile <narcisaanamaria12@gmail.com>
Acked-by: default avatarJulia Lawall <julia.lawall@lip6.fr>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent eaeab71f
...@@ -541,19 +541,21 @@ static bool fmt_validate(char *template, char *user) ...@@ -541,19 +541,21 @@ static bool fmt_validate(char *template, char *user)
*/ */
ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length) ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length)
{ {
int rc = 0;
char *newstr = NULL; char *newstr = NULL;
unsigned long flags; unsigned long flags;
if ((index >= MSG_FIRST_INDEX) && (index < MSG_LAST_INDEX)) { if ((index < MSG_FIRST_INDEX) || (index >= MSG_LAST_INDEX))
return -EINVAL;
newstr = kmalloc(length + 1, GFP_KERNEL); newstr = kmalloc(length + 1, GFP_KERNEL);
if (newstr) { if (!newstr)
return -ENOMEM;
memcpy(newstr, text, length); memcpy(newstr, text, length);
newstr[length] = '\0'; newstr[length] = '\0';
if (index >= MSG_FORMATTED_START && if (index >= MSG_FORMATTED_START &&
index <= MSG_FORMATTED_END && index <= MSG_FORMATTED_END &&
!fmt_validate(speakup_default_msgs[index], !fmt_validate(speakup_default_msgs[index], newstr)) {
newstr)) {
kfree(newstr); kfree(newstr);
return -EINVAL; return -EINVAL;
} }
...@@ -562,13 +564,7 @@ ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length) ...@@ -562,13 +564,7 @@ ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length)
kfree(speakup_msgs[index]); kfree(speakup_msgs[index]);
speakup_msgs[index] = newstr; speakup_msgs[index] = newstr;
spin_unlock_irqrestore(&speakup_info.spinlock, flags); spin_unlock_irqrestore(&speakup_info.spinlock, flags);
} else { return 0;
rc = -ENOMEM;
}
} else {
rc = -EINVAL;
}
return rc;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment