Skip to contentSkip to conversation

staging/speakup: Switch to kmemdup_nul()

PATCH In review Yang Yingliang 2 participants 3 messages Apr 2, 2021 – Apr 6, 2021 Speakup console speech driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging/speakup: Switch to kmemdup_nul()

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

---
 drivers/accessibility/speakup/i18n.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/accessibility/speakup/i18n.c +1 -3
index ee240d36f947..46bd50f3c3a4 100644
@@ -548,12 +548,10 @@ ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length)
 	if ((index < MSG_FIRST_INDEX) || (index >= MSG_LAST_INDEX))
 		return -EINVAL;
 
-	newstr = kmalloc(length + 1, GFP_KERNEL);
+	newstr = kmemdup_nul(text, length, 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)) {
Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · Yang Yingliang

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

---
 drivers/accessibility/speakup/i18n.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Your subject line is very odd, why does it have "staging"?

Your robot is not doing well these days...

greg k-h

#2 lore raw

Hi,

Quoted 10 lines · Greg KH
Quoted 8 lines · Yang Yingliang

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

---
  drivers/accessibility/speakup/i18n.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

Your subject line is very odd, why does it have "staging"?

I check git log of this file and use prefix of the history title, obviously I was wrong, I will send a v2 later.

Thanks,
Yang

Quoted 5 lines

Your robot is not doing well these days...

greg k-h
.