[PATCH NEEDS TEST] synth_direct_store refactor to use synth_write

From: Justin Stitt
Date: Fri Aug 25 2023 - 18:32:03 EST


I've just copy/pasted Kees' suggestion here [1] and rebased it against
6.5-rc7.

This patch needs testing as it refactors behavior in synth_direct_store.

[1]: https://lore.kernel.org/all/202308251439.36BC33ADB2@keescook/

Signed-off-by: Justin Stitt <justinstitt@xxxxxxxxxx>
---
drivers/accessibility/speakup/kobjects.c | 25 +++++++++++-------------
1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/accessibility/speakup/kobjects.c
b/drivers/accessibility/speakup/kobjects.c
index a7522d409802..0dfdb6608e02 100644
--- a/drivers/accessibility/speakup/kobjects.c
+++ b/drivers/accessibility/speakup/kobjects.c
@@ -413,27 +413,24 @@ static ssize_t synth_direct_store(struct kobject *kob=
j,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
- u_char tmp[256];
- int len;
- int bytes;
- const char *ptr =3D buf;
+ char *unescaped;
unsigned long flags;

if (!synth)
return -EPERM;

- len =3D strlen(buf);
+ unescaped =3D kstrdup(buf, GFP_KERNEL);
+ if (!unescaped)
+ return -ENOMEM;
+
+ string_unescape_any_inplace(unescaped);
+
spin_lock_irqsave(&speakup_info.spinlock, flags);
- while (len > 0) {
- bytes =3D min_t(size_t, len, 250);
- strncpy(tmp, ptr, bytes);
- tmp[bytes] =3D '\0';
- string_unescape_any_inplace(tmp);
- synth_printf("%s", tmp);
- ptr +=3D bytes;
- len -=3D bytes;
- }
+ synth_write(unescaped, strlen(unescaped));
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
+
+ kfree(unescaped);
+
return count;
}

--
2.42.0.rc1.204.g551eb34607-goog