Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Narcisa Ana Maria Vasile and committed by
Greg Kroah-Hartman
38081c71 eaeab71f

+20 -24
+20 -24
drivers/staging/speakup/i18n.c
··· 541 541 */ 542 542 ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length) 543 543 { 544 - int rc = 0; 545 544 char *newstr = NULL; 546 545 unsigned long flags; 547 546 548 - if ((index >= MSG_FIRST_INDEX) && (index < MSG_LAST_INDEX)) { 549 - newstr = kmalloc(length + 1, GFP_KERNEL); 550 - if (newstr) { 551 - memcpy(newstr, text, length); 552 - newstr[length] = '\0'; 553 - if (index >= MSG_FORMATTED_START && 554 - index <= MSG_FORMATTED_END && 555 - !fmt_validate(speakup_default_msgs[index], 556 - newstr)) { 557 - kfree(newstr); 558 - return -EINVAL; 559 - } 560 - spin_lock_irqsave(&speakup_info.spinlock, flags); 561 - if (speakup_msgs[index] != speakup_default_msgs[index]) 562 - kfree(speakup_msgs[index]); 563 - speakup_msgs[index] = newstr; 564 - spin_unlock_irqrestore(&speakup_info.spinlock, flags); 565 - } else { 566 - rc = -ENOMEM; 567 - } 568 - } else { 569 - rc = -EINVAL; 547 + if ((index < MSG_FIRST_INDEX) || (index >= MSG_LAST_INDEX)) 548 + return -EINVAL; 549 + 550 + newstr = kmalloc(length + 1, GFP_KERNEL); 551 + if (!newstr) 552 + return -ENOMEM; 553 + 554 + memcpy(newstr, text, length); 555 + newstr[length] = '\0'; 556 + if (index >= MSG_FORMATTED_START && 557 + index <= MSG_FORMATTED_END && 558 + !fmt_validate(speakup_default_msgs[index], newstr)) { 559 + kfree(newstr); 560 + return -EINVAL; 570 561 } 571 - return rc; 562 + spin_lock_irqsave(&speakup_info.spinlock, flags); 563 + if (speakup_msgs[index] != speakup_default_msgs[index]) 564 + kfree(speakup_msgs[index]); 565 + speakup_msgs[index] = newstr; 566 + spin_unlock_irqrestore(&speakup_info.spinlock, flags); 567 + return 0; 572 568 } 573 569 574 570 /*