summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNarcisa Ana Maria Vasile <narcisaanamaria12@gmail.com>2017-03-10 00:53:44 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-03-12 15:27:45 +0100
commit38081c71859efee77c7f3fec07bc4748acb248dc (patch)
treefcdbafd3f721811c468b9aba9422ad9d07acf012
parenteaeab71f27c485e8940782304158f41c3fff7139 (diff)
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: Narcisa Ana Maria Vasile <narcisaanamaria12@gmail.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/speakup/i18n.c44
1 files changed, 20 insertions, 24 deletions
diff --git a/drivers/staging/speakup/i18n.c b/drivers/staging/speakup/i18n.c
index a8326db78a0f..7809867f5d28 100644
--- a/drivers/staging/speakup/i18n.c
+++ b/drivers/staging/speakup/i18n.c
@@ -541,34 +541,30 @@ static bool fmt_validate(char *template, char *user)
*/
ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length)
{
- int rc = 0;
char *newstr = NULL;
unsigned long flags;
- if ((index >= MSG_FIRST_INDEX) && (index < MSG_LAST_INDEX)) {
- newstr = kmalloc(length + 1, GFP_KERNEL);
- if (newstr) {
- memcpy(newstr, text, length);
- newstr[length] = '\0';
- if (index >= MSG_FORMATTED_START &&
- index <= MSG_FORMATTED_END &&
- !fmt_validate(speakup_default_msgs[index],
- newstr)) {
- kfree(newstr);
- return -EINVAL;
- }
- spin_lock_irqsave(&speakup_info.spinlock, flags);
- if (speakup_msgs[index] != speakup_default_msgs[index])
- kfree(speakup_msgs[index]);
- speakup_msgs[index] = newstr;
- spin_unlock_irqrestore(&speakup_info.spinlock, flags);
- } else {
- rc = -ENOMEM;
- }
- } else {
- rc = -EINVAL;
+ if ((index < MSG_FIRST_INDEX) || (index >= MSG_LAST_INDEX))
+ return -EINVAL;
+
+ newstr = kmalloc(length + 1, GFP_KERNEL);
+ if (!newstr)
+ return -ENOMEM;
+
+ memcpy(newstr, text, length);
+ newstr[length] = '\0';
+ if (index >= MSG_FORMATTED_START &&
+ index <= MSG_FORMATTED_END &&
+ !fmt_validate(speakup_default_msgs[index], newstr)) {
+ kfree(newstr);
+ return -EINVAL;
}
- return rc;
+ spin_lock_irqsave(&speakup_info.spinlock, flags);
+ if (speakup_msgs[index] != speakup_default_msgs[index])
+ kfree(speakup_msgs[index]);
+ speakup_msgs[index] = newstr;
+ spin_unlock_irqrestore(&speakup_info.spinlock, flags);
+ return 0;
}
/*