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

speakup: i18n: Switch to kmemdup_nul() in spk_msg_set()

Use kmemdup_nul() helper instead of open-coding to
simplify the code in spk_msg_set().

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20210406034434.442251-1-yangyingliang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Yang Yingliang and committed by
Greg Kroah-Hartman
0d5cf954 6c00365d

+1 -3
+1 -3
drivers/accessibility/speakup/i18n.c
··· 548 548 if ((index < MSG_FIRST_INDEX) || (index >= MSG_LAST_INDEX)) 549 549 return -EINVAL; 550 550 551 - newstr = kmalloc(length + 1, GFP_KERNEL); 551 + newstr = kmemdup_nul(text, length, GFP_KERNEL); 552 552 if (!newstr) 553 553 return -ENOMEM; 554 554 555 - memcpy(newstr, text, length); 556 - newstr[length] = '\0'; 557 555 if (index >= MSG_FORMATTED_START && 558 556 index <= MSG_FORMATTED_END && 559 557 !fmt_validate(speakup_default_msgs[index], newstr)) {